PDFShift

Continuous IntegrationCoverage StatusHex VersionHex Docs

An Elixir client for the PDFShift API, which allows you to convert HTML to PDF.

Installation

The package can be installed by adding pdf_shift to your list of dependencies in mix.exs:

def deps do
[
{:pdf_shift, "~> 0.2.2"}
]
end

Configuration

You need a PDFShift API key to use this client. You can get one by signing up at PDFShift.

Set your API key using one of these methods:

  1. Set the PDFSHIFT_API_KEY environment variable

  2. Pass the API key in the options to each function

    PDFShift.convert("https://example.com", %{}, api_key: "your_api_key")

Usage

Converting a URL to PDF

PDFShift.convert("https://example.com")

Converting HTML content to PDF

PDFShift.convert("<html><body>Hello World</body></html>")

Converting with options

PDFShift.convert("https://example.com", %{
landscape: true,
format: "A4",
margin: %{
top: "1cm",
right: "1cm",
bottom: "1cm",
left: "1cm"
},
header: %{
source: "<div style='text-align: center;'>Header</div>",
height: "2cm"
},
footer: %{
source: "<div style='text-align: center;'>Page {{page}} of {{total}}</div>",
height: "2cm"
}
})

Check credit usage

PDFShift.credits_usage()

Available options

The following options can be passed to the convert/3 function:

Development

Setup

Run the setup script to install system dependencies and register git hooks:

bin/setup

This installs actionlint, check-jsonschema, lefthook, and mado via Homebrew, then registers the pre-commit hooks.

Then install Elixir dependencies:

mix deps.get

Commands

TaskCommand
Run testsmix test
Run a single test filemix test test/pdf_shift/client_test.exs
Run a single testmix test test/pdf_shift/client_test.exs:42
Lintmix credo
Formatmix format
Generate docsmix docs

License

The package is available as open source under the terms of the MIT License.