diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b512c09d476623ff4bf8d0d63c29b784925dbdf8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/bin/paged b/bin/paged index 36835f2214b3e88e9d2a0bd187a2b137c8e96f79..040ac1db58dc8f94eaebf8e7320fe6e76857a7f8 100755 --- a/bin/paged +++ b/bin/paged @@ -38,6 +38,8 @@ let relativePath = path.resolve(dir, input); let output; let tmpFile, tmpPath; +let headless = typeof program.debug === "undefined"; + // var hyphenator; // var hyphenateOptions; @@ -66,8 +68,6 @@ if (typeof(program.output) === "string") { output = "output.pdf"; } -console.log("output", output, program.output); - /* if (program.hyphenate) { hyphenateOptions = { @@ -96,7 +96,7 @@ if (program.hyphenate) { (async () => { const browser = await puppeteer.launch({ - // headless: false, + headless: headless // args: ['--no-sandbox', '--allow-file-access-from-files', '--enable-local-file-accesses'] }); @@ -113,36 +113,47 @@ if (program.hyphenate) { let server = app.listen(PORT); - await page.goto(`http://localhost:${PORT}/print/${basename}`); + await page.goto(`http://localhost:${PORT}/print/${basename}?preview=true`); - await page.addScriptTag({ - url: `http://localhost:${PORT}/polyfill/paged.polyfill.js` + await page.exposeFunction('PuppeteerLogger', (msg, counter) => { + console.log(msg, counter); }); await page.exposeFunction('onPagesRendered', async (msg, width, height, orientation) => { - console.log(msg); - console.log("Saved to", output); - let pdf = await page.pdf({ - path: output, - printBackground: true, - displayHeaderFooter: false, - width: width, - height: height, - orientation: orientation, - margin: { - top: 0, - right: 0, - bottom: 0, - left: 0, - }, - // format: 'A4' - }).catch((e) => { - console.error(e); - }) - - server.close(); - - await browser.close(); + console.log(msg, width, height, orientation); + + if (headless) { + let pages = await page.waitForSelector(".pages"); + let pdf = await page.pdf({ + path: output, + printBackground: true, + displayHeaderFooter: false, + width: width, + height: height, + orientation: orientation, + margin: { + top: 0, + right: 0, + bottom: 0, + left: 0, + }, + // format: 'A4' + }).catch((e) => { + console.error(e); + }); + + console.log("Saved to", output); + + server.close(); + + await browser.close(); + } + + + }); + + await page.addScriptTag({ + url: `http://localhost:${PORT}/polyfill/paged.polyfill.js` }); })(); diff --git a/test/samples/aurorae/book.css b/test/samples/aurorae/book.css index 833f8f92ed7a190e2db27ac0c78090c38deec360..5028fa30dd8a75ec5ac0474ca4ad27f8931df2e0 100644 --- a/test/samples/aurorae/book.css +++ b/test/samples/aurorae/book.css @@ -158,6 +158,20 @@ section[data-type="epigraph"], font-variant-numeric: oldstyle-nums; } +.shorter:nth(1) { + position: running(shorter1); +} + +.shorter:nth(2) { + position: running(shorter2); +} + +.page:nth(1) { + content: --var-1; +} + +--var-1 = dataurl:svg + /* flexbox */ section[data-type="copyright"] #flexbox {