Currently, I am using pdf.js to display a PDF file in my Ionic App. Instead of utilizing viewer.js and viewer.html, I have created a custom layout with a unique search bar. One feature I am looking to implement is the ability to highlight terms within the PDF file. Is there a specific function that can be called to achieve this?
The method I am using to render the file is as follows:
$scope.renderPages = function(pdfDoc) {
$scope.pdfFile = pdfDoc;
for(var num = 1; num <= pdfDoc.numPages; num++){
pdfDoc.getPage(num).then($scope.renderPage);
}
}
$scope.renderPage = function(page) {
var viewport = page.getViewport(1);
scale = document.getElementById('viewer').clientWidth / viewport.width;
viewport = page.getViewport(scale);
var canvas = document.createElement('canvas');
var ctx = canvas.getContext('2d');
var renderContext = {
canvasContext: ctx,
viewport: viewport
};
canvas.height = viewport.height;
canvas.width = viewport.width;
var canvasContainer = document.getElementById('viewer');
canvasContainer.appendChild(canvas);
page.render(renderContext);
}
In the HTML section:
<div id="viewerContainer" style="padding-bottom: 100%; padding-top: 20px;">
<div id="viewer" class="viewer-styles">
</div>
</div>