PDFShift

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.1.0"}
  ]
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()

Available options

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

Development

After checking out the repo, run mix deps.get to install dependencies. Then, run mix test to run the tests.

License

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