defmodule PdfGenerator do @vsn "0.3.0" @moduledoc """ # PdfGenerator Provides a simple wrapper around [wkhtmltopdf](http://wkhtmltopdf.org) and [pdftk](https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/) 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/Ubuntu - `brew 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 """ use Application alias Porcelain.Result # See http://elixir-lang.org/docs/stable/elixir/Application.html # for more information on OTP Applications def start(_type, _args) do import Supervisor.Spec, warn: false children = [ # Define workers and child supervisors to be supervised # worker(TestApp.Worker, [arg1, arg2, arg3]) worker( PdfGenerator.PathAgent, [[ wkhtml_path: Application.get_env(:pdf_generator, :wkhtml_path ), pdftk_path: Application.get_env(:pdf_generator, :pdftk_path ), ]] ) ] opts = [strategy: :one_for_one, name: PdfGenerator.Supervisor] Supervisor.start_link(children, opts) end # return file name of generated pdf # requires: Porcelain, Misc.Random @doc """ 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 # Examples pdf_path_1 = PdfGenerator.generate "