TAcroPDF page count and current page number


I’m considering using the Acrobat ActiveX reader in a project so I’ve installed TAcroPDF activeX component to give it a whirl.
Documentation on this doesn’t seem to be fantastic but most of it is fairly obvious.
The thing I haven’t been able to work out is how to get the page count of a PDF or how to get the current page number. Some Googling suggests I’m not the only one having trouble with this.

Has anyone been able to do this?


Not sure if this will help John but this (native opensource Delphi / FPC library for PDF) product might be worth a quick look :
GitHub - synopse/SynPDF: Synopse PDF engine is a fully featured Open Source PDF document creation library for Delphi, embedded in one unit

The site points to a QA forum so I guess you might be able to ask a few questions there to avoid wasting time evaluating the library in case it doesn’t meet you’re needs (I haven’t used it myself - yet).

Thanks for the suggestion Robert.

What I didn’t make clear in my post is that I’m wanting to display pdf files on screen.

While this library can create PDF documents I don’t think it can be used to display them.

This was briefly discussed at the agm meeting. There’s xpdf (C) and poppler (C++) which are open source but GPL.
@GrahameDGrieve mentioned pdfium.

If you only wanted total pages, pdftk command line can tell you - but I believe you want it current while being browsed.

Webbrowsers can show pdfs, but still wouldn’t fix your issue - unless via some javascript library.
Python might have something nifty.
Final thought - Windows explorer pdf preview is pretty nice. I wonder if there’s any way to use it ?


Of course, while this code will get you page numbers, it’s of no help in displaying PDF docs.

1 Like

Thanks Paul and Angus, I’ll have a look at these.

You might have sorted this out already, but I found I had tested PdfiumLib from Grahame & Andreas back in 2020.

It needs a dll, but the example project shows one page at a time (indexed), and it has a GetPageCount method.

Thankyou Paul.

I’ve had to put the project on hold for lack of finding a viable solution so I am very keen to try this out.

The project can’t go forward until it can count the pages in a pdf file. Have tried a number of things and all work to varying degrees, but so far none work on all of my test pdf files.

The only way you can get a page count using the Acrobat OCX is to have Acrobat writer (SDK) installed on the system the software is running on so that’s not viable.

This is for an outside of work project for my church where we want to be able to display music score sheets on monitors for the band. The software will receive signals from the program that displays words to songs on screen, so that it displays the appropriate music score for the band.

1 Like

Actually I seein to remember it needed a very particular version of the dll, and I believe the github readme and the source code content showed different #s at the time.

Also I see Blaise Pascal magazine, 100th edition, lists:
" Creating a new Library Program with PDF viewer - By Detlef Overbeek"

I’ve downloaded PdfiumLib from GitHub. (GitHub - grahamegrieve/PdfiumLib: PDF VCL Control using PDFium)### Loading the project into XE7 comes up with a couple of compile errors which are easily fixed, but running it and opening a PDF file results in an access violation.

The access violation has nothing to do with the compile errors I fixed. They were in two button click events on the main form that I’m not using yet.
Those were because objects from a TObjectList are being assigned to a TPDFObject variable without being typecasted.
(“for obj in FCtrl.Document.Pages[0].Objects do” where obj is a TPDFObject, and that doesn’t compile on subsequent lines where obj properties are accessed without being typecasted . Do later versions of Delphi allow that?)### The real issue however is the access violation which occurs in the PdfiumCore.pas TPdfBitmap.FillRect procedure.
Can anyone who is using this shed some light on this?

Hi John, I had some spare time so I have downloaded PDFiumLib and the DLLs and had a play. If I use the 64-bit version of the DLL the application simply dies without error. However, the 32-bit version of the DLL works fine (except for the errors you noted)… ensure change Target Platform to ‘Windows 32-bit’. Copy the DLL to the same folder as the EXE. I added a new button (as below) to show a msg with the pages count - all good. HTH… Cheers, Kim.

