Skip to content

Commit

Permalink
Experiment: produce PDF with Puppeteer (#6)
Browse files Browse the repository at this point in the history
This is currently only a sketch of how the final solution could look
like.

Still missing:
- [x] parameterize with filename and variables from meta.yaml
- [x] integrate into Github workflow
- [x] only generate PDF if HTML or Markdown have changed
- [ ] extract inline styles to `odata.css`?
  • Loading branch information
ralfhandl authored Jun 2, 2023
1 parent 93122d8 commit 06313fe
Show file tree
Hide file tree
Showing 7 changed files with 1,445 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
git config user.name ${GITHUB_ACTOR}
git config user.email ${PUSHER_EMAIL}
git add docs/*/*.html docs/*/*.md
git diff-index --quiet HEAD || git commit -m "auto-refreshed"
git diff-index --quiet HEAD || (npm run pdf --if-present && git add docs/*/*.pdf && git commit -m "auto-refreshed")
git push
env:
PUSHER_EMAIL: ${{ github.event.pusher.email }}
Binary file not shown.
4 changes: 4 additions & 0 deletions lib/build-pdf.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import pdf from './pdf.js';
import url from "url";

await pdf("odata-data-aggregation-ext");
31 changes: 31 additions & 0 deletions lib/pdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const puppeteer = require('puppeteer');
const fs = require("fs");
const url = require("url");
const yaml = require("js-yaml");

module.exports = async function(name) {
const meta = yaml.load(fs.readFileSync(__dirname + "/../" + name + "/meta.yaml"));

const browser = await puppeteer.launch({
headless: "new"
});
const page = await browser.newPage();
const htmlUrl = url.pathToFileURL(`${__dirname}/../docs/${name}/${name}.html`).href;
await page.goto(htmlUrl, {
waitUntil: "networkidle2",
});
await page.pdf({
path: `${__dirname}/../docs/${name}/${name}.pdf`,
format: "letter",
displayHeaderFooter: true,
headerTemplate: '<div style="font-size: 10px; width: 100%; text-align: center;">Standards Track Work Product</div>',
footerTemplate: `<div style="font-size: 8px; width: 90%; margin: auto; margin-top: 40px; display:flex; flex-flow:row wrap;">
<span style="text-align: left; width: 30%;">${meta.filename}</span>
<span style="text-align: center; width: 40%;">Copyright ${meta.copyright}. All Rights Reserved.</span>
<span style="text-align: right; width: 30%;">${meta.pubdate} - Page <span class="pageNumber"></span> of <span class="totalPages"></span>
</span></div>`,
margin: { top: 50, bottom: 60 }
});

await browser.close();
}
1 change: 1 addition & 0 deletions odata-data-aggregation-ext/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pagetitle: OData Extension for Data Aggregation Version 4.0
subtitle: Committee Specification Draft 04
filename: odata-data-aggregation-ext-csd04
pubdate: 24 May 2023
pubdateISO: '2023-05-24'
copyright: © OASIS Open 2023
Loading

0 comments on commit 06313fe

Please sign in to comment.