PDFNet.initialize() Issues

Product: PDFTron / Webviewer

Product Version: @pdftron/webviewer": “^8.3.0”,

Please give a brief summary of your issue:
(Think of this as an email subject)

Having issues with the following line

PDFNet.initialize()

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
I am attempting to create a downloadable PDF that is merged with exported annotations from PDFtron.
Since I have a URL to the PDF I want to merge I was planning on using

await PDFNet.PDFDoc.createFromURL(downloadUrl);

However, I get an error logged from PDFTron saying I need to run the following line first.

await PDFNet.initialize()

Unfortunately the init on my dev server just hangs and any code below it is not run despite it working fine in a local environment. In fact the PDF download works fine with or without the init. I have also tried passing in my license which seems to have no effect on the issue. Is there anything specific I can look into as why there would be a discrepancy between the two environments? The rest of PDFTron is currently working fine in both environments and that seems to be the only line where behavior changes.

Thanks.

Please provide a link to a minimal sample where the issue is reproducible:

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:APIs:Forums:

Hello Ryan,

The only thing that comes to mind is perhaps the workers are not available in your dev environment.
In which case, there should be an error thrown in the console.
Are there any errors thrown in the console from WebViewer?

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

The only errors we get from PDFTron are when we do not include PDFNet.initialize(), it throws an error saying to run it before calling PDFNet.PDFDoc.createFromURL. However in our local env we do not run initialize at all and everything works fine.

Hello Ryan,

The PDFNet.initialize is automatically run by the WebViewer code at some point. But to ensure it is ready when you require it, it’s best to initialize PDFNet yourself.
Are you able to send your WebViewer code, in which you call PDFNet.initialize() so I can reproduce the issue to look into it further?

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

  addViewerDownloadButton(): void {
    const saveButton = {
      type: 'actionButton',
      className: 'row',
      dataElement: 'downloadButton',
      label: 'Download',
      img: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z"/></svg>',
      onClick: async () => {
        const downloadUrl = await this.documentService
          .getDocumentForDownload(this.currentDocumentId)
          .toPromise();
        await this.wvInstance.Core.PDFNet.initialize();

        const doc = await this.wvInstance.Core.PDFNet.PDFDoc.createFromURL(
          downloadUrl
        );
        const annotations =
          await this.wvInstance.Core.annotationManager.exportAnnotations();
        await doc.mergeXFDFString(annotations);

        const buffer = await doc.saveMemoryBuffer(
          this.wvInstance.Core.PDFNet.SDFDoc.SaveOptions.e_linearized
        );
        const blob = new Blob([buffer], { type: 'application/pdf' });
        saveAs(blob, this.currentDocumentName);
      },

      this.wvInstance.UI.settingsMenuOverlay.add(
        [saveButton],
        'fullscreenButton'
      );
    };

This is the code we are using to add a download link into PDFtron. Like I mentioned before, on our local env there are no errors thrown. In fact the initalize line is not even required for the code to work. However when ran on our dev env, we get the error to run PDFNet.initialize() if this line is not included, and when we do include it, the error disappears but no code after the initialize is ever run.

Hi Ryan,

After further investigation, it appears your dataElement is clashing with the existing dataElement for the built-in download button. Please change the dataElement of your added button and see if it still doesn’t work.

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

Ah I am just realizing now you have a native download button. Instead I tried to comment out this version and use the native but it appears that

this.wvInstance.UI.enableElements(['downloadButton']);

and

instance.UI.enableFeatures(instance.Feature.Download);

is not working in our app. Is there anything you can recommend to debug this?

Hi Ryan,

What version of WebViewer are you using? Are you able to update to the latest?
Does it still not work in the latest version?

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

It looks like we are on version 8.5.0 and I believe we could update it if needed, would that fix the issue for us?

Hi Ryan,

Can you please send your WebViewer initialization code?
Also please update to the latest as it might fix the issue and since it’s a minor release, all your previous code should also work.

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

    this.wvInstance = await WebViewer(
      {
        path: 'assets/lib/',
        licenseKey: this.initialLoadService.initialLoad.tokens['PdfTronWebViewerKey'],
        enableAzureWorkaround: true,
        accessibleMode: true,
        annotationUser: 'You',
        fullAPI: true,
      },
      this.viewerRef.nativeElement
    );

This is the initialization code.

Hi Ryan,

I have found that some license keys do not have the download button functionality. Can you please email me your license key so I can check?

email

amoaaz@pdftron.com

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com

Hi Ryan,

It looks like your license key is not read-only so should be able to use the built-in download.
Were you able to update and did it fix your issue?
Please ensure you do not have any calls like this to disable the download button:

UI.disableElements(['downloadButton'])
UI.disableFeatures([UI.Feature.Download]);

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.
www.pdftron.com