Hi,
Considering the suggestions from all I made a new patch for
getting/setting the pdf ID.
Please find the new patch attached new patch with this mail.
I need suggestions from all. Please let me know when you commit this patch.
--
Thanks & regards
A srinivas
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>
Index: poppler-0.14.0/poppler/PDFDoc.h
===================================================================
--- poppler-0.14.0/poppler/PDFDoc.h (revision 202)
+++ 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
+ GBool getID(GooString *permanent_id,GooString *update_id);
+ // 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 202)
+++ poppler-0.14.0/poppler/PDFDoc.cc (working copy)
@@ -445,6 +445,147 @@
return lin;
}
+static void
+get_id(char* encodedid,char *pdfid) {
+
+ 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);
+}
+
+GBool PDFDoc::getID(GooString *permanent_id,GooString *update_id) {
+
+ 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*));
+ pdfids[0] = (char*)malloc(32*sizeof(char));
+ pdfids[1] = (char*)malloc(32*sizeof(char));
+
+ get_id(Id1,pdfids[0]);
+ get_id(Id2,pdfids[1]);
+
+ permanent_id->append(pdfids[0],32);
+ update_id->append(pdfids[1],32);
+
+ free(Id1);
+ free(Id2);
+
+ free(pdfids[0]);
+ free(pdfids[1]);
+ free(pdfids);
+
+ return true;
+}
+
+GBool PDFDoc::setID() {
+
+ GooString permanent_id,update_id;
+
+ if(getID(&permanent_id,&update_id)) { return false; }
+ else {
+ char *filename = getFileName()->getCString();
+
+ GooString message;
+ char buffer[64];
+ sprintf(buffer, "%i", (int)time(NULL));
+ message.append(buffer);
+
+ // gets filename from the path
+ char *file = strrchr(filename,'/');
+ if(!file) strrchr(filename,'\\');
+
+ // file name
+ if(filename)
+ message.append(file+1);
+ else
+ message.append("emptyfilename.pdf");
+
+ // file size
+ unsigned int fileSize = 0;
+
+ FILE *f;
+ f = fopen(filename,"r");
+ fseek(f,0,SEEK_END);
+ fileSize = ftell(f);
+
+ 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 file could not be open return false
+ if (!(f = fopen(filename,"r+"))) {
+ error(-1, "Couldn't open file '%s'",filename);
+ return false;
+ }
+ outStr = new FileOutStream(f,0);
+
+ fflush(stdout);
+ saveAs(outStr,writeForceIncremental);
+
+ fclose(f);
+ delete outStr;
+
+ free(file);
+ 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 202)
+++ poppler-0.14.0/glib/poppler-document.cc (working copy)
@@ -54,7 +54,9 @@
PROP_PAGE_MODE,
PROP_VIEWER_PREFERENCES,
PROP_PERMISSIONS,
- PROP_METADATA
+ PROP_METADATA,
+ PROP_PERMANENT_ID,
+ PROP_UPDATE_ID
};
static void poppler_document_layers_free (PopplerDocument *document);
@@ -762,6 +764,24 @@
}
}
break;
+ case PROP_PERMANENT_ID:
+ {
+ GooString permanent_id,update_id;
+ if(document->doc->getID(&permanent_id,&update_id))
+ {
+ g_value_set_string(value,permanent_id.getCString());
+ }
+ break;
+ }
+ case PROP_UPDATE_ID:
+ {
+ GooString permanent_id,update_id;
+ if(document->doc->getID(&permanent_id,&update_id))
+ {
+ g_value_set_string(value,update_id.getCString());
+ }
+ break;
+ }
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -931,6 +951,24 @@
"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
@@ -1928,7 +1966,30 @@
return NULL;
}
+PopplerDocumentId*
+poppler_document_get_pdf_id (PopplerDocument *document)
+{
+
+ GooString permanent_id,update_id;
+
+ if(document->doc->getID(&permanent_id,&update_id)) {
+
+ PopplerDocumentId *doc_id = g_new(PopplerDocumentId,1);
+ strcpy(doc_id->permanent_id,permanent_id.getCString());
+ strcpy(doc_id->update_id,update_id.getCString());
+
+ return doc_id;
+ }
+ else return NULL;
+}
+
gboolean
+poppler_document_set_pdf_id (PopplerDocument *document)
+{
+ return document->doc->setID() ? TRUE : FALSE;
+}
+
+gboolean
_poppler_convert_pdf_date_to_gtime (GooString *date,
time_t *gdate)
{
Index: poppler-0.14.0/glib/poppler-document.h
===================================================================
--- poppler-0.14.0/glib/poppler-document.h (revision 202)
+++ 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 ())
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler