Function to get count of pages in a PDF File

Can anyone provide a function that returns the number of pages in a PDF file that hopefully will work in Delphi XE 8

I tried this one, but had problems getting it working in Delphi XE 8

Thank you

Hi Scott,

I had the same need a while ago and spent a lot of time trying out different methods and libraries.

The only thing that has worked reliably on all pdfs I have encountered is pdfium.dll.

There are 3 delphi wrapper units that work together with this dll: PdfiumLib.pas, PdfiumCtrl.pas and PdfiumCore.pas. I must have a record somewhere about where I got mine from but can’t find that at the moment, but you could try GitHub - ahausladen/PdfiumLib: PDF VCL Control using PDFium.

The pas files that I have work with D2007. Don’t know about compatability with XE8. The dll file however is not delphi version specific.

1 Like

Hi Scott.
I’ve evidently forgotten to update that Tips page you’ve linked to above with a much more recent version that’s now hosted on GitHub here.
This GitHub unit is the latest, and should compile with any version of Delphi from Delphi 7 on. Also, in my testing, it returns a page count for all PDF files except those that are encrypted.

2 Likes

Thank you John and Angus

@angusj

I ended up using your PdfPageCount.pas unit on GitHub

Thank you for your efforts in putting that together

1 Like