Hi Pino Toscano,<br><br> Thank you for your valuable suggestions, I will make those changes and send the patch again.<br><br>Thanks & Regards<br>A Srinivas<br> <br><br><div class="gmail_quote">On Fri, Jun 11, 2010 at 12:30 AM, <span dir="ltr"><<a href="mailto:poppler-request@lists.freedesktop.org">poppler-request@lists.freedesktop.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Send poppler mailing list submissions to<br>
<a href="mailto:poppler@lists.freedesktop.org">poppler@lists.freedesktop.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
<a href="http://lists.freedesktop.org/mailman/listinfo/poppler" target="_blank">http://lists.freedesktop.org/mailman/listinfo/poppler</a><br>
or, via email, send a message with subject or body 'help' to<br>
<a href="mailto:poppler-request@lists.freedesktop.org">poppler-request@lists.freedesktop.org</a><br>
<br>
You can reach the person managing the list at<br>
<a href="mailto:poppler-owner@lists.freedesktop.org">poppler-owner@lists.freedesktop.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of poppler digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
1. Patch to Get/Set PDF ID in the trailer dictionary, get page<br>
labels . (srinivas adicherla)<br>
2. Re: Patch to Get/Set PDF ID in the trailer dictionary, get<br>
page labels . (Pino Toscano)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Thu, 10 Jun 2010 15:43:25 +0530<br>
From: srinivas adicherla <<a href="mailto:srinivas.adicherla@gmail.com">srinivas.adicherla@gmail.com</a>><br>
Subject: [poppler] Patch to Get/Set PDF ID in the trailer dictionary,<br>
get page labels .<br>
To: <a href="mailto:poppler@lists.freedesktop.org">poppler@lists.freedesktop.org</a><br>
Message-ID:<br>
<<a href="mailto:AANLkTincvceHMRDnHvY0yS70BAqqKOZG-GJZgIM1hrnm@mail.gmail.com">AANLkTincvceHMRDnHvY0yS70BAqqKOZG-GJZgIM1hrnm@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Hi,<br>
<br>
This Patch does the following:<br>
<br>
1) gets and set the pdf IDs in the trailer dictionary.<br>
2) get all page labels & get page labels by index.<br>
<br>
Kindly let me know if You commit this patch.<br>
<br>
<br>
Thanks<br>
A Srinivas<br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.freedesktop.org/archives/poppler/attachments/20100610/61154402/attachment.htm" target="_blank">http://lists.freedesktop.org/archives/poppler/attachments/20100610/61154402/attachment.htm</a>><br>
-------------- next part --------------<br>
A non-text attachment was scrubbed...<br>
Name: srinivas_poppler.patch<br>
Type: text/x-patch<br>
Size: 4859 bytes<br>
Desc: not available<br>
URL: <<a href="http://lists.freedesktop.org/archives/poppler/attachments/20100610/61154402/attachment-0001.bin" target="_blank">http://lists.freedesktop.org/archives/poppler/attachments/20100610/61154402/attachment-0001.bin</a>><br>
<br>
------------------------------<br>
<br>
Message: 2<br>
Date: Thu, 10 Jun 2010 13:01:58 +0200<br>
From: Pino Toscano <<a href="mailto:pino@kde.org">pino@kde.org</a>><br>
Subject: Re: [poppler] Patch to Get/Set PDF ID in the trailer<br>
dictionary, get page labels .<br>
To: <a href="mailto:poppler@lists.freedesktop.org">poppler@lists.freedesktop.org</a><br>
Message-ID: <<a href="mailto:201006101302.07643.pino@kde.org">201006101302.07643.pino@kde.org</a>><br>
Content-Type: text/plain; charset="iso-8859-1"<br>
<br>
Hi,<br>
<br>
I'm not a poppler-glib developer, but there are few notes below.<br>
<br>
Alle gioved? 10 giugno 2010, srinivas adicherla ha scritto:<br>
> +/* following three functions has added to get and set pdf ID stored<br>
> in Trailer Dictionary*/<br>
> +static void<br>
> +get_id(char* id,char *buff) {<br>
> +<br>
> + int i;<br>
> + for( i = 0; i < 16; i++ ) {<br>
> +<br>
> + char *buf = (char*)malloc(3*sizeof(char));<br>
> + sprintf(buf,"%02x",id[i] & 0xff);<br>
> +<br>
> + if(i == 0) strcpy(buff,buf);<br>
> + else strcat(buff,buf);<br>
> +<br>
> + free (buf);<br>
> + }<br>
> +}<br>
<br>
This is pretty inefficient: you are allocating on the heap 3 bytes 16<br>
times (!). It would be much better if you could just use an array of 3<br>
chars on stack, and reuse it at every iteration.<br>
(Minor: a better naming than 'buf' and 'buff' would help a lot to<br>
distinguish them.)<br>
<br>
> +<br>
> +gboolean<br>
> +poppler_document_get_trailer_id(char *uri,char *password,char<br>
> *id[2]) {<br>
> [...]<br>
> + for(int i=0; i<2; i++) {<br>
> + id[i] = (char*)malloc(32*sizeof(char));<br>
> + }<br>
<br>
Excluding the fact that such for loop is useless (just manually do the<br>
two calls it does), why do you dynamically malloc the two result strings<br>
if you already know they will be 32 chars long? Then, instead of a out<br>
parameter of a two-strings array, just use two out parameters of 32<br>
bytes.<br>
<br>
> +void *<br>
> +poppler_document_generate_and_set_id(char *uri,char *password) {<br>
<br>
If this function returns nothing, then declare it as void, not as void*.<br>
<br>
> +char*<br>
> +poppler_document_get_page_label_by_index(PopplerDocument *document,<br>
> + int index)<br>
> +{<br>
> + GooString *string = new GooString();<br>
> + Catalog *catalog = document->doc->getCatalog ();<br>
> +<br>
> + catalog->indexToLabel(index,string);<br>
> +<br>
> + char *label = string->getCString();<br>
> + return label;<br>
> +}<br>
<br>
'string' is leaked here, just put it on stack.<br>
<br>
> +char**<br>
> +poppler_document_get_page_labels(PopplerDocument *document)<br>
> +{<br>
> +<br>
> + char **labels;<br>
> + Catalog *catalog= document->doc->getCatalog ();<br>
> + int npages = poppler_document_get_n_pages(document);<br>
> +<br>
> + labels = (char**)malloc(sizeof(char*)*npages);<br>
> +<br>
> + int i;<br>
> + for(i = 0; i < npages; i++) {<br>
> +<br>
> + GooString *label = new GooString();<br>
> + catalog->indexToLabel(i,label);<br>
> + labels[i] = label->getCString();<br>
> + }<br>
> + return labels;<br>
> +}<br>
<br>
This is tricker: the 'label' allocated at each loop is leaked, but you<br>
use its internal storage as return value. As before, put the GooString<br>
on stack, but strdup its storage.<br>
<br>
> +/* Labels */<br>
> +char*<br>
> +poppler_document_get_page_label_by_index(PopplerDocument *document,<br>
> + int index);<br>
> +char**<br>
> +poppler_document_get_page_labels(PopplerDocument *document);<br>
<br>
A label is specific to every page, so I guess these two functions would<br>
quite more suited as part of the PopplerPage API.<br>
Also, they miss they are not documented with gtk-doc, just like the rest<br>
of the glib API.<br>
<br>
> +/*Get the PDF ID from the trailer dictionary. Pdf Id contains two<br>
> strings of length 16 bytes each, represented in Hex*/<br>
> +gboolean poppler_document_get_trailer_id(char *uri,char<br>
> *password,char *id[2]);<br>
> +<br>
> +/*Generate the Pdf Id and set it in the Pdf file*/<br>
> +void *poppler_document_generate_and_set_id(char *uri,char<br>
> *password);<br>
<br>
Most probably they should not be just "free functions", but be part of<br>
the PopplerDocument API, so you first open a document as usual, then get<br>
its trailer and then free the document.<br>
Also, the uri and password parameters should be 'const', to indicate<br>
they won't be changed in the functions. And as above, they miss gtk-doc<br>
API documentation.<br>
<br>
--<br>
Pino Toscano<br>
-------------- next part --------------<br>
A non-text attachment was scrubbed...<br>
Name: not available<br>
Type: application/pgp-signature<br>
Size: 190 bytes<br>
Desc: This is a digitally signed message part.<br>
URL: <<a href="http://lists.freedesktop.org/archives/poppler/attachments/20100610/36cd404b/attachment-0001.pgp" target="_blank">http://lists.freedesktop.org/archives/poppler/attachments/20100610/36cd404b/attachment-0001.pgp</a>><br>
<br>
------------------------------<br>
<br>
_______________________________________________<br>
poppler mailing list<br>
<a href="mailto:poppler@lists.freedesktop.org">poppler@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/poppler" target="_blank">http://lists.freedesktop.org/mailman/listinfo/poppler</a><br>
<br>
<br>
End of poppler Digest, Vol 64, Issue 7<br>
**************************************<br>
</blockquote></div><br>