diff --git a/src/main/PDFOperations.js b/src/main/PDFOperations.js index a2494ba..b466921 100644 --- a/src/main/PDFOperations.js +++ b/src/main/PDFOperations.js @@ -441,10 +441,16 @@ async function loadPdfjs() { // Points pdfjs-dist at its bundled standard font metrics so it doesn't warn // (and degrade text-extraction fidelity) when a PDF uses a standard font. +// pdfjs validates this as a URL that must end with a forward slash — a raw +// Windows path (C:\...\standard_fonts\) fails that check and breaks +// extractText/extractImages on Windows, so always hand pdfjs a file:// URL. function getStandardFontDataUrl() { - return ( - path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'standard_fonts') + path.sep + const dir = path.join( + path.dirname(require.resolve('pdfjs-dist/package.json')), + 'standard_fonts' ); + const url = require('url').pathToFileURL(dir); + return url.href.endsWith('/') ? url.href : url.href + '/'; } async function pdfExtractText(data) { diff --git a/tests/main/PDFBatchOperations.test.js b/tests/main/PDFBatchOperations.test.js index f3c2c61..8eba832 100644 --- a/tests/main/PDFBatchOperations.test.js +++ b/tests/main/PDFBatchOperations.test.js @@ -293,7 +293,9 @@ describe('PDFBatchOperations - runPDFBatchOperation', () => { operation: 'compress', outputFolder: path.join(blocker, 'child'), data: {}, - sanitizeError: (message) => message.replace(new RegExp(path.sep, 'g'), '_SANITIZED_'), + // path.sep is "\" on Windows — escape it for RegExp use + sanitizeError: (message) => + message.replace(new RegExp(path.sep.replace(/\\/g, '\\\\'), 'g'), '_SANITIZED_'), }); expect(completion.success).toBe(false);