Packages

Elixir client for the DocRaptor HTML-to-PDF/XLS API.

Current section

Files

Jump to
docraptor README.md
Raw

README.md

# DocRaptor

Elixir client for the [DocRaptor](https://docraptor.com) HTML-to-PDF and XLS API.

Prefer `document_content` (with inlined CSS/assets) over `document_url` when
developing against localhost — DocRaptor cannot fetch private hosts without a
tunnel. See [Development Testing & Localhost Servers](https://docraptor.com/documentation/article/1986775-development-testing-localhost-servers).

## Installation

```elixir
def deps do
  [
    {:docraptor, "~> 0.1.0"}
  ]
end
```

## Usage

Built on [Req](https://hex.pm/packages/req). High-level helpers cover the Python
`DocApi` surface; advanced callers can attach to a `%Req.Request{}` directly.

```elixir
{:ok, client} = DocRaptor.Client.new(api_key: "YOUR_API_KEY")
# test: true by default — watermarked, free quota

{:ok, %DocRaptor.Document{body: pdf, num_pages: pages}} =
  DocRaptor.create_doc(client, %{
    name: "hello.pdf",
    document_type: :pdf,
    document_content: "<html><body>Hello</body></html>"
  })

{:ok, %DocRaptor.AsyncJob{status_id: status_id}} =
  DocRaptor.create_async_doc(client, %{
    name: "hello.pdf",
    document_type: :pdf,
    document_content: "<html><body>Hello</body></html>"
  })

{:ok, document} = DocRaptor.await_async_doc(client, status_id)
```

### Low-level Req pipeline

```elixir
Req.new(method: :post, url: "/docs", json: body, decode_body: false)
|> DocRaptor.Client.attach(client)
|> Req.request()
```

Set `test: false` on the client (or per document) for production documents.