PDFShift.API (PDFShift v0.2.1)

Copy Markdown View Source

Module implementing the PDFShift API endpoints.

Summary

Functions

Converts a HTML document or URL to PDF.

Gets the current credits usage.

Functions

convert(client, config, source, options \\ %{})

@spec convert(
  module(),
  PDFShift.Config.t(),
  String.t(),
  PDFShift.Types.convert_options()
) ::
  {:ok, map()} | {:error, any()}

Converts a HTML document or URL to PDF.

Parameters

  • client - The HTTP client module
  • config - The configuration struct
  • source - URL or HTML content to convert to PDF
  • options - Conversion options (see PDFShift.Types.convert_options/0)

Returns

  • {:ok, response} - On successful conversion
  • {:error, reason} - On failure

Examples

iex> PDFShift.API.convert(PDFShift.Client, config, "https://example.com")
{:ok, %{body: <<PDF binary data>>, status: 200, headers: [...]}}

credits_usage(client, config)

@spec credits_usage(module(), PDFShift.Config.t()) :: {:ok, map()} | {:error, any()}

Gets the current credits usage.

Parameters

  • client - The HTTP client module
  • config - The configuration struct

Returns

  • {:ok, response} - On successful request
  • {:error, reason} - On failure

Examples

iex> PDFShift.API.credits_usage(PDFShift.Client, config)
{:ok, %{
  body: %{
    "credits" => %{
      "base" => 50000,
      "remaining" => 49881,
      "total" => 50000,
      "used" => 119
    },
    "success" => true
  },
  status: 200,
  headers: [...]
}}