PDF from HTML Template#

Create PDF’s from HTML template input.

One you have obtained a template then use the /pdf/convert/from/html API with the required templateId & templateData parameters defined.

/templates/html#

Return all HTML templates for the current user.

Use the dashboard to manage your HTML to PDF Templates.

  • Method: GET

  • Endpoint: /v1/templates/html

Query parameters#

No query parameters accepted.

Payload#

No body parameters accepted.

Response 2#

{
    "templates": [
        {
            "id": 1,
            "type": "system",
            "title": "General Invoice Template",
            "description": "sample invoice template showcasing use of Mustache templates syntax for generating invoices"
        },
        {
            "id": 15,
            "type": "user",
            "title": "User Template 1",
            "description": ""
        }
    ],
    "remainingCredits": 99204004,
    "credits": 2
}

CURL#

curl --location --request GET 'https://api.pdf.co/v1/templates/html' \
--header 'Content-Type: application/json' \
--header 'x-api-key: '


/templates/html/:id#

Returns HTML template by template’s id.

Use the dashboard to manage your HTML to PDF Templates.

  • Method: GET

  • Endpoint: /v1/templates/html/:id

Query parameters#

No query parameters accepted.

Payload#

No body parameters accepted.

Response 2#

{
    "id": 1,
    "type": "system",
    "title": "General Invoice Template",
    "description": "sample invoice template showcasing use of Mustache templates syntax for generating invoices",
    "body": "<!doctype html>\r\n<html lang=\"en-US\">\r\n<head>\r\n<title>Invoice  </title>    \r\n<link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css\" integrity=\"sha384-zCbKRCUGaJDkqS1kPbPd7TveP5iyJE0EjAuZQTgFLD2ylzuqKfdKlfG/eSrtxUkn\" crossorigin=\"anonymous\">\r\n</head>    \r\n<body>\r\n    \r\n    <div style=\"border-width: 3px;border-style: solid; border-color: #008000;border-radius: 8px; color: #008000; opacity:0.4; position: absolute; z-index: 1; left:80%; top:3%; font-size: 60pt;transform: rotate(-20deg)\">\r\n    PAID </div>\r\n    \r\n    \r\n    <div class=\"container\">\r\n        <div class=\"\">\r\n            <div class=\"\">\r\n                \r\n                <!-- invoice: header begin-->\r\n                <div class=\"row col-md-12\">\r\n                    <div class=\"col col-md-6\">\r\n                            <div class=\"font-weight-bold\"></div>\r\n\r\n                            <div  class=\"\"></div>\r\n                            <div class=\"\"></div>\r\n                            <div class=\"\"></div>\r\n                            <div class=\"\"></div>\r\n                    </div>\r\n                    <div class=\"col col-md-6\">\r\n                        <div class=\"\">\r\n                            <div class=\"\">\r\n                                <span class=\"font-weight-bold\">Invoice Number:</span> \r\n                            </div>\r\n                            <div class=\"\">\r\n                                <span class=\"font-weight-bold\">Invoice Date:</span> \r\n                            </div>\r\n                            <div class=\"\">\r\n                                <span class=\"font-weight-bold\">Invoice Due Date:</span> \r\n                            </div>\r\n                        </div>\r\n                    </div>\r\n                </div>\r\n                \r\n<div class=\"row col-md-12\">\r\n                    <div class=\"col col-md-6\"></div>\r\n\r\n                    <div class=\"col col-md-6\">\r\n                        <div class=\"font-weight-bold footer-title\">BILL TO</div>\r\n                        <div class=\"\">\r\n                            <div class=\"\"><strong>Name:</strong> </div>\r\n                            <div class=\"\"><strong>Company:</strong> </div>\r\n                            <div class=\"\"><strong>Address:</strong> </div>\r\n                            <div  class=\"\"><strong>Email:</strong> </div>\r\n                        </div>\r\n                    </div>    \r\n                </div>\r\n                \r\n                <div class=\"row col-md-12\">\r\n                    <div class=\"col col-md-12\">\r\n                    <table class=\"table table-striped\" cellspacing=\"0\">\r\n                        <thead>\r\n                            <tr class=\"table-head\">\r\n                                <th class=\"text-left\">Item</th>\r\n                                <th class=\"text-right\">Price</th>\r\n                            </tr>\r\n                        </thead>\r\n                        <tbody>\r\n                            \r\n                            <tr>\r\n                                <td class=\"text-left\"></td>\r\n                                <td class=\"text-right\"></td>\r\n                            </tr>\r\n                            \r\n                        </tbody>\r\n                    </table>                                        \r\n                    </div>                                       \r\n\r\n                </div>\r\n                <div class=\"row col-md-12\">\r\n                  <div class=\"col col-md-6\">\r\n                  </div>\r\n                    <div class=\"col col-md-6 text-right\">\r\n                        <div style=\"margin-bottom: 10px;\">Discount:   <span class=\"amount\"></span></div>\r\n                        <div style=\"margin-bottom: 10px;\">Tax:   <span class=\"amount\"></span></div>\r\n                        <div class=\"font-weight-bold footer-title\">TOTAL: <span class=\"total-amount amount font-weight-bold\"></span></div>                        \r\n                    </div>\r\n                    \r\n                </div>\r\n                </div>                \r\n            </div>\r\n        </div>\r\n        <div class=\"container text-muted\"></div>\r\n    </div>\r\n</body>\r\n</html>\r\n​",
    "remainingCredits": 99204002,
    "credits": 2
}

CURL#

curl --location --request GET 'https://api.pdf.co/v1/templates/html/1' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ' \
--data-raw ''


Template Samples#

Footnotes

1

Supports links from Google Drive, Dropbox, and PDF.co Built-In Files Storage. To upload files via the API check out the File Upload section. Note: If you experience intermittent Too Many Requests or Access Denied errors, please try to add cache: to enable built-in URL caching. (e.g cache:https://example.com/file1.pdf) For data security, you have the option to encrypt output files and decrypt input files. Learn more about user-controlled data encryption.

2(1,2)

Main response codes as follows:

Code

Description

200

Success

400

Bad request. Typically happens because of bad input parameters, or because the input URLs can’t be reached, possibly due to access restrictions like needing a login or password.

401

Unauthorized

402

Not enough credits

445

Timeout error. To process large documents or files please use asynchronous mode (set the async parameter to true) and then check status using the /job/check endpoint. If a file contains many pages then specify a page range using the pages parameter. The number of pages of the document can be obtained using the /pdf/info endpoint.