Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2019-06

Get the number of pages in a pdf file

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys
to Rogério Martins
Rogério Martins wrote
Is 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

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ My public PGP key: http://tinyurl.com/graeme-pgp

Reply by email

Santiago A.
to Graeme Geldenhuys
Graeme Geldenhuys wrote 12 lines
On 14/06/2019 6:19 pm, Rogério Martins via lazarus wrote: > Is 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.

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"

Saludos Santiago A.

Reply by email

Unknown author

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>

Reply by email