├── Readme.md
├── html2pdf.sh
├── revealjs.pdf
└── src
└── index.html
/Readme.md:
--------------------------------------------------------------------------------
1 | # HTML PDF Builder
2 |
3 | A small shell script that uses `wkhtmltopdf` to build PDF documents from HTML5 documents. Especially suited for creating PDF presentations as a 1 to 1 copy of your HTML presentations. Obviously also useful for PDF screenshots of websites. It's better than a normal screenshot though, because the PDF contains all text and images as separate elements, which can be manipulated individually.
4 |
5 | Presentation export is tested with reveal.js. You may want to use the reveal.js config to do customize the size of the presentation to fit the size of your example. The example pdf file (revealjs.pdf) was created using `./html2pdf.sh http://lab.hakim.se/reveal-js\?print-pdf revealjs.pdf 1280 768`.
6 |
7 | ## Usage
8 |
9 | Currently mainly useful for playing around.
10 |
11 | The program requires `wkhtmltopdf` to be available. Please check [http://wkhtmltopdf.org/](http://wkhtmltopdf.org/) for details.
12 |
13 | In order to create a PDF at `OUTPUT_LOCATION` from a `SRC_LOCATION` at a resolution of `WIDTH` x `HEIGHT` per page, you just need to call
14 |
15 | `./html2pdf.sh SRC_LOCATION OUTPUT_LOCATION WIDTH HEIGHT`
16 |
17 | You can also leave out the dimensions and Full HD (1920x1080) resolution will be chosen.
18 |
19 | `./html2pdf.sh SRC_LOCATION OUTPUT_LOCATION`
20 |
21 | Note that due to the behaviour of `wkhtmltopdf`, the `SRC_LOCATION` can be the **full** file path or a URL.
22 |
23 | You're welcome to fork your own version or provide additions & leave comments. You can also e-mail me at [me@gfm.io](mailto:me@gfm.io).
24 |
25 | LICENSE: MIT
26 |
27 | Copyright (C) 2015 Frédérique Mittelstaedt, gfm.io, me@gfm.io
28 |
--------------------------------------------------------------------------------
/html2pdf.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # HTML2PDF
4 |
5 | # Parameters and defaults
6 |
7 | srcFile=$1
8 | if [[ $srcFile == "" ]]; then
9 | echo "Source file or URL not provided."
10 | exit
11 | fi
12 |
13 | outFile=$2
14 | if [[ $outFile == "" ]]; then
15 | echo "Output file not provided."
16 | exit
17 | fi
18 |
19 | width=$3
20 | if [[ $width == "" ]]; then
21 | width=1920
22 | fi
23 |
24 | height=$4
25 | if [[ $height == "" ]]; then
26 | height=1080
27 | fi
28 |
29 | # Constants for internal use, based on working config on Mac OS X Yosemite. Might be different for your system.
30 |
31 | # Scaling factor required to get the right PDF size for width and height set above
32 | scalingFactor="100 / 6"
33 | # Zoom factor for the webkit engine to render the document as desired.
34 | zoomFactor=1.25
35 |
36 | # Testing prerequisites
37 |
38 | # Testing for wkhtmltopdf
39 | wkhtmltopdfFound=`which wkhtmltopdf`
40 | if [[ wkhtmltopdfFound == "wkhtmltopdf not found" ]]; then
41 | echo "wkhtmltopdf is not installed"
42 | exit
43 | fi
44 |
45 | # Script execution
46 |
47 | # Remove existing output file
48 | if [ -f $outFile ]; then
49 | rm $outFile
50 | fi
51 |
52 | w=$(( $width * $scalingFactor ))
53 | h=$(( $height * $scalingFactor ))
54 |
55 | wkhtmltopdf --use-xserver --page-width "$w"px --page-height "$h"px -B 0 -L 0 -R 0 -T 0 --zoom $zoomFactor $srcFile $outFile
56 |
57 | exit
58 |
--------------------------------------------------------------------------------
/revealjs.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gfmio/html2pdf/35a496d6b36d41b8b28f4246f3a05634f5e5c39e/revealjs.pdf
--------------------------------------------------------------------------------
/src/index.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gfmio/html2pdf/35a496d6b36d41b8b28f4246f3a05634f5e5c39e/src/index.html
--------------------------------------------------------------------------------