• Resolved tobiasnolimitation

    (@tobiasnolimitation)


    How can I set a default Zoom level, using the PDF Embedder premium plugin? I want it to be Automatic Zoom.

    It would be nice to be able to set it once just, so it does not have to be set for each url, if it possible. But any solution is wanted.

    Alternate solution would be if there is a JS event that fires when the PDF is loaded, then I could set the zoom level with JS probably.

    Thank you in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi, @tobiasnolimitation!
    Thanks for contacting us.

    This is a requested feature and will definitely be in future updates ??

    Thanks for sharing it, and have a good one!

    Thread Starter tobiasnolimitation

    (@tobiasnolimitation)

    Thank you for this.

    For anyone else looking for a solution to this, here is how I solved it with JavaScript.

    //Change the default zoom on the PDF Viewer
    
    //Loop through all the PDF Embedder iframes
    let pdfIframes = document.querySelectorAll(".pdfembed-iframe");
    
    pdfIframes.forEach(iframe => {
        iframe.addEventListener('load', () => {
            //Pdf viewer class
            let pdfViewer = iframe.contentWindow.PDFViewerApplication; //Events in EventBus and everything else can be found by console.log(pdfViewer)
    
            //When the PDF is loaded, change the scale
            pdfViewer.eventBus._on("pagesloaded", () => {
                changeScaleInPdfViewer(iframe, "auto");
            });
        });
    });
    
    function changeScaleInPdfViewer(iframe, scale) {
        //Change the value of the select
        iframe.contentWindow.document.querySelector("#wppdf-iframe-body #scaleSelect").value = "auto";
    
        setTimeout(() => { //Await for the select to change
            //Dispatch the event in the PDF Viewer Application class
            iframe.contentWindow.PDFViewerApplication.eventBus.dispatch('scalechanged', {'value': 'auto'});
        }, 10)
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Default zoom level’ is closed to new replies.