Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can give relative URL, e.g <code>pdfPath="pdf/TestDocument.pdf"</code>.</p> <p>Following is a sample code created out of examples provided on Github:</p> <pre><code>PDFJS.workerSrc ='PATH_TO_WORKER_LOADER/worker_loader.js'; pdfDoc = PDFJS.getDocument(pdfPath); pdfDoc.then(renderPdf); function renderPdf(pdfDoc) { pdfNumPages = pdfDoc.numPages; pdfDoc.getPage(1).then(renderPage); } function renderPage(page) { var viewport = page.getViewport(scale); var $canvas = jQuery("&lt;canvas&gt;&lt;/canvas&gt;"); //Set the canvas height and width to the height and width of the viewport var canvas = $canvas.get(0); var context = canvas.getContext("2d"); canvas.height = viewport.height; canvas.width = viewport.width; //Append the canvas to the pdf container div (refer a div in your HTML file) var $editorTextArea = jQuery("#editorTextArea"); $editorTextArea.css("height", canvas.height + "px").css("width", canvas.width + "px"); $editorTextArea.append($canvas); var canvasOffset = $canvas.offset(); var $textLayerDiv = jQuery("&lt;div /&gt;") .addClass("textLayer") .css("height", viewport.height + "px") .css("width", viewport.width + "px") .offset({ top: canvasOffset.top, left: canvasOffset.left }); //The following few lines of code set up scaling on the context if we are on a HiDPI display var outputScale = getOutputScale(context); if (outputScale.scaled) { var cssScale = 'scale(' + (1 / outputScale.sx) + ', ' + (1 / outputScale.sy) + ')'; CustomStyle.setProp('transform', canvas, cssScale); CustomStyle.setProp('transformOrigin', canvas, '0% 0%'); } context._scaleX = outputScale.sx; context._scaleY = outputScale.sy; if (outputScale.scaled) { context.scale(outputScale.sx, outputScale.sy); } var renderContext = { canvasContext: context, viewport: viewport, textLayer: textLayer }; page.render(renderContext); }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload