lib/my_app/application.ex
def MyApp.Application do def start(_type, _args) do
children = [
# other apps...
ChromicPDF
]
Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)
end end
### Main API
Here's how you generate a PDF from an external URL and store it in the local filesystem.
```elixir
# Prints a local HTML file to PDF.
ChromicPDF.print_to_pdf({:url, "https://example.net"}, output: "example.pdf")
The next example shows how to print a local HTML file to PDF/A, as well as the use of a callback function that receives the generated PDF as path to a temporary file.
ChromicPDF.print_to_pdfa({:url, "file:///example.html"}, output: fn pdf ->
# Send pdf via mail, upload to S3, ...
end)
Template API
ChromicPDF.Template contains additional functionality for controlling page dimensions of your PDF.
[content: "<p>Hello Template</p>", size: :a4]
|> ChromicPDF.Template.source_and_options()
|> ChromicPDF.print_to_pdf()
Multiple sources
Multiple sources can be automatically concatenated using Ghostscript.
ChromicPDF.print_to_pdf([{:html, "page 1"}, {:html, "page 2"}], output: "joined.pdf")
Examples
- There is an outdated example of how to integrate ChromicPDF in a Phoenix application, see examples/phoenix.
Development
This should get you started:
mix deps.get
mix test
For running the full suite of integration tests, please install and have in your $PATH
:
verapdf
- For
pdfinfo
andpdftotext
, you needpoppler-utils
(most Linux distributions) or Xpdf (OSX) - For the odd ZUGFeRD test in
zugferd_test.exs
, you need to download ZUV and set the$ZUV_JAR
environment variable.