I have integrated PDF JS into my Vue3 project to overlay a
<canvas id="draw_canvas">
on the rendered pdf document. This allows me to draw rectangles programmatically over the pdf, serving as markers for specific areas.
The rendering process of a pdf file using PDF JS involves placing each page's content inside separate <canvas>
elements. In my project, I have two Vue Single File Components (SFCs) named App
and Child
. The Child
component loads and displays the pdf's pages (3 in total) within a scrollable container
<div id="pages_container">
, which is nested inside another <div id="doc_container">
.
To dynamically adjust the height of
<canvas id="draw_canvas">
as the <div id="pages_container">
expands, I utilize a ResizeObserver
that monitors changes in the size of the <div id="pages_container">
and updates the canvas' height to match its offsetHeight.