PDFinch.com API Documentation
Authentication
To use our API, you need an account with enough credit on it and a set of API keys, see your Dashboard under Developers -> API Keys.
Then you authenticate using those API keys, using an OAuth2 form-encoded client credentials POST request to /oauth2/token
:
curl --request POST \ --url https://api.pdfinch.com/oauth2/token \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data grant_type=client_credentials \ --data client_id=$PDFinch_API_ID \ --data client_secret=$PDFinch_API_Secret
This will result in a JSON Web Token (JWT):
{ "access_token": "eyJ...eA", "token_type": "bearer", "expires_in": 5999}
When possible, cache the access_token
value containing the JWT for reuse during its validity period. When it expires (or the token is otherwise invalid), you'll get a 401 response on your requests.
Usage of the JWT
Now for successive requests, you issue that access_token
as a bearer authentication header:
curl --request POST \ --url https://api.pdfinch.com/pdf/create \ --header 'Authorization: Bearer $PDfinch_API_Token' \ --header 'Content-Type: text/plain' \ --data '<h1>Your Title</h1>Hello, I am HTML.'
APIs
Currently, there are two APIs:
POST https://api.pdfinch.com/pdf/create
You can POST HTML here, the content type is ignored, UTF-8 is assumed. You'll get an application/octet-stream back which you can treat as a PDF file.
Possible query string parameters:
Name | Type | Values |
---|---|---|
MarginLeft | int | 0-999 |
MarginRight | int | 0-999 |
MarginTop | int | 0-999 |
MarginBottom | int | 0-999 |
Landscape | bool | true/false |
Parameters are case-insensitive.
POST https://api.pdfinch.com/pdf/merge
Send multiple HTML and parameter definitions, to append multiple pages. You can post with the content-type "multipart/form-data". The form element format is:
Name | Type | Values |
---|---|---|
d[n].Body | string | HTML |
d[n].MarginLeft | int | 0-999 |
d[n].MarginRight | int | 0-999 |
d[n].MarginTop | int | 0-999 |
d[n].MarginBottom | int | 0-999 |
d[n].Landscape | bool | true/false |
Where n
is the 0-based index of your data. So if you want to post three HTML definitions, you can post something like this:
--X-YOUR-BOUNDARY
Content-Disposition: form-data; name="d[0].body"
<h1>Your-Html-String</h1>
--X-YOUR-BOUNDARY
Content-Disposition: form-data; name="d[0].landscape"
true
--X-YOUR-BOUNDARY
Content-Disposition: form-data; name="d[1].body"
<h1>Your-Second-Html</h1>
--X-YOUR-BOUNDARY
Content-Disposition: form-data; name="d[2].body"
<h1>Your-Third-Html</h1>
--X-YOUR-BOUNDARY
Content-Disposition: form-data; name="d[2].landscape"
true