PDF Mage API for developers
API is a programmable interface used for creating PDF files from HTML markup. PDF Mage API is currently in beta version and is provided free of charge.
The interface is located at the address https://pdfmage.org/pdf-api/v1
API uses REST architecture. The parameters are sent using POST method in the request body in “key=value” format or in JSON. The format is determined on client side, by the providing the "Content-Type" header:
- For “key=value” parameters Content-Type should be: application/x-www-form-urlencoded
- For JSON parameters Content-Type should be: application/json
The system will normally respond with HTTP 200 status, sending a JSON response body which will have a "Success" parameter, and optional "Error" message and "Data":
Requests are authenticated based on the "X-Api-Key" HTTP header, which should contain your unique API key. API keys can be obtained after purchasing API access.
If the request does not have a header with authentication information, or the information sent in the request is incorrect, the system will return a HTTP 401 status – Unauthorized.
To check interaction with API you can call a test method at https://pdfmage.org/pdf-api/v1/sample without sending any parameters. The system will return a sample PDF download URL.
Generate PDF from HTML
To generate PDF from custom HTML, make a request to the following address: https://pdfmage.org/pdf-api/v1/process. These are the parameters you can use:
|Html||String||Yes||HTML markup that needs to be converted to PDF|
|TargetUrl||String||No||The URL at which HTML page is located (used to download scripts, styles, images and other files needed for HTML page to be displayed properly )|
|PageWidth||Numeric||No||HTML viewer width in pixels (default is 1024)|
Determines PDF page orientation. Possible values are:
|SinglePage||Boolean||No||Determines whether to split PDF file into pages, or use single page regardless of HTML page size|
Check your API key
To check your API key, make a request to the following address: https://pdfmage.org/pdf-api/v1/check-key without sending any parameters. You should pass your key in request headers, like for all other methods.
Our API is currently in test mode, and it is rate limited. You may only perform requests from a single IP address every 5 seconds.
If you attempt to make more frequent requests, the system will return a HTTP 409 status – Conflict.