Hi !
Is there a function for read info about a pdf file ? I need to know the number of pages in a given pdf file.
Thanks

Mailing lists / lazarus / 2019-06
4 messages · 4 people · –
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
Hi !
Is there a function for read info about a pdf file ? I need to know the number of pages in a given pdf file.
Thanks
Rogério Martins wroteIs there a function for read info about a pdf file ? I need to know the number of pages in a given pdf file.
I don't know of a Object Pascal library you can you, but there is an alternative. The PDF fromat is a mixture of text and binary. You can search for text as follows:
/Type /Pages
/Count 45
After the "/Type /Pages" there should be a "/Count <n>" line which contains the page count. Hope that helps.
Regards,
Graeme
It is not completely reliably.
I used to search "/Type /Pages", but a day I couldn't find it, after digging a little in the PDF, I discovered that the number of pages was stored in a compressed stream. PDF can sore any data in a compressed stream and they decided to compress page information. And since then I have begun to find it more frequently. I suppose that once you have the frame work to compress stream, why not compress everything. I can't see what are the advantages of compressing a few bytes, but it's there.
Now I try to search "/Type /Pages" and if I can't find it I call a external utility "pdftk"
Searching for strings of /Pages and /Count would be highly unreliable.
At worst, you would need to search the whole file, adding the entries.
To do it right, you need to get the page tree of the document catalog, then recursively look up the kids of each page tree node, increment the count, then visit the all child nodes.
There are many libraries that can do this, both free, and commercial.
Joe C. Hecht
UberPDF.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20190616/2e8f86e1/attachment.html>