How to use the pdfjs-dist/build/pdf.js.GlobalWorkerOptions function in pdfjs-dist

To help you get started, we’ve selected a few pdfjs-dist examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CircuitCoder / Console-Lite / shared / util.js View on Github external
const pdfjs = require('pdfjs-dist/build/pdf.js');
const Trie = require('./trie');
const pinyin = require('pinyin');
const MarkdownIt = require('markdown-it');

pdfjs.GlobalWorkerOptions.workerSrc = require.resolve('pdfjs-dist/build/pdf.worker.js');

/* Set scale = -1 to auto-scale */

function renderPDF(content, scale, elem, targetWidth) {
  return pdfjs.getDocument(content).then(pdf => {
    const promises = [];
    for(let i = 1; i <= pdf.numPages; ++i)
      promises.push(pdf.getPage(i).then(page => {
        let _scale = scale;
        if(_scale === -1) {
          const svp = page.getViewport(1);
          _scale = targetWidth / svp.width;
          console.log(_scale);
        }

        const vp = page.getViewport(_scale);