PDF Generator v0.3.5 PdfGenerator
PdfGenerator
Provides a simple wrapper around wkhtmltopdf and pdftk to generate possibly encrypted PDFs from an HTML source.
Configuration (optional)
if no or partial configuration is given, PdfGenerator will search for executables on path. This will rais an error when wkhtmltopdf cannot be found.
config :pdf_generator,
wkhtml_path: "/path/to/wkhtmltopdf",
pdftk_path: "/path/to/pdftk",
In your config/config.exs. Add :pdf_generator to your mix.exs: Note that this is optional but advised to as it will perform a check on startup whether it can find a suitable wkhtmltopdf executable. It’s generally better to have an app fail at startup than at later runtime.
def application do
[applications: [ .., :pdf_generator, ..], .. ]
end
If you don’t want to autostart, issue
PdfGenerator.start wkhtml_path: “/path/to/wkhtml_path”
System requirements
- wkhtmltopdf
- pdftk (optional, for encrypted PDFs)
- goon (optional, for Porcelain shalle wrapper)
Precompiled wkhtmltopdf binaries can be obtained here: http://wkhtmltopdf.org/downloads.html
pdftk should be available as package on your system via
apt-get install pdftk
on Debian/Ubuntubrew pdftk
on OSX (you’ll need homebrew, of course)- Install the Exe-Installer on Windows found the project’s homepage (link above)
goon is available here: https://github.com/alco/goon/releases
Summary
Functions
Generates a pdf file from given html string. Returns a string containing a temporary file path for that PDF
Same as generate but returns PDF file name only (raises on error)
Takes same options as generate
but will return an
{:ok, binary_pdf_content}
tuple
Same as generate_binary but returns PDF content directly or raises on error
Callback implementation for c:Application.start/2
Functions
Generates a pdf file from given html string. Returns a string containing a temporary file path for that PDF.
options:
- page_size: output page size, defaults to “A4”
- open_password: password required to open PDF. Will apply encryption to PDF
- edit_password: password required to edit PDF
- shell_params: list of command-line arguments to wkhtmltopdf see http://wkhtmltopdf.org/usage/wkhtmltopdf.txt for all options
- delete_temporary: true to remove the temporary html generated in the system tmp dir
Examples
pdf_path_1 = PdfGenerator.generate “
Boom
” pdf_path_2 = PdfGenerator.generate( “Boom
”, page_size: “A5”, open_password: “secret”, edit_password: “g3h31m”, shell_params: [ "--outline", "--outline-depth3", "3" ], delete_temporary: true )Takes same options as generate
but will return an
{:ok, binary_pdf_content}
tuple.
In case option delete_temporary is true, will as well delete the temporary pdf file.
Same as generate_binary but returns PDF content directly or raises on error.