View Source Api2pdf (Api2pdf v0.1.1)

Api2pdf

Unofficial API client for PDF generator/converter service https://www.api2pdf.com.

At this point only features that are related to PDF generation and conversion are supported as those are the ones that I'm currently using personally.

Contribution are welcomed to add missing features or simply open a ticket for feature requests. If you're looking for API clients in other languages please check their official repository.

Below are lists of features that are supported and those that are not, grouped by their engine:

headless-chrome

Headless Chrome

wkhtml

Wkhtml

libre-office

Libre Office

pdfsharp

PdfSharp

  • [ ] merge_pdfs
  • [ ] bookmark_pdf
  • [ ] password_pdf
  • [ ] extract_pdf
  • [ ] compress_pdf

zxing-bar-codes-generator

ZXING (Bar codes generator)

  • [ ] generate_barcode

utility-commands

Utility Commands

installation

Installation

Add api2pdf to your list of dependencies in mix.exs:

def deps do
  [
    {:api2pdf, "~> 0.1.1"}
  ]
end

api-key

API Key

Api2pdf service requires API key to be able to access their endpoints which you can get by creating an account on their membership portal site.

Once you have API key, you can pass it to this Api2pdf client in two ways.

via-application-config

Via application config

# file: config.exs

config :api2pdf,
  api_key: "YOUR-API-KEY"

via-options

Via options

All functions accept optional Keyword list where you can pass the api_key and some other configuration.

Api2pdf.Chrome.url_to_pdf("https://example.com", api_key: "YOUR-API-KEY")

engines

Engines

Api2pdf service uses multiple engines to generate PDF and doing document conversions that you can choose from. Which one to use? It's up to your preference.

You can switch between those engines by using separate modules, they are:

Link to this section Summary

Link to this section Functions

Link to this function

check_balance(options \\ [])

View Source
@spec check_balance(keyword()) ::
  {:error, any()} | {:ok, Api2pdf.Model.BalanceCheckSuccessResponse.t()}

Utility command to check your balance on https://portal.api2pdf.com.

https://app.swaggerhub.com/apis-docs/api2pdf/api2pdf/2.0.0#/Utility%20Commands/balanceCheck

examples

Examples

# api_key in config.exs
Api2pdf.check_balance()

# OR, api_key as option
Api2pdf.check_balance(api_key: "YOUR-API-KEY")
Link to this function

make_get_request(endpoint, options \\ [])

View Source
@spec make_get_request(
  String.t(),
  keyword()
) ::
  {:error, any()}
  | {:ok, Api2pdf.Model.ApiSuccessResponse.t()}
  | {:ok, Api2pdf.Model.BalanceCheckSuccessResponse.t()}
Link to this function

make_post_request(endpoint, payload, options \\ [])

View Source
@spec make_post_request(String.t(), struct(), keyword()) ::
  {:error, any()}
  | {:ok, Api2pdf.Model.ApiSuccessResponse.t()}
  | {:ok, Api2pdf.Model.BalanceCheckSuccessResponse.t()}