How to Get the Current PDF Page from C# in an External Viewer
Question details
Determine the current page number of a PDF document opened in a third-party viewer using a custom C# application.

- Product
- PDF Viewer
- Device & OS
- not provided
- Scenario
- A developer needs to track or read the active page state of a PDF currently opened in another host application via a C# program.
- Observed behavior
- The C# application requires an API, automation framework, or interprocess communication method to successfully extract the current page index from the external PDF viewer.
Identify the exact host application (e.g., Adobe Acrobat, WPS PDF, or a web browser) where the PDF is opened, as the required integration method depends entirely on the specific API exposed by that PDF viewer.
Utilize Application-Specific COM APIs
The most reliable method to interact with a standalone PDF viewer is through its official COM Interop API, provided the host application supports it.
Many professional desktop PDF applications provide a COM interface that allows external programs written in C# to control the application and read its state.
You must have the target PDF software installed on the machine running the C# code to successfully reference and use its COM objects.
Check the developer documentation for your specific PDF viewer to find the name of its COM library or SDK.
Open your project in Visual Studio, right-click 'References', select 'Add Reference', navigate to the 'COM' tab, and select the PDF viewer's type library.
Instantiate the application's main object in your C# code, access the active document or active view property, and query the 'CurrentPage' or 'CurrentPageIndex' attribute.

Implement Windows UI Automation
If the PDF viewer does not offer an official API, you can programmatically read the current page number directly from the application's user interface.
Switch to WPS Office for Seamless PDF and Document Management
Whether you are managing complex PDF workflows or creating daily documents, WPS Office provides a lightweight, highly compatible, and free alternative to Microsoft Office. It seamlessly integrates a powerful PDF reader and editor alongside standard word processing, spreadsheet, and presentation tools in a single familiar interface.

Frequently Asked Questions
Can I get the current PDF page from a web browser using C#?
Extracting the active page from a browser's built-in PDF viewer is difficult because modern browsers do not expose a public COM API for their internal plugins. You typically need to use browser automation frameworks like Selenium or PuppeteerSharp instead.
Why does my C# COM Interop code throw an exception?
An exception usually occurs if the target PDF application is not installed on the machine running the code, or if there is an architecture mismatch (e.g., calling a 32-bit COM object from a 64-bit C# process).
Does WPS Office provide APIs for developers?
Yes, WPS Office offers developer APIs and SDKs designed for enterprise integration, allowing developers to automate document handling, perform format conversions, and interact with the WPS Office application programmatically.




