33 lines
947 B
JavaScript
33 lines
947 B
JavaScript
import fs from "fs";
|
|
import { getDocument } from "file://C:\\Users\\kj131\\pdf-forge\\pdf.js\\build\\dist\\build\\pdf.min.mjs";
|
|
|
|
// Some PDFs need external cmaps.
|
|
const CMAP_URL = "../node_modules/pdfjs-dist/cmaps/";
|
|
const CMAP_PACKED = true;
|
|
|
|
// Where the standard fonts are located.
|
|
const STANDARD_FONT_DATA_URL =
|
|
"../node_modules/pdfjs-dist/standard_fonts/";
|
|
|
|
// Loading file from file system into typed array.
|
|
const pdfPath =
|
|
process.argv[2] || "ISO_32000-2_2020(en).pdf";
|
|
const data = new Uint8Array(fs.readFileSync(pdfPath));
|
|
|
|
// Load the PDF file.
|
|
const loadingTask = getDocument({
|
|
data,
|
|
cMapUrl: CMAP_URL,
|
|
cMapPacked: CMAP_PACKED,
|
|
standardFontDataUrl: STANDARD_FONT_DATA_URL,
|
|
});
|
|
try {
|
|
const pdfDocument = await loadingTask.promise;
|
|
console.log("# PDF document loaded.");
|
|
const page = await pdfDocument.getPage(1);
|
|
const opList = await page.getOperatorList();
|
|
console.log(opList);
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|