0

I have been following this tutorial to embed a PDF on my website using PDF.js. But I only want to embed a certain part, ie. a section in the middle of the PDF page. Is there a smart way to do this? Can I somehow crop the PDF displayed?

I use this code to render the pdf

const scale = 1,
canvas = document.querySelector('#pdf-render'),
ctx = canvas.getContext('2d');


const renderPage = num => {

pageIsRendering = true;

//get the page

pdfDoc.getPage(num).then(page => {

    //set scale

    const viewport = page.getViewport({scale});
    canvas.height = viewport.height;
    canvas.width =  viewport.width;

    const renderCtx = {
        canvasContext: ctx,
        viewport
    };

    page.render(renderCtx).promise.then(() => {
        pageIsRendering = false;

        if(pageNumIsPending !== null){
            renderPage(pageNumIsPending);
            pageNumIsPending = null;
        }
    });
Joel
  • 1
  • 2
  • It might be good to include a bit more detail of what you're doing so far. It's unlikely anyone reading your question is going to sit down and watch a Youtube video before answering. – IMSoP Feb 02 '21 at 09:19
  • Does this answer your question? [How to display whole PDF (not only one page) with PDF.JS?](https://stackoverflow.com/questions/16480469/how-to-display-whole-pdf-not-only-one-page-with-pdf-js) – ponsfrilus Feb 02 '21 at 09:34
  • @ponsfrilus I dont think it does, as I want to do the opposite. (He wants to have multiple pages on one canvas and I only want a part of the page.) Unless you can tell me which elements from the post I need. But thank you anyways :) – Joel Feb 02 '21 at 09:57

0 Answers0