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;
}
});