I am using pdf.js to show some pdf file with react project, actually using react-pdf which wrapped the pdf.js. Now I am using scale like this to zoom in or zoom out the pdf:
<Page
key={index + "@new-" + projAttribute.pdfScale}
scale={projAttribute.pdfScale}
className={styles.pdfPage}
onLoad={handlePageChange}
canvasRef={(element) => updateRefArray(index, element)}
onChange={handlePageChange}
onRenderSuccess={handlePageRenderSuccess}
pageNumber={index}
width={width}
>
{curPdfPosition && viewPort ? (
<Highlight
position={curPdfPosition}
pageNumber={index}
viewport={viewPort}
></Highlight>
) : (
<div></div>
)}
</Page>
and this is how I get the viewport:
React.useEffect(() => {
setPageViewports(undefined);
if (!pdf) {
return;
}
(async () => {
const pageNumbers = Array.from(new Array(pdf.numPages)).map(
(_, index) => index + 1
);
const nextPageViewports = await asyncMap(
pageNumbers,
(pageNumber: number) =>
pdf
.getPage(pageNumber)
.then((page) =>
page.getViewport({ scale: projAttr.pdfScale || 1 })
)
);
setPageViewports(nextPageViewports);
})();
}, [pdf]);
should I change the viewport scale or keep it with the same with pdf scale(the pdf scale range is 0.1-6.0, and + or – 0.1 with each click) when zoom the pdf? or what value should I set with the viewport scale?
