how do i resize a pdf with js?

I have updated the code.

if (pageNumber >= 1 && pageNumber <= doc._pdfInfo.numPages) {
    
        // Fetch the page
        const page = await doc.getPage(pageNumber);
    
        // Set the viewport
         let scale;
        if(window.innerWidth < 662px) {
           scale = 0.75
        } else {
           scale = 1
        }
        const viewport = page.getViewport({ scale });
    
        // Set the canvas dimensions to the PDF page dimensions
        const canvas = document.getElementById("canvas");
        const context = canvas.getContext("2d");
        canvas.height = viewport.height;
        canvas.width = viewport.width;
    
        // Render the PDF page into the canvas context
        return await page.render({
            canvasContext: context,
            viewport: viewport
        }).promise;
    
    } else {
        console.log("Please specify a valid page number");
    }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top