[poppler] 3 commits - glib/demo glib/poppler-document.cc glib/poppler-document.h glib/reference poppler/PDFDoc.cc poppler/PDFDoc.h
Carlos Garcia Campos
carlosgc at kemper.freedesktop.org
Fri Sep 17 01:39:39 PDT 2010
glib/demo/info.cc | 9 ++++
glib/poppler-document.cc | 52 ++++++++++++++++++++++++++++
glib/poppler-document.h | 3 +
glib/reference/poppler-sections.txt | 1
poppler/PDFDoc.cc | 65 ++++++++++++++++++++++++++++++++++++
poppler/PDFDoc.h | 3 +
6 files changed, 133 insertions(+)
New commits:
commit a5fec843dbb40fdd2007b926405b96789b21496d
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Fri Sep 17 10:38:14 2010 +0200
[glib-demo] Show permanent/update ID in document info demo
diff --git a/glib/demo/info.cc b/glib/demo/info.cc
index 87be8ea..8aa6dc8 100644
--- a/glib/demo/info.cc
+++ b/glib/demo/info.cc
@@ -118,6 +118,8 @@ pgd_info_create_widget (PopplerDocument *document)
gchar *title, *format, *author, *subject;
gchar *keywords, *creator, *producer, *linearized;
gchar *metadata;
+ gchar *perm_id;
+ gchar *up_id;
GTime creation_date, mod_date;
GEnumValue *enum_value;
PopplerBackend backend;
@@ -211,6 +213,13 @@ pgd_info_create_widget (PopplerDocument *document)
enum_value = g_enum_get_value ((GEnumClass *) g_type_class_peek (POPPLER_TYPE_PAGE_LAYOUT), layout);
pgd_table_add_property (GTK_TABLE (table), "<b>Page Layout:</b>", enum_value->value_name, &row);
+ if (poppler_document_get_id (document, &perm_id, &up_id)) {
+ pgd_table_add_property (GTK_TABLE (table), "<b>Permanent ID:</b>", perm_id, &row);
+ pgd_table_add_property (GTK_TABLE (table), "<b>Update ID:</b>", up_id, &row);
+ g_free (perm_id);
+ g_free (up_id);
+ }
+
pgd_info_add_permissions (GTK_TABLE (table), permissions, &row);
pgd_info_add_metadata (GTK_TABLE (table), metadata, &row);
commit bfaf8f3cc62f28c6255d42680b9464ab9973737e
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Fri Sep 17 10:37:32 2010 +0200
[glib] Add poppler_document_get_id() to get the PDF file identifier
diff --git a/glib/poppler-document.cc b/glib/poppler-document.cc
index 78c739d..aaa26b3 100644
--- a/glib/poppler-document.cc
+++ b/glib/poppler-document.cc
@@ -359,6 +359,58 @@ poppler_document_finalize (GObject *object)
}
/**
+ * poppler_document_get_id:
+ * @document: A #PopplerDocument
+ * @permanent_id: (out) (allow-none): location to store an allocated string, use g_free() to free the returned string
+ * @update_id: (out) (allow-none): location to store an allocated string, use g_free() to free the returned string
+ *
+ * Returns the PDF file identifier represented as two byte string arrays.
+ * @permanent_id is the permanent identifier that is built based on the file
+ * contents at the time it was originally created, so that this identifer
+ * never changes. @update_id is the update identifier that is built based on
+ * the file contents at the time it was last updated.
+ *
+ * Returns: %TRUE if the @document contains an id, %FALSE otherwise
+ *
+ * Since: 0.16
+ */
+gboolean
+poppler_document_get_id (PopplerDocument *document,
+ gchar **permanent_id,
+ gchar **update_id)
+{
+ GooString *permanent = NULL;
+ GooString *update = NULL;
+ gboolean retval = FALSE;
+
+ g_return_val_if_fail (POPPLER_IS_DOCUMENT (document), FALSE);
+
+ if (permanent_id) {
+ permanent = new GooString();
+ *permanent_id = NULL;
+ }
+
+ if (update_id) {
+ update = new GooString();
+ *update_id = NULL;
+ }
+
+ if (document->doc->getID (permanent, update)) {
+ if (permanent)
+ *permanent_id = g_strdup (permanent->getCString());
+ if (update)
+ *update_id = g_strdup (update->getCString());
+
+ retval = TRUE;
+ }
+
+ delete permanent;
+ delete update;
+
+ return retval;
+}
+
+/**
* poppler_document_get_n_pages:
* @document: A #PopplerDocument
*
diff --git a/glib/poppler-document.h b/glib/poppler-document.h
index 6be824b..4dc7c99 100644
--- a/glib/poppler-document.h
+++ b/glib/poppler-document.h
@@ -170,6 +170,9 @@ gboolean poppler_document_save (PopplerDocument *document,
gboolean poppler_document_save_a_copy (PopplerDocument *document,
const char *uri,
GError **error);
+gboolean poppler_document_get_id (PopplerDocument *document,
+ gchar **permanent_id,
+ gchar **update_id);
int poppler_document_get_n_pages (PopplerDocument *document);
PopplerPage *poppler_document_get_page (PopplerDocument *document,
int index);
diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt
index 6582766..344c3e2 100644
--- a/glib/reference/poppler-sections.txt
+++ b/glib/reference/poppler-sections.txt
@@ -111,6 +111,7 @@ poppler_document_new_from_file
poppler_document_new_from_data
poppler_document_save
poppler_document_save_a_copy
+poppler_document_get_id
poppler_document_get_n_pages
poppler_document_get_page
poppler_document_get_page_by_label
commit b15641677447b2e89853a667fc34bcca1383a97a
Author: srinivas adicherla <srinivas.adicherla at gmail.com>
Date: Fri Sep 17 10:36:22 2010 +0200
Add a method to get the PDF file identifier
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index e4ac639..385e367 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -71,6 +71,7 @@
#define headerSearchSize 1024 // read this many bytes at beginning of
// file to look for '%PDF'
+#define pdfIdLength 32 // PDF Document IDs (PermanentId, UpdateId) length
//------------------------------------------------------------------------
// PDFDoc
@@ -462,6 +463,70 @@ GBool PDFDoc::isLinearized() {
return lin;
}
+static GBool
+get_id (const char *encodedid, GooString *id) {
+ char pdfid[pdfIdLength + 1];
+ int n;
+
+ if (strlen(encodedid) != 16)
+ return gFalse;
+
+ n = sprintf(pdfid, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+ encodedid[0] & 0xff, encodedid[1] & 0xff, encodedid[2] & 0xff, encodedid[3] & 0xff,
+ encodedid[4] & 0xff, encodedid[5] & 0xff, encodedid[6] & 0xff, encodedid[7] & 0xff,
+ encodedid[8] & 0xff, encodedid[9] & 0xff, encodedid[10] & 0xff, encodedid[11] & 0xff,
+ encodedid[12] & 0xff, encodedid[13] & 0xff, encodedid[14] & 0xff, encodedid[15] & 0xff);
+ if (n != pdfIdLength)
+ return gFalse;
+
+ id->Set(pdfid, pdfIdLength);
+ return gTrue;
+}
+
+GBool PDFDoc::getID(GooString *permanent_id, GooString *update_id) {
+ Object obj;
+ xref->getTrailerDict()->dictLookup ("ID", &obj);
+
+ if (obj.isArray() && obj.arrayGetLength() == 2) {
+ Object obj2;
+
+ if (permanent_id) {
+ if (obj.arrayGet(0, &obj2)->isString()) {
+ if (!get_id (obj2.getString()->getCString(), permanent_id)) {
+ obj2.free();
+ return gFalse;
+ }
+ } else {
+ error(-1, "Invalid permanent ID");
+ obj2.free();
+ return gFalse;
+ }
+ obj2.free();
+ }
+
+ if (update_id) {
+ if (obj.arrayGet(1, &obj2)->isString()) {
+ if (!get_id (obj2.getString()->getCString(), update_id)) {
+ obj2.free();
+ return gFalse;
+ }
+ } else {
+ error(-1, "Invalid update ID");
+ obj2.free();
+ return gFalse;
+ }
+ obj2.free();
+ }
+
+ obj.free();
+
+ return gTrue;
+ }
+ obj.free();
+
+ return gFalse;
+}
+
int PDFDoc::saveAs(GooString *name, PDFWriteMode mode) {
FILE *f;
OutStream *outStr;
diff --git a/poppler/PDFDoc.h b/poppler/PDFDoc.h
index 6d7dea2..8fb4bcb 100644
--- a/poppler/PDFDoc.h
+++ b/poppler/PDFDoc.h
@@ -206,6 +206,9 @@ public:
int getPDFMajorVersion() { return pdfMajorVersion; }
int getPDFMinorVersion() { return pdfMinorVersion; }
+ //Return the PDF ID in the trailer dictionary (if any).
+ GBool getID(GooString *permanent_id, GooString *update_id);
+
// Save this file with another name.
int saveAs(GooString *name, PDFWriteMode mode=writeStandard);
// Save this file in the given output stream.
More information about the poppler
mailing list