How to access the current PDF document?

Product: PDFNet SDK for C#

Product Version: 9.3.0

Please give a brief summary of your issue:
How is it possible to access the current PDF document loaded via Toolbar?

Please describe your issue and provide steps to reproduce it:
I use the PdfViewCtrl in a Windows Forms application, with ShowToolbar set to true. Once a PDF file is opened via the toolbars “open” menu, I am not able to access the current PDF file in order to (for example) edit it. I tried it with the “PdfViewCtrl.GetDoc()” method, but that returns null. How is it possible to access the current PDF document (of type PDFDoc)?

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:Forums:

Yes PDFViewCtrl.GetDoc is what you use. Perhaps you are running into some sort of timing issue where PDFViewCtrl.SetDoc has not sufficiently completed.

Can you reproduce using one of our samples? If yes, please provide the exact steps and any modified code.

Hi Ryan, unfortunately there is no sample for the use of PdfViewCtrl with WinForms that uses the build-in toolbar. This is my code where I want to access the current PDF document, but somehow it is always null when the PDF is loaded via the toolbar (it works somehow when I use a custom menu to load the PDF, as in the PDFViewSimple example). Is there a way to load the PDF via toolbar and somehow handle that event so that I can assign the loaded PDF to a global variable of type PdfDoc?

Thanks for help
Niels

public Form1()
{
    InitializeComponent();
    PDFNet.Initialize(PDFTronLicense.Key);
    _pdfView = pdfViewCtrl;
    _pdfView.ShowToolbar(true);
    _pdfView.SetCurrentPageHandler(new PDFViewCurrentPageDelegate(OnLoad), this);
}
private void OnLoad(int current_page, int num_pages, object obj)
{
    var doc = _pdfView?.GetDoc(); // doc is always null when I load a PDF via the toolbar.
}