Skip to content
Snippets Groups Projects
Commit 6e7b1076 authored by Fred Chasen's avatar Fred Chasen
Browse files

Merge branch 'eslint' into 'master'

Add eslint and fix errors

See merge request tools/pagedjs-cli!8
parents 17f68e9b 68ac65b3
No related branches found
No related tags found
1 merge request!8Add eslint and fix errors
Pipeline #30144 failed with stages
in 2 seconds
#!/usr/bin/env node #!/usr/bin/env node
const program = require('commander'); const program = require("commander");
const ora = require('ora'); const ora = require("ora");
const Printer = require("../"); const Printer = require("../");
const path = require('path'); const path = require("path");
const fs = require('fs'); const fs = require("fs");
const { promisify } = require('util'); // const { promisify } = require("util");
const writeFileAsync = promisify(fs.writeFile); // const writeFileAsync = promisify(fs.writeFile);
const replaceExt = require('replace-ext'); const replaceExt = require("replace-ext");
program program
.version(require('../package.json').version) .version(require("../package.json").version)
.arguments('[inputPath]') .arguments("[inputPath]")
.option('-i, --inputs [inputs]', 'Inputs') .option("-i, --inputs [inputs]", "Inputs")
.option('-o, --output [output]', 'Output') .option("-o, --output [output]", "Output")
.option('-d, --debug', 'Debug') .option("-d, --debug", "Debug")
.option('-l, --landscape', 'Landscape printing', false) .option("-l, --landscape", "Landscape printing", false)
.option('-s, --page-size [size]', 'Print to Page Size [size]') .option("-s, --page-size [size]", "Print to Page Size [size]")
.option('-w, --width [size]', 'Print to Page Width [width] in MM') .option("-w, --width [size]", "Print to Page Width [width] in MM")
.option('-h --height [size]', 'Print to Page Height [weight] in MM') .option("-h --height [size]", "Print to Page Height [weight] in MM")
// .option('-m, --page-margin [margin]', 'Print with margin [margin]') // .option("-m, --page-margin [margin]", "Print with margin [margin]")
// .option('-n, --hyphenate [lang]', 'Hyphenate with language [language], defaults to "en-us"') // .option("-n, --hyphenate [lang]", "Hyphenate with language [language], defaults to "en-us"")
// .option('-hi, --hypher_ignore [str]', 'Ignore passed element selectors, such as ".class_to_ignore, h1"') // .option("-hi, --hypher_ignore [str]", "Ignore passed element selectors, such as ".class_to_ignore, h1"")
// .option('-ho, --hypher_only [str]', 'Only hyphenate passed elements selector, such as ".hyphenate, aside"') // .option("-ho, --hypher_only [str]", "Only hyphenate passed elements selector, such as ".hyphenate, aside"")
// .option('-e, --encoding [type]', 'Set the encoding of the input html, defaults to "utf-8"') // .option("-e, --encoding [type]", "Set the encoding of the input html, defaults to "utf-8"")
.option('-t, --timeout [ms]', 'Set a max timeout of [ms]') .option("-t, --timeout [ms]", "Set a max timeout of [ms]")
.option('-x, --html', 'output html file') .option("-x, --html", "output html file")
.option('-b, --blockLocal', 'Disallow access to filesystem for local files') .option("-b, --blockLocal", "Disallow access to filesystem for local files")
.option('--outline-tags [tags]', 'Specifies that an outline should be ' + .option("--outline-tags [tags]", "Specifies that an outline should be " +
'generated for the resulting PDF document. [tags] specifies which ' + "generated for the resulting PDF document. [tags] specifies which " +
'HTML tags should be considered for that outline. ' + "HTML tags should be considered for that outline. " +
'"h1,h2" will trigger an outline with "h1" tags as root elements ' + "\"h1,h2\" will trigger an outline with \"h1\" tags as root elements " +
'and "h2" elements as their childs.') "and \"h2\" elements as their childs.")
.parse(process.argv); .parse(process.argv);
...@@ -38,19 +38,17 @@ let input = program.inputs || program.args[0]; ...@@ -38,19 +38,17 @@ let input = program.inputs || program.args[0];
let dir = process.cwd(); let dir = process.cwd();
let url;
let relativePath; let relativePath;
let allowLocal; let allowLocal;
try { try {
url = new URL(input); new URL(input);
allowLocal = false; allowLocal = false;
} catch { } catch (error) {
relativePath = path.resolve(dir, input); relativePath = path.resolve(dir, input);
allowLocal = !program.blockLocal; allowLocal = !program.blockLocal;
} }
let output; let output;
let tmpFile, tmpPath;
let headless = typeof program.debug === "undefined"; let headless = typeof program.debug === "undefined";
...@@ -64,7 +62,7 @@ if (!input) { ...@@ -64,7 +62,7 @@ if (!input) {
if (relativePath) { if (relativePath) {
if (['.html', '.xhtml'].indexOf(path.extname(relativePath)) === -1) { if ([".html", ".xhtml"].indexOf(path.extname(relativePath)) === -1) {
console.error("Must pass a html or xhtml file as input"); console.error("Must pass a html or xhtml file as input");
return process.exit(1); return process.exit(1);
} }
...@@ -80,7 +78,7 @@ if (relativePath) { ...@@ -80,7 +78,7 @@ if (relativePath) {
if (typeof(program.output) === "string") { if (typeof(program.output) === "string") {
output = path.resolve(dir, program.output); output = path.resolve(dir, program.output);
} else if (typeof(program.output) !== "undefined") { } else if (typeof(program.output) !== "undefined") {
output = './' + replaceExt(path.basename(input), '.pdf'); output = "./" + replaceExt(path.basename(input), ".pdf");
} else { } else {
output = "output.pdf"; output = "output.pdf";
} }
...@@ -88,7 +86,7 @@ if (typeof(program.output) === "string") { ...@@ -88,7 +86,7 @@ if (typeof(program.output) === "string") {
const spinner = ora({ const spinner = ora({
spinner: "circleQuarters" spinner: "circleQuarters"
}) });
if (typeof input === "string") { if (typeof input === "string") {
...@@ -106,7 +104,7 @@ if (typeof input === "string") { ...@@ -106,7 +104,7 @@ if (typeof input === "string") {
spinner.start("Rendering: Page " + (page.position + 1)); spinner.start("Rendering: Page " + (page.position + 1));
} else { } else {
spinner.text = "Rendering: Page " + (page.position + 1) spinner.text = "Rendering: Page " + (page.position + 1);
} }
}); });
...@@ -125,9 +123,9 @@ if (typeof input === "string") { ...@@ -125,9 +123,9 @@ if (typeof input === "string") {
let options = {}; let options = {};
if (program.html) { if (program.html) {
file = await printer.html(input, options); file = await printer.html(input, options);
output = replaceExt(output, '.html'); output = replaceExt(output, ".html");
} else { } else {
options.outlineTags = !program.outlineTags ? [] : program.outlineTags.split(','); options.outlineTags = !program.outlineTags ? [] : program.outlineTags.split(",");
file = await printer.pdf(input, options); file = await printer.pdf(input, options);
} }
} else { } else {
......
This diff is collapsed.
...@@ -11,24 +11,25 @@ ...@@ -11,24 +11,25 @@
"bin": "./bin/paged", "bin": "./bin/paged",
"scripts": { "scripts": {
"start": "./bin/paged", "start": "./bin/paged",
"build": "pkg ." "build": "pkg .",
"lint": "./node_modules/.bin/eslint src bin/paged"
}, },
"main": "index.js", "main": "index.js",
"dependencies": { "dependencies": {
"commander": "^2.20.0", "commander": "^3.0.2",
"express": "^4.16.4", "express": "^4.17.1",
"hyphenopoly": "^3.0.1", "hyphenopoly": "^3.2.1",
"katex": "^0.10.1", "katex": "^0.11.1",
"lodash": "^4.17.11", "lodash": "^4.17.15",
"mathjax": "^2.7.5", "mathjax": "^3.0.0",
"node-fetch": "^2.4.1", "node-fetch": "^2.6.0",
"ora": "^3.4.0", "ora": "^4.0.2",
"pagedjs": "^0.1.34", "pagedjs": "0.1.34",
"pdf-lib": "^0.6.1", "pdf-lib": "^1.2.0",
"puppeteer": "^1.15.0", "puppeteer": "^1.20.0",
"replace-ext": "^1.0.0" "replace-ext": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^5.16.0" "eslint": "^6.5.1"
} }
} }
const PDFLib = require("pdf-lib"); const PDFLib = require("pdf-lib");
const EventEmitter = require('events'); const EventEmitter = require("events");
const PDFDocumentWriter = require('./writer'); const PDFDocumentWriter = require("./writer");
class PostProcesser extends EventEmitter { class PostProcesser extends EventEmitter {
constructor(pdf) { constructor(pdf) {
super(); super();
if (!pdf) { if (!pdf) {
throw "Must pass a PDF Buffer to PostProcesser" throw "Must pass a PDF Buffer to PostProcesser";
} }
this.pdf = pdf this.pdf = pdf;
this.pdfDoc = PDFLib.PDFDocumentFactory.load(pdf); this.pdfDoc = PDFLib.PDFDocumentFactory.load(pdf);
} }
...@@ -58,7 +58,7 @@ class PostProcesser extends EventEmitter { ...@@ -58,7 +58,7 @@ class PostProcesser extends EventEmitter {
modDate: info.getMaybe("ModDate") && info.getMaybe("ModDate").string, modDate: info.getMaybe("ModDate") && info.getMaybe("ModDate").string,
creator: info.getMaybe("Creator") && info.getMaybe("Creator").string, creator: info.getMaybe("Creator") && info.getMaybe("Creator").string,
producer: info.getMaybe("Producer") && info.getMaybe("Producer").string producer: info.getMaybe("Producer") && info.getMaybe("Producer").string
} };
} }
updateInfoDict(meta) { updateInfoDict(meta) {
...@@ -100,9 +100,9 @@ class PostProcesser extends EventEmitter { ...@@ -100,9 +100,9 @@ class PostProcesser extends EventEmitter {
} }
addXmpMetadata(meta) { addXmpMetadata(meta) {
const charCodes = (str) => str.split('').map((c) => c.charCodeAt(0)); const charCodes = (str) => str.split("").map((c) => c.charCodeAt(0));
const typedArrayFor = (str) => new Uint8Array(charCodes(str)); const typedArrayFor = (str) => new Uint8Array(charCodes(str));
const whitespacePadding = new Array(20).fill(' '.repeat(100)).join('\n'); const whitespacePadding = new Array(20).fill(" ".repeat(100)).join("\n");
const metadataXML = ` const metadataXML = `
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?> <?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.2-c001 63.139439, 2010/09/27-13:37:26"> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.2-c001 63.139439, 2010/09/27-13:37:26">
...@@ -124,7 +124,7 @@ class PostProcesser extends EventEmitter { ...@@ -124,7 +124,7 @@ class PostProcesser extends EventEmitter {
<rdf:Bag> <rdf:Bag>
${meta.keywords ${meta.keywords
.map((keyword) => `<rdf:li>${keyword}</rdf:li>`) .map((keyword) => `<rdf:li>${keyword}</rdf:li>`)
.join('\n')} .join("\n")}
</rdf:Bag> </rdf:Bag>
</dc:subject> </dc:subject>
</rdf:Description> </rdf:Description>
...@@ -149,8 +149,8 @@ class PostProcesser extends EventEmitter { ...@@ -149,8 +149,8 @@ class PostProcesser extends EventEmitter {
const metadataStreamDict = PDFLib.PDFDictionary.from( const metadataStreamDict = PDFLib.PDFDictionary.from(
{ {
Type: PDFLib.PDFName.from('Metadata'), Type: PDFLib.PDFName.from("Metadata"),
Subtype: PDFLib.PDFName.from('XML'), Subtype: PDFLib.PDFName.from("XML"),
Length: PDFLib.PDFNumber.fromNumber(metadataXML.length), Length: PDFLib.PDFNumber.fromNumber(metadataXML.length),
}, },
this.pdfDoc.index, this.pdfDoc.index,
...@@ -163,8 +163,8 @@ class PostProcesser extends EventEmitter { ...@@ -163,8 +163,8 @@ class PostProcesser extends EventEmitter {
const metadataStreamRef = this.pdfDoc.register(metadataStream); const metadataStreamRef = this.pdfDoc.register(metadataStream);
this.pdfDoc.catalog.set('Metadata', metadataStreamRef); this.pdfDoc.catalog.set("Metadata", metadataStreamRef);
}; }
boxes(pages) { boxes(pages) {
const pdfPages = this.pdfDoc.getPages(); const pdfPages = this.pdfDoc.getPages();
...@@ -205,17 +205,17 @@ class PostProcesser extends EventEmitter { ...@@ -205,17 +205,17 @@ class PostProcesser extends EventEmitter {
/** /**
* Adds a table of content to the generated PDF * Adds a table of content to the generated PDF
* *
* Ideally this would not be required if Chromium would add this directly. * Ideally this would not be required if Chromium would add this directly.
* So if these bugs are closed this can probably be removed again: * So if these bugs are closed this can probably be removed again:
* - https://bugs.chromium.org/p/chromium/issues/detail?id=840455 * - https://bugs.chromium.org/p/chromium/issues/detail?id=840455
* - https://github.com/GoogleChrome/puppeteer/issues/1778 * - https://github.com/GoogleChrome/puppeteer/issues/1778
* *
* This code is heavily based on @Hopding's comment at: * This code is heavily based on @Hopding's comment at:
* https://github.com/Hopding/pdf-lib/issues/127#issuecomment-502450179 * https://github.com/Hopding/pdf-lib/issues/127#issuecomment-502450179
*/ */
addOutline(outlineSpec) { addOutline(outlineSpec) {
const outline = JSON.parse(JSON.stringify(outlineSpec)) const outline = JSON.parse(JSON.stringify(outlineSpec));
const pageRefs = []; const pageRefs = [];
...@@ -234,7 +234,7 @@ class PostProcesser extends EventEmitter { ...@@ -234,7 +234,7 @@ class PostProcesser extends EventEmitter {
count += countOutlineLayer(outlineEntry.children); count += countOutlineLayer(outlineEntry.children);
} }
return count; return count;
} };
const createItemsForOutlineLayer = (layer, parent) => { const createItemsForOutlineLayer = (layer, parent) => {
layer.forEach((outlineItem, i) => { layer.forEach((outlineItem, i) => {
...@@ -243,13 +243,13 @@ class PostProcesser extends EventEmitter { ...@@ -243,13 +243,13 @@ class PostProcesser extends EventEmitter {
const pdfItem = createOutlineItem(outlineItem, prev, next, parent); const pdfItem = createOutlineItem(outlineItem, prev, next, parent);
index.assign(outlineItem.ref, pdfItem); index.assign(outlineItem.ref, pdfItem);
}); });
} };
const createOutlineItem = (outlineItem, prev, next, parent) => { const createOutlineItem = (outlineItem, prev, next, parent) => {
if (!outlineItem.id) { if (!outlineItem.id) {
throw new Error(`Cannot generate outline item with title '${outlineItem.title} ` + throw new Error(`Cannot generate outline item with title '${outlineItem.title} ` +
`without any target anchor. Please specify an 'id' attribute for ` + "without any target anchor. Please specify an 'id' attribute for " +
`the relevant HTML element`); "the relevant HTML element");
} }
const item = { const item = {
Title: PDFLib.PDFString.fromString(outlineItem.title), Title: PDFLib.PDFString.fromString(outlineItem.title),
...@@ -277,14 +277,14 @@ class PostProcesser extends EventEmitter { ...@@ -277,14 +277,14 @@ class PostProcesser extends EventEmitter {
for (const child of outlineEntry.children) { for (const child of outlineEntry.children) {
createOutlineReferences(child); createOutlineReferences(child);
} }
} };
for (const outlineItem of outline) { for (const outlineItem of outline) {
createOutlineReferences(outlineItem); createOutlineReferences(outlineItem);
} }
createItemsForOutlineLayer(outline, outlineReference); createItemsForOutlineLayer(outline, outlineReference);
const pdfOutline = PDFLib.PDFDictionary.from( const pdfOutline = PDFLib.PDFDictionary.from(
{ {
First: outline[0].ref, First: outline[0].ref,
...@@ -294,7 +294,7 @@ class PostProcesser extends EventEmitter { ...@@ -294,7 +294,7 @@ class PostProcesser extends EventEmitter {
index, index,
); );
index.assign(outlineReference, pdfOutline); index.assign(outlineReference, pdfOutline);
this.pdfDoc.catalog.set('Outlines', outlineReference); this.pdfDoc.catalog.set("Outlines", outlineReference);
} }
save() { save() {
......
const Paged = require('pagedjs'); const EventEmitter = require("events");
const EventEmitter = require('events'); const puppeteer = require("puppeteer");
const puppeteer = require('puppeteer');
const util = require('util');
const fs = require('fs');
const fetch = require("node-fetch"); const fetch = require("node-fetch");
const path = require('path'); const path = require("path");
let dir = process.cwd(); let dir = process.cwd();
...@@ -14,7 +11,7 @@ let pagedjsLocation = require.resolve("pagedjs/dist/paged.polyfill.js"); ...@@ -14,7 +11,7 @@ let pagedjsLocation = require.resolve("pagedjs/dist/paged.polyfill.js");
let paths = pagedjsLocation.split("node_modules"); let paths = pagedjsLocation.split("node_modules");
let scriptPath = paths[0] + "node_modules" + paths[paths.length-1]; let scriptPath = paths[0] + "node_modules" + paths[paths.length-1];
const PostProcesser = require('./postprocesser'); const PostProcesser = require("./postprocesser");
class Printer extends EventEmitter { class Printer extends EventEmitter {
constructor(headless, allowLocal) { constructor(headless, allowLocal) {
...@@ -27,7 +24,7 @@ class Printer extends EventEmitter { ...@@ -27,7 +24,7 @@ class Printer extends EventEmitter {
async setup() { async setup() {
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
headless: this.headless, headless: this.headless,
args: this.allowLocal ? ['--allow-file-access-from-files', '--disable-dev-shm-usage'] : ['--disable-dev-shm-usage'], args: this.allowLocal ? ["--allow-file-access-from-files", "--disable-dev-shm-usage"] : ["--disable-dev-shm-usage"],
ignoreHTTPSErrors: true ignoreHTTPSErrors: true
}); });
...@@ -54,10 +51,10 @@ class Printer extends EventEmitter { ...@@ -54,10 +51,10 @@ class Printer extends EventEmitter {
uri = new URL(input); uri = new URL(input);
if (uri.protocol === "https:") { if (uri.protocol === "https:") {
html = await fetch(input) html = await fetch(input)
.then(res => res.text()) .then(res => res.text());
} }
url = input; url = input;
} catch { } catch (error) {
let relativePath = path.resolve(dir, input); let relativePath = path.resolve(dir, input);
url = "file://" + relativePath; url = "file://" + relativePath;
} }
...@@ -101,15 +98,15 @@ class Printer extends EventEmitter { ...@@ -101,15 +98,15 @@ class Printer extends EventEmitter {
path: scriptPath path: scriptPath
}); });
// await page.exposeFunction('PuppeteerLogger', (msg) => { // await page.exposeFunction("PuppeteerLogger", (msg) => {
// console.log(msg); // console.log(msg);
// }); // });
await page.exposeFunction('onSize', (size) => { await page.exposeFunction("onSize", (size) => {
this.emit("size", size); this.emit("size", size);
}); });
await page.exposeFunction('onPage', (page) => { await page.exposeFunction("onPage", (page) => {
// console.log("page", page.position + 1); // console.log("page", page.position + 1);
this.pages.push(page); this.pages.push(page);
...@@ -117,7 +114,7 @@ class Printer extends EventEmitter { ...@@ -117,7 +114,7 @@ class Printer extends EventEmitter {
this.emit("page", page); this.emit("page", page);
}); });
await page.exposeFunction('onRendered', (msg, width, height, orientation) => { await page.exposeFunction("onRendered", (msg, width, height, orientation) => {
this.emit("rendered", msg, width, height, orientation); this.emit("rendered", msg, width, height, orientation);
resolver({msg, width, height, orientation}); resolver({msg, width, height, orientation});
}); });
...@@ -146,7 +143,7 @@ class Printer extends EventEmitter { ...@@ -146,7 +143,7 @@ class Printer extends EventEmitter {
x: getPointsValue(cropbox.x) - getPointsValue(mediabox.x), x: getPointsValue(cropbox.x) - getPointsValue(mediabox.x),
y: getPointsValue(cropbox.y) - getPointsValue(mediabox.y) y: getPointsValue(cropbox.y) - getPointsValue(mediabox.y)
} }
} };
window.onPage({ id, width, height, startToken, endToken, breakAfter, breakBefore, position, boxes }); window.onPage({ id, width, height, startToken, endToken, breakAfter, breakBefore, position, boxes });
}); });
...@@ -173,7 +170,7 @@ class Printer extends EventEmitter { ...@@ -173,7 +170,7 @@ class Printer extends EventEmitter {
async _parseOutline(page, tags) { async _parseOutline(page, tags) {
return await page.evaluate((tags) => { return await page.evaluate((tags) => {
const tagsToProcess = []; const tagsToProcess = [];
for (const node of document.querySelectorAll(tags.join(','))) { for (const node of document.querySelectorAll(tags.join(","))) {
tagsToProcess.push(node); tagsToProcess.push(node);
} }
tagsToProcess.reverse(); tagsToProcess.reverse();
...@@ -212,8 +209,8 @@ class Printer extends EventEmitter { ...@@ -212,8 +209,8 @@ class Printer extends EventEmitter {
for (const child of node.children) { for (const child of node.children) {
stripParentProperty(child); stripParentProperty(child);
} }
} };
stripParentProperty(root) stripParentProperty(root);
return root.children; return root.children;
}, tags); }, tags);
} }
...@@ -233,7 +230,7 @@ class Printer extends EventEmitter { ...@@ -233,7 +230,7 @@ class Printer extends EventEmitter {
if (tag.name) { if (tag.name) {
meta[tag.name] = tag.content; meta[tag.name] = tag.content;
} }
}) });
return meta; return meta;
}); });
...@@ -252,7 +249,7 @@ class Printer extends EventEmitter { ...@@ -252,7 +249,7 @@ class Printer extends EventEmitter {
bottom: 0, bottom: 0,
left: 0, left: 0,
} }
} };
let pdf = await page.pdf(settings) let pdf = await page.pdf(settings)
.catch((e) => { .catch((e) => {
......
const PDFLib = require("pdf-lib"); const PDFLib = require("pdf-lib");
const isFunction = require( 'lodash/isFunction' ); const isFunction = require( "lodash/isFunction" );
const last = require( 'lodash/last' ); const last = require( "lodash/last" );
const sortBy = require( 'lodash/sortBy' ); const sortBy = require( "lodash/sortBy" );
const PDFXRefTableFactory = require( 'pdf-lib/lib/core/pdf-structures/factories/PDFXRefTableFactory' ).default; const PDFXRefTableFactory = require( "pdf-lib/lib/core/pdf-structures/factories/PDFXRefTableFactory" ).default;
const createIndirectObjectsFromIndex = ({ index }) => { const createIndirectObjectsFromIndex = ({ index }) => {
let catalogRef; let catalogRef;
...@@ -45,7 +45,7 @@ class PDFDocumentWriter extends PDFLib.PDFDocumentWriter { ...@@ -45,7 +45,7 @@ class PDFDocumentWriter extends PDFLib.PDFDocumentWriter {
nonStreamObjects, nonStreamObjects,
} = createIndirectObjectsFromIndex(pdfDoc.index); } = createIndirectObjectsFromIndex(pdfDoc.index);
if (!catalogRef) error('Missing PDFCatalog'); if (!catalogRef) console.error("Missing PDFCatalog");
streamObjects.forEach((streamObj) => { streamObjects.forEach((streamObj) => {
if (isFunction(streamObj.pdfObject.encode)) streamObj.pdfObject.encode(); if (isFunction(streamObj.pdfObject.encode)) streamObj.pdfObject.encode();
}); });
...@@ -53,7 +53,7 @@ class PDFDocumentWriter extends PDFLib.PDFDocumentWriter { ...@@ -53,7 +53,7 @@ class PDFDocumentWriter extends PDFLib.PDFDocumentWriter {
const merged = [...streamObjects, ...nonStreamObjects]; const merged = [...streamObjects, ...nonStreamObjects];
const offsets = computeOffsets(pdfDoc.header.bytesSize(), merged); const offsets = computeOffsets(pdfDoc.header.bytesSize(), merged);
const sortedOffsets = sortBy(offsets, 'objectNumber'); const sortedOffsets = sortBy(offsets, "objectNumber");
/* ===== (2) Create XRefTable and Trailer ===== */ /* ===== (2) Create XRefTable and Trailer ===== */
const table = PDFXRefTableFactory.forOffsets(sortedOffsets); const table = PDFXRefTableFactory.forOffsets(sortedOffsets);
...@@ -74,6 +74,8 @@ class PDFDocumentWriter extends PDFLib.PDFDocumentWriter { ...@@ -74,6 +74,8 @@ class PDFDocumentWriter extends PDFLib.PDFDocumentWriter {
const bufferSize = tableOffset + table.bytesSize() + trailer.bytesSize(); const bufferSize = tableOffset + table.bytesSize() + trailer.bytesSize();
const buffer = new Uint8Array(bufferSize); const buffer = new Uint8Array(bufferSize);
/* eslint-disable no-unused-vars */
// TODO: how is remaining used?
let remaining = pdfDoc.header.copyBytesInto(buffer); let remaining = pdfDoc.header.copyBytesInto(buffer);
remaining = merged.reduce( remaining = merged.reduce(
(remBytes, indirectObj) => indirectObj.copyBytesInto(remBytes), (remBytes, indirectObj) => indirectObj.copyBytesInto(remBytes),
...@@ -81,6 +83,7 @@ class PDFDocumentWriter extends PDFLib.PDFDocumentWriter { ...@@ -81,6 +83,7 @@ class PDFDocumentWriter extends PDFLib.PDFDocumentWriter {
); );
remaining = table.copyBytesInto(remaining); remaining = table.copyBytesInto(remaining);
remaining = trailer.copyBytesInto(remaining); remaining = trailer.copyBytesInto(remaining);
/* eslint-enable no-unused-vars */
return buffer; return buffer;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment