Skip to content

Commit 5d8b46c

Browse files
committed
0.6.0
- make chrome installs chroumium to Application's priv dir - document all this
1 parent 97984f1 commit 5d8b46c

File tree

6 files changed

+129
-99
lines changed

6 files changed

+129
-99
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ erl_crash.dump
55
/doc
66
.elixir_ls
77
/priv/node_modules
8+
rebar.version
9+
hex.info
10+
check_env

CHANGES.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
# Changes
22

3+
- 0.6.0
4+
- introducting `make` as build tool (optional) for chromium binaries
5+
(puppeteer)
6+
- **BUGFIX:** documentation: option `pagesize` requires string argument
7+
(for example `"letter"` or `"A4"`)
8+
- updated some npm dependencies for chromium
9+
- 0.5.7
10+
- **BUGFIX:** fix chrome-option parameter handling
311
- 0.5.6
412
- **BUGFIX:** fix A4 and A5 paper sizes in inches for **chrome-headless**:
5-
it's not 8.5 x 11.0 (US letter) but 8.26772 x 11.695 (DIN A4), the former
6-
being chrome-headless defaults. This is important if you want to create
7-
proper A4 pages
8-
- Users printing **US letter** sized PDFs, please use `page_size: :letter`
13+
it's not 8.5 x 11.0 (US letter) but 8.26772 x 11.695 (DIN A4), the former
14+
being chrome-headless defaults. This is important if you want to create
15+
proper A4 pages
16+
- Users printing **US letter** sized PDFs, please use `page_size: "letter"`
917
- 0.5.5
1018
- improved documentation on `prefer_system_executable: true` for chrome.
1119
Thanks to [Martin Richer](https://github.com/richeterre) for rasining this

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,7 @@ run-test: check_env _build/test test
4848
run-dev: check_env _build/dev
4949
iex -S mix
5050

51-
build: check_env priv/node_modules _build/prod
51+
build: check_env _build/prod
52+
53+
chrome: check_env priv/node_modules _build/prod
54+

README.md

+108-92
Original file line numberDiff line numberDiff line change
@@ -3,103 +3,17 @@
33
A wrapper for both wkhtmltopdf and chrome-headless plus PDFTK (adds in
44
encryption) for use in Elixir projects.
55

6-
```Elixir
7-
{:ok, pdf} = PdfGenerator.generate_binary("<html><body><h1>Yay!</h1></body></html>")
8-
```
6+
# Latest release v0.6.0 on 2019-12-17
97

10-
# Latest release v0.5.5 – v0.5.8 on 2019-12-17
11-
12-
- 0.5.8
8+
- 0.6.0
9+
- introducting `make` as build tool (optional) for chromium binaries
10+
(puppeteer)
1311
- **BUGFIX:** documentation: option `pagesize` requires string argument
1412
(for example `"letter"` or `"A4"`)
1513
- updated some npm dependencies for chromium
16-
- 0.5.7
17-
- **BUGFIX:** fix chrome-option parameter handling
18-
- 0.5.6
19-
- **BUGFIX:** fix A4 and A5 paper sizes in inches for **chrome-headless**:
20-
it's not 8.5 x 11.0 (US letter) but 8.26772 x 11.695 (DIN A4), the former
21-
being chrome-headless defaults. This is important if you want to create
22-
proper A4 pages
23-
- Users printing **US letter** sized PDFs, please use `page_size: "letter"`
24-
- 0.5.5
25-
- improved documentation on `prefer_system_executable: true` for chrome.
26-
Thanks to [Martin Richer](https://github.com/richeterre) for rasining this
27-
and a [PR](https://github.com/gutschilla/elixir-pdf-generator/pull/55)
28-
- improved documentation on `no_sandbox: true` for chrome in dockerized
29-
environment (running as root)
30-
- clarify that wkhtmltopdf installation snippet is for Ubuntu 18.04.
31-
- log call options as debug info to Logger
32-
- add "knows issues" section to README
3314

3415
For a proper changelog, see [CHANGES](CHANGES.md)
3516

36-
# System prerequisites
37-
38-
It's either
39-
40-
* wkhtmltopdf or
41-
42-
* nodejs and possibly chrome/chromium
43-
44-
## chrome-headless
45-
46-
This will allow you to make more use of Javascript and advanced CSS as it's just
47-
your Chrome/Chromium browser rendering your web page as HTML and printing it as
48-
PDF. Rendering _tend_ to be a bit faster than with wkhtmltopdf. The price tag is
49-
that PDFs printed with chrome/chromium are usually considerably bigger than
50-
those generated with wkhtmltopdf.
51-
52-
1. Run `npm -g install chrome-headless-render-pdf puppeteer`.
53-
54-
This requires [nodejs](https://nodejs.org), of course. This will install a
55-
recent chromium and chromedriver to run Chrome in headless mode and use this
56-
browser and its API to print PDFs globally on your machine.
57-
58-
If you prefer a project-local install, just use `npm install` This will
59-
install dependencies under `./node_modules`. Be aware that those won't be
60-
packaged in your distribution (I will add support for this later).
61-
62-
On some machines, this doesn't install Chromium and fails. Here's how to get
63-
this running on Ubuntu 18:
64-
65-
```
66-
DEBIAN_FRONTEND=noninteractive PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=TRUE \
67-
apt-get install -y chromium-chromedriver \
68-
&& npm -g install chrome-headless-render-pdf puppeteer
69-
```
70-
71-
## wkhtmltopdf
72-
73-
2. Download wkhtmltopdf and place it in your $PATH. Current binaries can be
74-
found here: http://wkhtmltopdf.org/downloads.html
75-
76-
For the impatient (Ubuntu 18.04 Bionic Beaver):
77-
78-
```
79-
apt-get -y install xfonts-base xfonts-75dpi \
80-
&& wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb \
81-
&& dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb
82-
```
83-
84-
For other distributions, refer to http://wkhtmltopdf.org/downloads.html – For
85-
example, replace `bionic` with `xenial` if you're on Ubuntu 16.04.
86-
87-
## optional dependencies
88-
89-
3. _optional:_ Install `xvfb` (shouldn't be required with the binary mentioned above):
90-
91-
To use other wkhtmltopdf executables comiled with an unpatched Qt on systems
92-
without an X window server installed, please install `xvfb-run` from your
93-
repository (on Debian/Ubuntu: `sudo apt-get install xvfb`).
94-
95-
I haven't heard any feedback of people using this feature since a while since
96-
the wkhtmltopdf projects ships ready-made binaries. I will deprecate this
97-
starting in `0.6.0` since, well, YAGNI.
98-
99-
4. _optional:_ Install `pdftk` via your package manager or homebrew. The project
100-
page also contains a Windows installer. On Debian/Ubuntu just type:
101-
`apt-get -y install pdftk`
102-
10317
# Usage
10418

10519
_Hint:_ In IEX, `h PdfGenerator.generate` is your friend.
@@ -110,18 +24,44 @@ Add this to your dependencies in your mix.exs:
11024
def application do
11125
[applications: [
11226
:logger,
113-
:pdf_generator # <-- add this
27+
:pdf_generator # <-- add this for Elixir <= 1.4
11428
]]
11529
end
11630

11731
defp deps do
11832
[
11933
# ... whatever else
120-
{ :pdf_generator, ">=0.5.5" }, # <-- and this
34+
{ :pdf_generator, ">=0.6.0" }, # <-- and this
12135
]
12236
end
12337
```
12438

39+
If you want to use a locally-installed chromium in **RELEASES** (think `mix
40+
release`), alter your mixfile to let make take care of comilation and
41+
dependency-fetching:
42+
43+
```Elixir
44+
defp deps do
45+
[
46+
# ... whatever else
47+
{ :pdf_generator, ">=0.6.0", compile: "make chrome" }
48+
]
49+
end
50+
```
51+
52+
This will embed a **300 MB** (yes, that large) Chromium binary into your priv folder
53+
which will survive packaging as Erlang release. This _can_ be handy as this will
54+
run on slim Alpine docker images with just NodeJS installed.
55+
56+
The recommended way still is to install Chromium/Puppeteer globally and set the
57+
`prefer_system_executable: true` option when generating PDFs.
58+
59+
In development: While this usually works, it unfortunately leads to
60+
pdf_generator to be compiled all the time again and again due to my bad Makefile
61+
skills. Help is very much appreciated.
62+
63+
## Try it out
64+
12565
Then pass some html to PdfGenerator.generate
12666

12767
```Elixir
@@ -167,6 +107,82 @@ filename = PdfGenerator.generate! "<html>..."
167107
pdf_binary = PdfGenerator.generate_binary! "<html>..."
168108
```
169109

110+
# System prerequisites
111+
112+
It's either
113+
114+
* wkhtmltopdf or
115+
116+
* nodejs (for chromium/puppeteer)
117+
118+
## chrome-headless
119+
120+
This will allow you to make more use of Javascript and advanced CSS as it's just
121+
your Chrome/Chromium browser rendering your web page as HTML and printing it as
122+
PDF. Rendering _tend_ to be a bit faster than with wkhtmltopdf. The price tag is
123+
that PDFs printed with chrome/chromium are usually considerably bigger than
124+
those generated with wkhtmltopdf.
125+
126+
### global install (great for Docker images)
127+
128+
Run `npm -g install chrome-headless-render-pdf puppeteer`.
129+
130+
This requires [nodejs](https://nodejs.org), of course. This will install a
131+
recent chromium and chromedriver to run Chrome in headless mode and use this
132+
browser and its API to print PDFs globally on your machine.
133+
134+
If you prefer a project-local install, just use `npm install` This will install
135+
dependencies under `./node_modules`. Be aware that those won't be packaged in
136+
your distribution (I will add support for this later).
137+
138+
On some machines, this doesn't install Chromium and fails. Here's how to get
139+
this running on Ubuntu 18:
140+
141+
```bash
142+
DEBIAN_FRONTEND=noninteractive PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=TRUE \
143+
apt-get install -y chromium-chromedriver \
144+
&& npm -g install chrome-headless-render-pdf puppeteer
145+
```
146+
147+
### local install
148+
149+
Run `make priv/node_modules`. This requires both `nodejs` (insallation see
150+
above) and `make`.
151+
152+
Or, run `cd priv && npm install`
153+
154+
## wkhtmltopdf
155+
156+
2. Download wkhtmltopdf and place it in your $PATH. Current binaries can be
157+
found here: http://wkhtmltopdf.org/downloads.html
158+
159+
For the impatient (Ubuntu 18.04 Bionic Beaver):
160+
161+
```
162+
apt-get -y install xfonts-base xfonts-75dpi \
163+
&& wget https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb \
164+
&& dpkg -i wkhtmltox_0.12.5-1.bionic_amd64.deb
165+
```
166+
167+
For other distributions, refer to http://wkhtmltopdf.org/downloads.html – For
168+
example, replace `bionic` with `xenial` if you're on Ubuntu 16.04.
169+
170+
## optional dependencies
171+
172+
3. _optional:_ Install `xvfb` (shouldn't be required with the binary mentioned above):
173+
174+
To use other wkhtmltopdf executables comiled with an unpatched Qt on systems
175+
without an X window server installed, please install `xvfb-run` from your
176+
repository (on Debian/Ubuntu: `sudo apt-get install xvfb`).
177+
178+
I haven't heard any feedback of people using this feature since a while since
179+
the wkhtmltopdf projects ships ready-made binaries. I will deprecate this
180+
starting in `0.6.0` since, well, YAGNI.
181+
182+
4. _optional:_ Install `pdftk` via your package manager or homebrew. The project
183+
page also contains a Windows installer. On Debian/Ubuntu just type:
184+
`apt-get -y install pdftk`
185+
170186
# Options and Configuration
171187

172188
This module will automatically try to finde both `wkhtmltopdf` and `pdftk` in

lib/pdf_generator.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule PdfGenerator do
22

33
require Logger
44

5-
@vsn "0.5.8"
5+
@vsn "0.6.0"
66

77
@moduledoc """
88
# PdfGenerator

mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule PdfGenerator.Mixfile do
55
[
66
app: :pdf_generator,
77
name: "PDF Generator",
8-
version: "0.5.7",
8+
version: "0.6.0",
99
elixir: ">= 1.1.0",
1010
deps: deps(),
1111
description: description(),

0 commit comments

Comments
 (0)