From 2af2b336045c5f244d29ea37e4c14868cb20524f Mon Sep 17 00:00:00 2001 From: deathemperor <4255482+deathemperor@users.noreply.github.com> Date: Wed, 15 Nov 2023 00:35:10 +0700 Subject: [PATCH] address issue with missing fonts https://github.com/ol-th/pdf-img-convert.js/issues/42 --- pdf-img-convert.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pdf-img-convert.js b/pdf-img-convert.js index 01e8c64..ce016e9 100644 --- a/pdf-img-convert.js +++ b/pdf-img-convert.js @@ -29,6 +29,7 @@ const Canvas = require("canvas"); const assert = require("assert").strict; const fs = require("fs"); const util = require('util'); +const path = require('path'); const readFile = util.promisify(fs.readFile); @@ -96,8 +97,10 @@ module.exports.convert = async function (pdf, conversion_config = {}) { // At this point, we want to convert the pdf data into a 2D array representing // the images (indexed like array[page][pixel]) + var packagePath = path.dirname(require.resolve("pdfjs-dist/package.json")); + var outputPages = []; - var loadingTask = pdfjs.getDocument({data: pdfData, disableFontFace: true, verbosity: 0}); + var loadingTask = pdfjs.getDocument({data: pdfData, disableFontFace: true, verbosity: 0, standardFontDataUrl: packagePath + '/standard_fonts/'}); var pdfDocument = await loadingTask.promise