Up & Running with PDFMonkey

Create a PDFMonkey account

To create an account, go to the Register page and fill in you email and password.

We do not ask for a password confirmation but you can toggle password hiding by clicking on Show my password.

Once you’ve filled in your credentials, we will send you an activation email. Click the link in the email to activate your account. You will not be able to sign in until your account is confirmed.

Sign in

Once your account confirmed, fill in your credentials in the Sign in page to get access to your dashboard.

Create your first app

In your dashboard you can create apps that will regroup your templates and documents.

To create an app, click on Add an application and give a name to your app. Then click on Add.

You can change the name of your apps as often as you want, it will have no impact on your client applications.

Create your first template

To create a template, click on the name of the application you want to use then click on Add a template and give a name to your tempalte. Then click on Add.

You can change the name of your templates as often as you want, it will have no impact on your client applications.

You can then start editing your template by clicking on its name.

A template is composed of four things:

  1. An HTML body to structure your PDF’s content. PDFMonkey uses the Liquid Syntax for its templates.
  2. A (S)CSS file to style your PDF and bring it to life.
  3. A JSON payload to provide sample data to the Liquid template. Use it to test your template and provide an usage example later on.
  4. A list of settings to customize the generated PDF (orientation, margins, etc).

When you change a template, you can then save a draft and preview the new version by clicking on Save & Refresh. Once you’re happy with the result you can publish your draft by clicking on Publish.

In case you want to discard your modifications and rollback to the last published version by clicking on the Discard changes button.

Create a document using the UI

Once you’ve created and published a template, you can now create a document.

Head to the Documents page and click on Add a document.

You can then choose the template you want to use and start filling in the data to use in the template. You can switch to the Sample data tab to see the test data used when building the template and compare with your real data.

The preview will keep updating everytime you change your data so that you can see how your document will look like.

The preview is a real PDF, you will be able to see exactly how your document will look like once generated!

Once you’re happy with what you’re seeing, click on the Generate it button to create your document. Once the document is generated, the page will show a Download button you can click to get your PDF.

That’s it!

Create a document using the API

1. Get your API KEY

In order to generate a PDF through the API, you’ll need to grab your API KEY first.

Head to the My account page using the top-right menu.

Toggle your API KEY by clicking on the Display value link below the API SECRET KEY field. You can now copy you key.

2. Get your template ID

Every template has a unique ID that you can get from the Templates page.

Copy your template’s id. You’re now ready to generate a document!

3. Generate a document

Here is a sample cURL command you can use to generate a document:

curl 'https://api.pdfmonkey.io/api/v1/documents' \
  -H 'Authorization: Token auth_token="[API KEY]", email="[YOUR EMAIL]"' \
  -H 'Content-Type: application/json' \
  -d '{ \
        "document": { \
          "document_template_id": "[TEMPLATE ID]", \
          "payload": "{\"name\":\"toto\"}", \
          "status": "pending" \
        } \
      }'
Be careful to replace [API KEY], [YOUR EMAIL] and [TEMPLATE ID] with the corresponding information.
The status parameter will indicate to PDFMonkey to generate your document upon creation. Don’t forget it!

You’ll get back your document’s payload containing its ID like this:

{
  "document" : {
      …
      "id" : "d2f2de44-9de7-4dd8-90f4-bee5e99c9984",
      "status": "generating"
      …
  }
}

To check if your document is done generating, call the API again to get your document payload:

curl 'https://api-staging.pdfmonkey.io/api/v1/documents/[DOCUMENT ID]' \
  -H 'Authorization: Token auth_token="[API KEY]", email="[YOUR EMAIL]"'

You will get the same payload again. Retry until its status changes to success.

When your document is generated, its payload will include a download_url. This URL will be valid for 30 seconds, afterward you’ll need to call the API again to get a new one.

Visit the download_url to get your document. That's it!

Webhooks

You can configure webhooks for your application. To do so, go to the Edit app page and set a Webhook URL then click on the Save button.

Everytime a Document is generated for this app, your webhook will be called using a POST request with a Content-Type: application/json header and your Document details as body:

{
  "document": {
    "id": "4204eff8-3126-4ec7-a5f9-aa8ed5b8517b",
    "status": "success",
    "app_id": "d9ec8249-65ae-4d50-8aee-7c12c1f9683a",
    "document_template_id": "b13ebd75-d290-409b-9cac-8f597ae3e785",
    "payload": "{\"name\":\"John Doe\"}",
    "checksum": "6dc8942e10f93b1e22d4b18bdf04e2f3",
    "download_url": "https://….pdf",
    "preview_url": null,
    "meta": null,
    "created_at": "2018-12-04T20:28:35.072+01:00",
    "updated_at": "2018-12-04T20:28:38.899+01:00"
  }
}
Warning: PDFMonkey will expect a 200 OK response from your webhook URL with an empty body.