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

Santiago A. svaa at ciberpiula.net
Sun Jun 16 13:16:07 CEST 2019

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"


Santiago A.

More information about the lazarus mailing list