javascriptreactjspdftron

Untick Include Annotation Checkbox by default in PDFTron PrintModal


As per my knowledge, there is no explicit properties given in pdftron to untick Include Annotation Checkbox which is checked by default. You can go to https://www.pdftron.com/webviewer/demo/ and see the print modal by pressing ctrl+P: Print Modal Image

So I am looking for work around in javascript, to make it disaable, having id "include-annotations". The issue is when the code runs, dom object is 'NULL', then after some time that same code works on console.

How to make this trigger when print modal dom gets loaded.

document.addEventListener("keydown", (e) => {
                if (e.ctrlKey && e.code === "KeyP") {
const annotationUncheck = document.getElementById(
                         "include-annotations"
                    ) as HTMLElement;
                    annotationUncheck.click(); 
}
            });

Solution

  • The reason why document.getElementById("include-annotations") is coming up as null, is because Webviewer runs inside an iframe and its components will not be part of the main DOM. To get the checkbox from inside the iFrame and uncheck it, you can use this code:

    WebViewer({...}, viewerElement).then(function (instance) {
      const { UI } = instance;
      UI.iframeWindow.document.getElementById("include-annotations").click();
    });
    

    Here is the relevant API for getting the iFrame window. https://www.pdftron.com/api/web/UI.html#.iframeWindow