electron/spec/fixtures/api/pdf-reader.mjs
trop[bot] d62c324567
fix: enable wasm trap handlers in all Node.js processes (#48837)
* fix: enable wasm trap handlers in all Node.js processes

Co-authored-by: deepak1556 <hop2deep@gmail.com>

* fix: separate registrations to account for featurelist init

Co-authored-by: deepak1556 <hop2deep@gmail.com>

* build: add missing header for SetStackDumpFirstChanceCallback

* fix: pdf spec

delay load pdfjs-dist which compiles wasm on load, trap handlers
will be initialized once the user script starts but before app#ready.

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
2025-11-11 18:45:57 +09:00

24 lines
613 B
JavaScript

import { app } from 'electron';
async function getPDFDoc () {
try {
const pdfjs = await import('pdfjs-dist');
const doc = await pdfjs.getDocument(process.argv[2]).promise;
const page = await doc.getPage(1);
const { items } = await page.getTextContent();
const markInfo = await doc.getMarkInfo();
const pdfInfo = {
numPages: doc.numPages,
view: page.view,
textContent: items,
markInfo
};
console.log(JSON.stringify(pdfInfo));
process.exit();
} catch (ex) {
console.error(ex);
process.exit(1);
}
}
app.whenReady().then(() => getPDFDoc());