procedure TfrmMain.btnPagesClick(Sender: TObject);
ShowMessage('Pages = '+ inttostr(FCtrl.Document.PageCount));

Hi Kim,

Thank you for doing that.

Changed the example project to 32-bit and placed the 32 bit version of pdfium.dll in the right place but I’m still getting an access violation when it attempts to load a pdf file.


I’m not sure if it was just a typo, but you mentioned that you downloaded Dlls, as in plural. Could you please let me know which Dlls if any, are involved besides pdfium.dll?

Many thanks.

Hi John, I was just referring to both 32- and 64-bit versions of the DLL located at:

Did you want me to ZIP-up my source code and attach it to an email for you?

Hello again John,

This could be a problem with another (perhaps incompatible) version of pdfium.dll already being loaded in memory. The following link details the search order for DLLs:

Note that I myself have other versions of the DLL on my system, for e.g. in:

  • EaseUS Data Recovery Wizard;

  • TheBrain; and

  • Microsoft Power Bl Desktop.

If any other these programs should be running then the PDFium sample may possibly find an already loaded version first.

Good luck…

I’m using DevExpress’s PDF components. It’s easy and works well. Comes with sources too – which was good for me, because I needed to add an extra PDF field to the code, for page orientation, to be able to read it. Not free at all, though.


Ah yes, of course. Makes sense.

I wonder if pdfium.dll has dependencies on other resources that you have on your system but I don’t.

I’ve tried running this on a number of computers but always results in the access violation when it attempts to load a pdf.

I know it’s based on Chromium 4660. Not sure if that’s encapsulated in pdfium.dll or if I need something in addition.

Mmmm. I sent the below post before Alexander’s post and Kim’s most recent post below it. Maybe I should stop replying using email and post all replies in the forum to avoid timing mess-ups. :blush:

Okay, I have the pfdium example working in both 32bit and 64bit.

There is an unitialised poiner in Pdfiumcore.pas which is causing the problem.

I added ”BmpBits := nil;” to the code as indicated where the stars are below. No more access violation.

procedure TPdfPage.Draw(bitmap : TBitmap; Rotate: TPdfPageRotation; const Options: TPdfPageRenderOptions);


PdfBmp: TPdfBitmap;

BitmapInfo: TBitmapInfo;

Bmp, OldBmp: HBITMAP;

BmpBits: Pointer;


vbmp : TBitmap;




******* BmpBits := nil; *******

PdfBmp := TPdfBitmap.Create(bitmap.Width, bitmap.Height, bfBGRA, BmpBits, bitmap.Width * 4);


if Transparency then

PdfBmp.FillRect(0, 0, bitmap.Width, bitmap.Height, $00FFFFFF)


PdfBmp.FillRect(0, 0, bitmap.Width, bitmap.Height, $FFFFFFFF);

DrawToPdfBitmap(PdfBmp, 0, 0, bitmap.Width, bitmap.Height, Rotate, Options);

DrawFormToPdfBitmap(PdfBmp, 0, 0, bitmap.Width, bitmap.Height, Rotate, Options);





…… more lines

Thank you to everyone for their help.

Hi John. My (closed) issue on github says Sep 2020. It says :

Readme states:

Required pdfium.dll version

But pdfiumlib.pas states: 4243

The files I have still compile and run now under Delphi 11, and did with whatever I used back then too.

  • Just checking … that the pdf is in a directory /x86 or /x64 under the exe file.

  • the (32 bit) pdfium.dll I have says 4044kb, and came from a directory I have as “bin x86 4243 V8 FA”

  • I had also tried one from “bin x86 4194 V8 FA” and it is 16,551kb which did not work.

I will go get the 4660 version it now mentions in the readme and try that as well.

(none of these dlls show a version under ‘properties’ for me. that’s not helpful) :slight_smile:

[ Edit:
Sorry, browser page was open about 12 hrs and I didn’t see the recent updates. ]