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.1"}
  ]
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=&#39;text-align: center;&#39;>Header</div>",
    height: "2cm"
  },
  footer: %{
    source: "<div style=&#39;text-align: center;&#39;>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 markdownlint-cli2 via Homebrew, then registers the pre-commit hooks.

Then install Elixir dependencies:

mix deps.get

Commands

Task Command
Run tests mix test
Run a single test file mix test test/pdf_shift/client_test.exs
Run a single test mix test test/pdf_shift/client_test.exs:42
Lint mix credo
Format mix format
Generate docs mix docs

License

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