Some checks failed
CI / Test (20) (push) Has been cancelled
CI / Test (22) (push) Has been cancelled
CI / Test (23) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Lint / Lint (lts/*) (push) Has been cancelled
Types tests / Test (lts/*) (push) Has been cancelled
32 lines
920 B
JavaScript
32 lines
920 B
JavaScript
import fs from "fs";
|
|
import { getDocument } from "../../build/dist/build/pdf.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] || "../../web/compressed.tracemonkey-pldi-09.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 table = await pdfDocument.getStreamAsString("/Page2/Contents/0/Data");
|
|
console.log(table);
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|