Skip to content

Commit ec95ee8

Browse files
committed
Use Node to generate PDF instead
1 parent 381097c commit ec95ee8

File tree

3 files changed

+109
-27
lines changed

3 files changed

+109
-27
lines changed

.gitignore

+64-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
book.pdf
2-
3-
# Created by https://www.gitignore.io/api/ruby,linux,jekyll
1+
# Created by https://www.gitignore.io/api/node,ruby,linux,jekyll
42

53
### Jekyll ###
64
_site/
@@ -22,6 +20,67 @@ _site/
2220
# .nfs files are created when an open file is removed but is still being accessed
2321
.nfs*
2422

23+
### Node ###
24+
# Logs
25+
logs
26+
*.log
27+
npm-debug.log*
28+
yarn-debug.log*
29+
yarn-error.log*
30+
31+
# Runtime data
32+
pids
33+
*.pid
34+
*.seed
35+
*.pid.lock
36+
37+
# Directory for instrumented libs generated by jscoverage/JSCover
38+
lib-cov
39+
40+
# Coverage directory used by tools like istanbul
41+
coverage
42+
43+
# nyc test coverage
44+
.nyc_output
45+
46+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
47+
.grunt
48+
49+
# Bower dependency directory (https://bower.io/)
50+
bower_components
51+
52+
# node-waf configuration
53+
.lock-wscript
54+
55+
# Compiled binary addons (http://nodejs.org/api/addons.html)
56+
build/Release
57+
58+
# Dependency directories
59+
node_modules/
60+
jspm_packages/
61+
62+
# Typescript v1 declaration files
63+
typings/
64+
65+
# Optional npm cache directory
66+
.npm
67+
68+
# Optional eslint cache
69+
.eslintcache
70+
71+
# Optional REPL history
72+
.node_repl_history
73+
74+
# Output of 'npm pack'
75+
*.tgz
76+
77+
# Yarn Integrity file
78+
.yarn-integrity
79+
80+
# dotenv environment variables file
81+
.env
82+
83+
2584
### Ruby ###
2685
*.gem
2786
*.rbc
@@ -34,6 +93,7 @@ _site/
3493
/test/tmp/
3594
/test/version_tmp/
3695
/tmp/
96+
package-lock.json
3797

3898
# Used by dotenv library to load environment variables.
3999
# .env
@@ -74,4 +134,4 @@ build-iPhoneSimulator/
74134
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
75135
.rvmrc
76136

77-
# End of https://www.gitignore.io/api/ruby,linux,jekyll
137+
# End of https://www.gitignore.io/api/node,ruby,linux,jekyll

utils/convert_to_pdf.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
---
3+
"use strict";
4+
5+
const puppeteer = require("puppeteer")
6+
const fs = require("fs")
7+
const os = require("os")
8+
9+
var links = {{ site.data.links_en | jsonify }};
10+
11+
(async() => {
12+
const browser = await puppeteer.launch()
13+
const page = await browser.newPage()
14+
15+
var root = "file:///" + __dirname + "/../en/"
16+
console.log("Root is: " + root)
17+
18+
for (var i = 0; i < links.length; i++) {
19+
var link = links[i]
20+
if (link.link) {
21+
console.log("Rendering " + link.title)
22+
await page.goto(root + link.link, {waitUntil: "networkidle"})
23+
24+
// page.pdf() is currently supported only in headless mode.
25+
// @see https://bugs.chromium.org/p/chromium/issues/detail?id=753118
26+
const margin = "0.2in"
27+
await page.pdf({
28+
path: "tmp/page_" + (link.num || ("0_" + link.title.replace(".", "_"))) + ".pdf",
29+
format: "A5",
30+
margin: {
31+
top: margin,
32+
right: margin,
33+
bottom: margin,
34+
left: margin,
35+
}
36+
})
37+
}
38+
}
39+
browser.close()
40+
41+
})()

utils/convert_to_pdf.sh

+4-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
1-
---
2-
---
31
#!/bin/sh
42

5-
oldCWD="$PWD"
6-
cd $(dirname $0)
7-
cd ../en/
8-
9-
#wkhtmltopdf --print-media-type {% for link in site.data.links_en %}{% if link.link %}{{ link.link }} {% endif %}{% endfor %} out.pdf
10-
#mv out.pdf $oldCWD/book.pdf
11-
12-
{% for link in site.data.links_en %}
13-
{% if link.link %}
14-
/opt/google/chrome/google-chrome --headless --disable-gpu --print-to-pdf file:///${PWD}/{{ link.link }}
15-
16-
{% if link.num %}
17-
mv output.pdf page_{{ link.num }}.pdf
18-
{% else %}
19-
mv output.pdf page_0_{{ link.link | replace:".","_" }}.pdf
20-
{% endif %}
21-
22-
{% endif %}
23-
{% endfor %}
24-
25-
pdfunite page*.pdf ${oldCWD}/book.pdf
3+
jekyll build
4+
mkdir -p tmp
5+
n use latest _site/utils/convert_to_pdf.js
6+
pdfunite tmp/page*.pdf tmp/book.pdf

0 commit comments

Comments
 (0)