Hi,
By considering the suggestions from Carlos & Pino Toscano, I made some
changes to the previous patch.
As Carlos mentioned, I added PDFDoc:getID() in the core and from
the glib bindings took the structure for PopplerDocumentId and returning it.
In addition to that I added two new properties in the PopplerDocument
namely, "permanent-id" , "update-id".
As Carlos mentioned PDFDoc::saveAs() will not generate ID unless
we modify and save the file. If we don't modify and save it, it is nothing
but save a copy.So, I added PDFDoc::setID() in the core.
Please find two attachments with this mail containing the above said
changes.
On Sat, Jun 12, 2010 at 12:30 AM, <[email protected]>wrote:
> Send poppler mailing list submissions to
> [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://lists.freedesktop.org/mailman/listinfo/poppler
> or, via email, send a message with subject or body 'help' to
> [email protected]
>
> You can reach the person managing the list at
> [email protected]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of poppler digest..."
>
>
> Today's Topics:
>
> 1. Re: Patch to Get/Set PDF ID in the trailer dictionary, get
> page labels . (Carlos Garcia Campos)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Fri, 11 Jun 2010 12:31:47 +0200
> From: Carlos Garcia Campos <[email protected]>
> Subject: Re: [poppler] Patch to Get/Set PDF ID in the trailer
> dictionary, get page labels .
> To: srinivas adicherla <[email protected]>
> Cc: poppler <[email protected]>
> Message-ID: <1276251137-sup-4...@charmaleon>
> Content-Type: text/plain; charset="utf8"
>
> Excerpts from srinivas adicherla's message of jue jun 10 12:13:25 +0200
> 2010:
> > Hi,
>
> Hi srinivas,
>
> > This Patch does the following:
>
> Thanks for the patch, I some comments:
>
> > 1) gets and set the pdf IDs in the trailer dictionary.
>
> The code to get ID could be moved to the core, so that it can be used
> by other frontends, someting like PDFDoc::getID(). In the glib
> frontend, instead of returning an array we could use a struct so that
> we can also give names to the fields, since the first id is the
> permanent id and the second one is the id that changes when the
> document is updated. Something like
>
> typedef struct _PopplerDocumentId {
> gchar permanent_id[32];
> gchar update_id[32];
> } PopplerDocumentId;
>
> The method generate_and_set_id() shouldn't be necessary since
> PDFDoc::saveAS() already generates a new id.
>
> > 2) get all page labels & get page labels by index.
>
> We already have labels in the glib frontend, it's property of
> PopplerPage that can be obtained with
>
> g_object_get (page, "label", &label, NULL);
>
> I don't think we need that API in PopplerDocument, but we should
> probably expose it in the PopplerPage API to make it easier to
> find.
>
> > Kindly let me know if You commit this patch.
> >
> >
> > Thanks
> > A Srinivas
> --
> Carlos Garcia Campos
> PGP key: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x523E6462
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: signature.asc
> Type: application/pgp-signature
> Size: 198 bytes
> Desc: not available
> URL: <
> http://lists.freedesktop.org/archives/poppler/attachments/20100611/3ab6035b/attachment-0001.pgp
> >
>
> ------------------------------
>
> _______________________________________________
> poppler mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/poppler
>
>
> End of poppler Digest, Vol 64, Issue 9
> **************************************
>
Index: poppler-0.14.0/poppler/PDFDoc.h
===================================================================
--- poppler-0.14.0/poppler/PDFDoc.h (revision 198)
+++ poppler-0.14.0/poppler/PDFDoc.h (working copy)
@@ -206,6 +206,11 @@
int getPDFMajorVersion() { return pdfMajorVersion; }
int getPDFMinorVersion() { return pdfMinorVersion; }
+ // Return the PDF ID contains in the trailer dictionary
+ char** getID();
+ // Set the PDF ID in the trailer dictionary
+ GBool setID();
+
// Save this file with another name.
int saveAs(GooString *name, PDFWriteMode mode=writeStandard);
// Save this file in the given output stream.
Index: poppler-0.14.0/poppler/PDFDoc.cc
===================================================================
--- poppler-0.14.0/poppler/PDFDoc.cc (revision 198)
+++ poppler-0.14.0/poppler/PDFDoc.cc (working copy)
@@ -445,6 +445,129 @@
return lin;
}
+static void
+get_id(char* encodedid,char *pdfid) {
+
+ char buf[3];
+ for(int i=0;i<16;i++) {
+
+ sprintf(buf,"%02x",encodedid[i] & 0xff);
+
+ if(i == 0) strcpy(pdfid,buf);
+ else strcat(pdfid,buf);
+ }
+}
+
+char** PDFDoc::getID() {
+
+ Object *trailer = xref->getTrailerDict();
+
+ Object obj;
+ trailer->dictLookup("ID",&obj);
+
+ if(obj.isNull())
+ return NULL;
+
+ Object val1,val2;
+ obj.arrayGet(0,&val1);
+ obj.arrayGet(1,&val2);
+
+ char *Id1 = val1.getString()->getCString();
+ char *Id2 = val2.getString()->getCString();
+
+ char **pdfids = (char**)malloc(2*sizeof(char*));
+ ids[0] = (char*)malloc(32*sizeof(char));
+ ids[1] = (char*)malloc(32*sizeof(char));
+
+ get_id(Id1,pdfids[0]);
+ get_id(Id2,pdfids[1]);
+
+ free(Id1);
+ free(Id2);
+
+ return pdfids;
+}
+
+GBool PDFDoc::setID() {
+
+ char **pdfid = getID();
+ if(pdfid != NULL) return false;
+ else {
+ char *filename = getFileName()->getCString();
+
+ GooString message;
+ char buffer[256];
+ sprintf(buffer, "%i", (int)time(NULL));
+ message.append(buffer);
+ message.append(filename);
+
+ // file size
+ unsigned int fileSize = 0;
+
+ FILE *f;
+ f = fopen(filename,"r");
+ char ch;
+ while((ch=fgetc(f)) != EOF) {
+ fileSize++;
+ }
+
+ sprintf(buffer, "%i", fileSize);
+ message.append(buffer);
+
+ Object obj1;
+
+ //info dict -- only use text string
+ if (xref->getDocInfo(&obj1)->isDict()) {
+
+ for(int i=0; i<obj1.getDict()->getLength(); i++) {
+ Object obj2;
+ obj1.getDict()->getVal(i, &obj2);
+ if (obj2.isString()) {
+ message.append(obj2.getString());
+ }
+ obj2.free();
+ }
+ }
+ obj1.free();
+
+ Guchar digest[16];
+ Decrypt::md5((Guchar*)message.getCString(), message.getLength(), digest);
+
+ Object obj2,obj3;
+
+ obj2.initString(new GooString((const char*)digest,16));
+ obj3.initString(new GooString((const char*)digest,16));
+
+ Object *trailerDict = xref->getTrailerDict();
+ //create ID array
+ obj1.initArray(xref);
+
+ obj1.arrayAdd(&obj2);
+ obj1.arrayAdd(&obj3);
+
+ trailerDict->dictSet("ID", &obj1);
+
+ OutStream *outStr;
+
+ if (!(f = fopen(filename,"r+"))) {
+ error(-1, "Couldn't open file '%s'",filename);
+ }
+ outStr = new FileOutStream(f,0);
+
+ fflush(stdout);
+ saveAs(outStr,writeForceIncremental);
+
+ fclose(f);
+ delete outStr;
+
+ obj1.free();
+ obj2.free();
+ obj3.free();
+
+ return true;
+ }
+}
+
int PDFDoc::saveAs(GooString *name, PDFWriteMode mode) {
FILE *f;
OutStream *outStr;
Index: poppler-0.14.0/glib/poppler-document.cc
===================================================================
--- poppler-0.14.0/glib/poppler-document.cc (revision 198)
+++ poppler-0.14.0/glib/poppler-document.cc (working copy)
@@ -55,6 +55,8 @@
PROP_VIEWER_PREFERENCES,
PROP_PERMISSIONS,
PROP_METADATA
+ PROP_PERMANENT_ID,
+ PROP_UPDATE_ID
};
static void poppler_document_layers_free (PopplerDocument *document);
@@ -762,6 +764,22 @@
}
}
break;
+ case PROP_PERMANENT_ID:
+ char **pid;
+ pid = document->doc->getID();
+ if(pid != NULL) {
+ g_value_set_string(value,strdup(pid[0]));
+ free(pid);
+ }
+ break;
+
+ case PROP_UPDATE_ID:
+ pid = document->doc->getID();
+ if(pid != NULL) {
+ g_value_set_string(value,strdup(pid[1]));
+ free(pid);
+ }
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -931,6 +949,23 @@
"Embedded XML metadata",
NULL,
G_PARAM_READABLE));
+ g_object_class_install_property
+ (G_OBJECT_CLASS (klass),
+ PROP_PERMANENT_ID,
+ g_param_spec_string ("permanent-id",
+ "Permanent Id",
+ "Permanent Id of the Pdf Document",
+ NULL,
+ G_PARAM_READABLE));
+
+ g_object_class_install_property
+ (G_OBJECT_CLASS (klass),
+ PROP_UPDATE_ID,
+ g_param_spec_string ("update-id",
+ "Update Id",
+ "Update Id of the Pdf Document",
+ NULL,
+ G_PARAM_READABLE));
}
static void
@@ -1948,3 +1983,31 @@
return retval;
}
+
+PopplerDocumentId*
+poppler_document_get_pdf_id (PopplerDocument *document)
+{
+ char **pid = document->doc->getID();
+
+ if(pid == NULL) {
+ free(pid);
+ return NULL;
+ }
+ else
+ {
+ PopplerDocumentId *doc_id = g_new(PopplerDocumentId,1);
+ strcpy(doc_id->permanent_id,strdup(pid[0]));
+ strcpy(doc_id->update_id,strdup(pid[1]));
+
+ free(pid);
+ return doc_id;
+ }
+}
+
+gboolean
+poppler_document_set_pdf_id (PopplerDocument *document)
+{
+ GBool boolean = document->doc->setID();
+ if(boolean) return TRUE;
+ else return FALSE;
+}
Index: poppler-0.14.0/glib/poppler-document.h
===================================================================
--- poppler-0.14.0/glib/poppler-document.h (revision 198)
+++ poppler-0.14.0/glib/poppler-document.h (working copy)
@@ -89,8 +89,14 @@
} PopplerPermissions;
+typedef struct _PopplerDocumentId
+{
+ gchar permanent_id[33];
+ gchar update_id[33];
+}PopplerDocumentId;
+
GType poppler_document_get_type (void) G_GNUC_CONST;
PopplerDocument *poppler_document_new_from_file (const char *uri,
const char *password,
@@ -121,6 +127,11 @@
/* Form */
PopplerFormField *poppler_document_get_form_field (PopplerDocument *document,
gint id);
+/*Get the PDF IDs from the trailer dictionary.
+Pdf Ids contains two strings of length 16 bytes each, represented in Hex*/
+PopplerDocumentId *poppler_document_get_pdf_id(PopplerDocument *document);
+/*Generate the Pdf Id and set it in the Pdf file*/
+gboolean poppler_document_set_pdf_id (PopplerDocument *document);
/* Interface for getting the Index of a poppler_document */
#define POPPLER_TYPE_INDEX_ITER (poppler_index_iter_get_type ())
Index: poppler/poppler-poppler-document.html
===================================================================
--- poppler/poppler-poppler-document.html (revision 200)
+++ poppler/poppler-poppler-document.html (working copy)
@@ -44,6 +44,7 @@
enum <a class="link" href="poppler-poppler-document.html#PopplerFontType" title="enum PopplerFontType">PopplerFontType</a>;
enum <a class="link" href="poppler-poppler-document.html#PopplerViewerPreferences" title="enum PopplerViewerPreferences">PopplerViewerPreferences</a>;
enum <a class="link" href="poppler-poppler-document.html#PopplerPermissions" title="enum PopplerPermissions">PopplerPermissions</a>;
+ <a class="link" href="poppler-poppler-document.html#PopplerDocumentId" title="PopplerDocumentId">PopplerDocumentId</a>;
<a class="link" href="poppler-poppler.html#PopplerDocument">PopplerDocument</a> * <a class="link" href="poppler-poppler-document.html#poppler-document-new-from-file" title="poppler_document_new_from_file ()">poppler_document_new_from_file</a> (const char *uri,
const char *password,
<a
@@ -81,6 +82,8 @@
<a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gint"
>gint</a> id);
+<a class="link" href="poppler-poppler-document.html#PopplerDocumentId">PopplerDocumentId</a> * <a class="link" href="poppler-poppler-document.html#poppler-document-get-pdf-id" title="poppler_document_get_pdf_id ()">poppler_document_get_pdf_id</a> (<a class="link" href="poppler-poppler.html#PopplerDocument">PopplerDocument</a> *document);
+gboolean <a class="link" href="poppler-poppler-document.html#poppler-document-set-pdf-id" title="poppler_document_set_pdf_id ()">poppler_document_set_pdf_id</a> (<a class="link" href="poppler-poppler.html#PopplerDocument">PopplerDocument</a> *document);
<a
href="/usr/share/gtk-doc/html/gobject/gobject-Type-Information.html#GType"
>GType</a> <a class="link" href="poppler-poppler-document.html#poppler-index-iter-get-type" title="poppler_index_iter_get_type ()">poppler_index_iter_get_type</a> (void);
@@ -232,6 +235,18 @@
</p>
</div>
<hr>
+<div class="refsect2" title="PopplerDocumentId">
+<a name="PopplerDocumentId"></a><h3>PopplerDocumentId</h3>
+<pre class="programlisting">struct _PopplerDocumentId
+{
+ gchar permanent_id[33];
+ gchar update_id[33];
+} PopplerDocumentId;
+</pre>
+<p>
+</p>
+</div>
+<hr>
<div class="refsect2" title="poppler_document_new_from_file ()">
<a name="poppler-document-new-from-file"></a><h3>poppler_document_new_from_file ()</h3>
<pre class="programlisting"><a class="link" href="poppler-poppler.html#PopplerDocument">PopplerDocument</a> * poppler_document_new_from_file (const char *uri,
@@ -581,6 +596,56 @@
</table></div>
</div>
<hr>
+<hr>
+<div class="refsect2" title="poppler_document_get_pdf_id ()">
+<a name="poppler-document-get-pdf-id"></a><h3>poppler_document_get_pdf_id ()</h3>
+<pre class="programlisting"> <a class="link" href="poppler-poppler-document.html#PopplerDocumentId">PopplerDocumentId</a> * poppler_document_get_pdf_id (<a class="link" href="poppler-poppler.html#PopplerDocument">PopplerDocument</a> *document);</pre>
+<p>
+Returns a <a class="link" href="poppler-poppler-document.html#PopplerDocumentId">PopplerDocumentId</a>. Pdf file optionally contains two id strings in the trailer dictionary.
+</p>
+<p>
+</p>
+<div class="variablelist"><table border="0">
+<col align="left" valign="top">
+<tbody>
+<tr>
+<td><p><span class="term"><em class="parameter"><code>document</code></em> :</span></p></td>
+<td> a <a class="link" href="poppler-poppler.html#PopplerDocument">PopplerDocument</a></td>
+</tr>
+
+<tr>
+<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
+<td> <a class="link" href="poppler-poppler-document.html#PopplerDocumentId">PopplerDocumentId</a> if pdf file contains the ID in the trailer dictionary else NULL.
+</td>
+</tr>
+</tbody>
+</table></div>
+</div>
+
+<hr>
+<div class="refsect2" title="poppler_document_set_pdf_id ()">
+<a name="poppler-document-set-pdf-id"></a><h3>poppler_document_set_pdf_id ()</h3>
+<pre class="programlisting">gboolean poppler_document_set_pdf_id (<a class="link" href="poppler-poppler.html#PopplerDocument">PopplerDocument</a> *document);</pre>
+<p>
+Pdf file optionally contains two id strings in the trailer dictionary. If Not there generate pdf ids and set it in the trailer dictionary.
+</p>
+<p>
+</p>
+<div class="variablelist"><table border="0">
+<col align="left" valign="top">
+<tbody>
+<tr>
+<td><p><span class="term"><em class="parameter"><code>document</code></em> :</span></p></td>
+<td> a <a class="link" href="poppler-poppler.html#PopplerDocument">PopplerDocument</a></td>
+</tr>
+<tr>
+<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
+<td> TRUE if it sets the ID otherwise FALSE ( if pdf file already contains the ID ).
+</td>
+</tr>
+</tbody>
+</table></div>
+</div>
<div class="refsect2" title="poppler_index_iter_get_type ()">
<a name="poppler-index-iter-get-type"></a><h3>poppler_index_iter_get_type ()</h3>
<pre class="programlisting"><a
Index: poppler/poppler-poppler.html
===================================================================
--- poppler/poppler-poppler.html (revision 200)
+++ poppler/poppler-poppler.html (working copy)
@@ -130,6 +130,12 @@
"<a class="link" href="poppler-poppler.html#PopplerPage--label" title='The "label" property'>label</a>" <a
href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"
>gchar</a>* : Read
+ "<a class="link" href="poppler-poppler.html#PopplerDocument--permanent-id" title='The "permanent-id" property'>permanent-id</a>" <a
+href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"
+>gchar</a>* : Read
+ "<a class="link" href="poppler-poppler.html#PopplerDocument--update-id" title='The "update-id" property'>update-id</a>" <a
+href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"
+>gchar</a>* : Read
</pre>
</div>
<div class="refsect1" title="Description">
@@ -538,8 +544,24 @@
<p>The label of the page.</p>
<p>Default value: NULL</p>
</div>
+<hr>
+<div class="refsect2" title='The "permanent-id" property'>
+<a name="PopplerDocument--permanent-id"></a><h3>The <code class="literal">"permanent-id"</code> property</h3>
+<pre class="programlisting"> "permanent-id" <a
+href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"
+>gchar</a>* : Read</pre>
+<p>The permanent-id of the Document.</p>
</div>
+<hr>
+<div class="refsect2" title='The "update-id" property'>
+<a name="PopplerDocument--update-id"></a><h3>The <code class="literal">"update-id"</code> property</h3>
+<pre class="programlisting"> "update-id" <a
+href="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gchar"
+>gchar</a>* : Read</pre>
+<p>The update-id of the Document.</p>
</div>
+</div>
+</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.11</div>
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler