Disable loading all annotatnions on load

Product: PDFTron WebViewer

Product Version: 8.0.0

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

Is there any possibility to not load all current annotatnions while loading PDF?

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
Is there any possibility to not load all current annotatnions while loading PDF?
I assume that all links in PDF document are treated like annotatnions, so for larger files it takes a few minutes to generate document content. So I want to know how I can disable loading all existing annotatnions when document content is loaded.

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

Hi,

You can try set the “enableAnnotations” option to be false when initializing WebViewer, please see PDFTron WebViewer Global

Thanks.

Wanbo

So I need to use this as an option when initialize WebViewer, and then am I able to enable Annotatnion again using viewerLoaded event?

Best Regards,

Also I can see that this option isn’t working.
Maybe I use it incorrect.
Here is how i use it:

WebViewer(
        {
            path: "http://localhost:@BridgeSettings.WebPort/lib/PDFViewer/lib",
            initialDoc: "http://localhost:@BridgeSettings.WebPort/Signing/GetPDF",
            licenseKey: "",
            css: "http://localhost:@BridgeSettings.WebPort/lib/PDFViewer/lib/ui/buttons.css",
            enableAnnotations: false
        },
        viewerElement

I’m also using annotationChanged event like here:

annotationManager.addEventListener('annotationChanged',
            (annotations, action) => {
                if (action === 'add') {

                    // My code here
                    console.log("create");
                }
                else if (action === 'modify') {
                    console.log('this change modified annotations');
                }
                else if (action === 'delete') {
                    console.log("delete");
                    // My code here
                }
                annotations.forEach((annot) => {
                    console.log(`Page Number: ${annot.PageNumber} X: ${annot.getX ()} Y: ${annot.getY ()}`);
                    console.log(`width: ${annot.getWidth ()} Height: ${annot.getHeight ()}`);
                    console.log(docViewer.getPageHeight(annot.PageNumber));
                    // My code here
                });
            });

And after setting enableAnnotatnions to false I still get info about loaded annotatnions like here:

image

How can I fix it?

If you see annotations not loaded in the document and annotation tools are hidden, then it means that the option is working properly.

It is as you wrote.
I cannot use annotatnion tool, but links are still threated as annotations and are loaded when document is loading.
How can I turn that off? Every link is like annotation, so for bigger documents it takes a lot of time to load the document. I want to avoid that, and make the load time as short as possible.

Hi,

Another way is to use this code but pass the empty string into the callback function https://www.pdftron.com/documentation/web/guides/annotation/import-export/advanced-load/

Could you give it a try?

Thanks.

Wanbo

I tried it.
Here is my code, and error which i get.

Code:

docViewer.setPagesUpdatedInternalAnnotationsTransform((xfdfData, callback) => {
           
            callback("");
        });

Error:
image

Please follow the first example, which uses “(xfdfData, pageList, callback)”.

I copied the whole example, still the same error message.

Could you attach your code here? Thanks.

Hi!

Here is my code.

WebViewer(
{
    path: "http://localhost:@BridgeSettings.WebPort/lib/PDFViewer/lib",
    initialDoc: "http://localhost:@BridgeSettings.WebPort/Signing/GetPDF",
    licenseKey: "license_key",
    css: "http://localhost:@BridgeSettings.WebPort/lib/PDFViewer/lib/ui/buttons.css"
            //enableAnnotations: false
        },
        viewerElement
        ).then((instance) => {
         

            instance.closeElements('rubberStampOverlay');
            instance.UI.disableElement('customStampPanelButton');


        /*
        * My code (not important in this case)
        */

        
        docViewer.setPagesUpdatedInternalAnnotationsTransform((xfdfData, callback) => {
           
            const parser = new DOMParser ();
            const xfdfElements = parser.parseFromString(xfdfData, 'text/xml');
            [].forEach.call(xfdfElements.querySelectorAll('link'),
                e => {
                    e.parentNode.removeChild(e);
                });

            const serializer = new XMLSerializer ();
            callback(serializer.serializeToString(xfdfElements));
        });
        

        /*
        * My code (not important in this case)
        */


        const myStamp = 'http://localhost:@BridgeSettings.WebPort/sample.svg';
        // instance.docViewer.getTool(instance.Tools.ToolNames.RUBBER_STAMP).setStandardStamps([myStamp]);

        const myStamp1 = 'http://localhost:@BridgeSettings.WebPort/sample1.svg';
        instance.docViewer.getTool(instance.Tools.ToolNames.RUBBER_STAMP).setStandardStamps([myStamp, myStamp1]);

        //tool.setCustomStamps(customStamp);

        /*
        * My code (not important in this case)
        */

        docViewer.on('annotationsLoaded',
            () => {
                console.log("LOADED!!!!");
                const annotations = annotationManager.getAnnotationsList ();
                /*
        * My code (not important in this case)
        */

    });
        annotationManager.addEventListener('annotationChanged',
            (annotations, action) => {
                if (action === 'add') {

                    /*
        * My code (not important in this case)
        */
        console.log("create");
    }
    else if (action === 'modify') {
        console.log('this change modified annotations');
    }
    else if (action === 'delete') {
        console.log("delete");
                   /*
        * My code (not important in this case)
        */
    }
    annotations.forEach((annot) => {
                    /*
        * My code (not important in this case)
        */
        console.log(annot);
    });
});

        /*
        * My code (not important in this case)
        */
    });

Hello,

Any Ideas?

Thanks

Hi,

Looks like in your code, you still have two parameters here instead of the (xfdfData, pageList, callback) which is in the first example in https://www.pdftron.com/documentation/web/guides/annotation/import-export/advanced-load/