[Lazarus] Get the number of pages in a pdf file

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] Get the number of pages in a pdf file

Free Pascal - Lazarus mailing list

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

--

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Get the number of pages in a pdf file

Free Pascal - Lazarus mailing list
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.


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
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Get the number of pages in a pdf file

Free Pascal - Lazarus mailing list
El 15/06/2019 a las 13:56, Graeme Geldenhuys via lazarus escribió:

> 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.

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] Get the number of pages in a pdf file

Free Pascal - Lazarus mailing list
In reply to this post by Free Pascal - Lazarus mailing list
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

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus