Skip to content

Introduction

Gaurav Kulkarni edited this page Mar 24, 2016 · 4 revisions

What is pdfhook?

PDFHook is a library that turns interactive PDFs into APIs. To try it out right now you can use our current deployment of this located at https://pdfhook.herokuapp.com/. You can visit that page to try it out. To programmatically hook into pdfhook, you can make HTTP requests to interface with pdfhook.

Making an interactive PDF

Before you start, you must turn your PDF into an interactive PDF. Instructions can be found here.

Curl

To get the fields of a PDF: (NOTE: data/sample_pdfs/sample_form.pdf is part of the repository. Replace that path with your PDF if you want to use a different one)

curl -H "Accept: application/json" -X POST https://pdfhook.herokuapp.com -F file=@data/sample_pdfs/sample_form.pdf

returns something like

{
  "added_on": "2016-03-24T03:31:28.634346+00:00",
  "fields": [
    {
      "name": "Address 1 Text Box",
      "type": "text",
      "value": ""
    },
    {
      "name": "Address 2 Text Box",
      "type": "text",
      "value": ""
    },
    ....
    {
      "name": "Language 5 Check Box",
      "options": [
        "Off",
        "Yes"
      ],
      "type": "button",
      "value": "Off"
    },
    {
      "name": "Postcode Text Box",
      "type": "text",
      "value": ""
    }
  ],
  "id": 15,
  "latest_post": null,
  "original_pdf_title": "sample_form.pdf",
  "post_count": 0,
  "url": "https://pdfhook.herokuapp.com/15/"
}

Then you can fill out this pdf by doing something like this. (NOTE: the URL https://pdfhook.herokuapp.com/15/ comes from the url field in the previous response. Replace it with the response you got when running the first command).

curl -H "Content-Type: application/json" -X POST --data '{"Address 1 Text Box":"test"}' https://pdfhook.herokuapp.com/15/ > test.pdf

Which will save the filled out PDF in test.pdf. You can view it with the following.

open test.pdf
Clone this wiki locally