> ## Documentation Index
> Fetch the complete documentation index at: https://developer.pdf.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Return HTML Template by ID

> Returns HTML template by template’s id.

<Note>
  **Try it live:** [Return HTML Template by ID → API Tester](/api-tester/pdf-from-html/template-id) — send a real request from your browser.
</Note>

## `GET /v1/templates/html/{id}`

Once you have obtained a template then use the [PDF from HTML](/api/pdf-from-html) API with the required `templateId` & `templateData` parameters defined.

Use the dashboard to manage your [HTML to PDF Templates](https://app.pdf.co/html-templates-tool).

## Path parameters

<ParamField path="id" type="integer" required>
  Template ID.
</ParamField>

## Responses

```json Synchronous response theme={null}
{
  "body": "<!-- this simple sample templates shows how to use macros in Mustache https://mustache.github.io/mustache.5.html and Handlebars https://handlebarsjs.com/guide/  templates. See other templates for advanced functions like auto calculation of tax, total, discount -->\n<!doctype html>\n<html lang=\"en-US\">\n<head>\n<title>Invoice {{invoice_id}} {{client_name}}</title>\n\n<script>\n// helper to format numbers\nHandlebars.registerHelper('numberFormat', numberFormat);\nfunction numberFormat(value){\n    // Helper parameters\n    var dl = 2;\n    var ts = ',';\n    var ds = '.';\n\n    // Parse to float\n    var value = parseFloat(value);\n\n    // The regex\n    var re = '\\\\d(?=(\\\\d{3})+' + (dl > 0 ? '\\\\D' : '$') + ')';\n\n    // Formats the number with the decimals\n    var num = value.toFixed(Math.max(0, ~~dl));\n\n    // Returns the formatted number\n    return (ds ? num.replace('.', ds) : num).replace(new RegExp(re, 'g'), '$&' + ts);\n}\n\n</script>\n\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\">\n<style>\n  @page {\n    size: auto;\n  }\n</style>\n</head>\n<body>\n    {{#if paid}}\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)\">\n    PAID </div>\n    {{/if}}\n\n    <div class=\"container\">\n        <div class=\"\">\n            <div class=\"\">\n\n                <!-- invoice: header begin-->\n                <div class=\"row col-md-12\">\n                    <div class=\"col col-md-6\">\n                            <div class=\"font-weight-bold\">{{issuer_name}}</div>\n\n                            <div  class=\"\">{{issuer_company}}</div>\n                            <div class=\"\">{{issuer_address}}</div>\n                            <div class=\"\">{{issuer_email}}</div>\n                            <div class=\"\">{{issuer_website}}</div>\n                    </div>\n                    <div class=\"col col-md-6\">\n                        <div class=\"\">\n                            <div class=\"\">\n                                <span class=\"font-weight-bold\">Invoice Number:</span> {{invoice_id}}\n                            </div>\n                            <div class=\"\">\n                                <span class=\"font-weight-bold\">Invoice Date:</span> {{invoice_date}}\n                            </div>\n                            <div class=\"\">\n                                <span class=\"font-weight-bold\">Invoice Due Date:</span> {{invoice_dateDue}}\n                            </div>\n                        </div>\n                    </div>\n                </div>\n\n<div class=\"row col-md-12\">\n                    <div class=\"col col-md-6\"></div>\n\n                    <div class=\"col col-md-6\">\n                        <div class=\"font-weight-bold footer-title\">BILL TO</div>\n                        <div class=\"\">\n                            <div class=\"\"><strong>Name:</strong> {{client_name}}</div>\n                            <div class=\"\"><strong>Company:</strong> {{client_company}}</div>\n                            <div class=\"\"><strong>Address:</strong> {{client_address}}</div>\n                            <div  class=\"\"><strong>Email:</strong> {{client_email}}</div>\n                        </div>\n                    </div>\n                </div>\n\n                <div class=\"row col-md-12\">\n                    <div class=\"col col-md-12\">\n                    <table class=\"table table-striped\" cellspacing=\"0\">\n                        <thead>\n                            <tr class=\"table-head\">\n                                <th class=\"text-left\">Item</th>\n                                <th class=\"text-right\">Price</th>\n                            </tr>\n                        </thead>\n                        <tbody>\n                            {{#each items}}\n                            <tr>\n                                <td class=\"text-left\">{{name}}</td>\n                                <td class=\"text-right\">$ {{numberFormat price}}</td>\n                            </tr>\n                            {{/each}}\n                        </tbody>\n                    </table>\n                    </div>\n\n                </div>\n                <div class=\"row col-md-12\">\n                  <div class=\"col col-md-6\">\n                  </div>\n                    <div class=\"col col-md-6 text-right\">\n                        <div style=\"margin-bottom: 10px;\">Discount:   <span class=\"amount\">$ {{numberFormat discount}}</span></div>\n                        <div style=\"margin-bottom: 10px;\">Tax:   <span class=\"amount\">$ {{numberFormat tax}}</span></div>\n                        <div class=\"font-weight-bold footer-title alert-warning\">TOTAL: <span class=\"total-amount amount font-weight-bold\">$ {{numberFormat total}}</span></div>\n                    </div>\n\n                </div>\n                </div>\n            </div>\n        </div>\n        <div class=\"container text-muted\">{{note}}</div>\n\n        <center>\n<img src=\"[[barcode: QRCode Invoice {{invoice_id}} {{client_name}} ]]\" />\n</center>\n\n    </div>\n</body>\n</html>",
  "credits": 2,
  "description": "simple invoice template using Mustache macros replacement. For advanced templates with auto calculations and functions please see other sample templates",
  "id": 1,
  "remainingCredits": 88468,
  "test_json": "{\r\n    \"paid\": true,\r\n    \"invoice_id\": \"0021\",\r\n    \"invoice_date\": \"August 29, 2041\",\r\n    \"invoice_dateDue\": \"September 29, 2041\",\r\n    \"issuer_name\": \"Sarah Connor\",\r\n    \"issuer_company\": \"T-800 Research Lab\",\r\n    \"issuer_address\": \"435 South La Fayette Park Place, Los Angeles, CA 90057\",\r\n    \"issuer_website\": \"www.example.com\",\r\n    \"issuer_email\": \"info@example.com\",\r\n    \"client_name\": \"Cyberdyne Systems\",\r\n    \"client_company\": \"Cyberdyne Systems\",\r\n    \"client_address\": \"18144 El Camino Real, Sunnyvale, California\",\r\n    \"client_email\": \"sales@example.com\",\r\n    \"items\": [\r\n      {\r\n        \"name\": \"T-800 Prototype Research\",\r\n        \"price\": 1000.0\r\n      },\r\n      {\r\n        \"name\": \"T-800 Cloud Sync Setup\",\r\n        \"price\": 300.0\r\n      }\r\n    ],\r\n    \"discount\": 0.1,\r\n    \"tax\": 0.0725,\r\n    \"note\": \"Thank you for your support of advanced robotics.\"\r\n}\r\n  ",
  "title": "Simple Invoice using Mustache template and qr code barcode",
  "type": "system",
  "updated_at": "2022-10-12T12:15:29.075Z"
}
```

| Field | Type | Description |
| - | - | - |
| `body` | string | Template content. |
| `credits` | integer | Number of credits consumed by the request |
| `description` | string | Template description. |
| `id` | integer | Template ID. |
| `remainingCredits` | integer | Number of credits remaining in the account |
| `test_json` | string | Template test JSON. |
| `title` | string | Template title. |
| `type` | string | Template type. |
| `updated_at` | string | Template updated at. |

<Note>
  **Inconsistent URL Encoding in cURL Output:** When using cURL to make API requests, the output JSON may show URL characters encoded as Unicode escape sequences. For example, the ampersand character (`&`) may appear as `\u0026` in the cURL output. This is normal JSON encoding behavior and does not affect the validity of the URL. The URL will function correctly when used, as JSON parsers automatically decode these escape sequences. If you're parsing the response programmatically, your JSON parser will handle this conversion automatically.
</Note>

<div id="code-samples" />

<Panel>
  **Sample request**

  <RequestExample dropdown>
    ```bash cURL theme={null}
    curl --location --request GET 'https://api.pdf.co/v1/templates/html/1' \
    --header 'Content-Type: application/json' \
    --header 'x-api-key: '
    ```

    ```php PHP theme={null}
    <?php

    // The authentication key (API Key).
    // Get your own by registering at https://app.pdf.co
    $API_KEY = "***********************************";

    // ID of the HTML template to retrieve
    $TemplateId = 1;

    getHtmlTemplate($API_KEY, $TemplateId);

    function getHtmlTemplate($apiKey, $templateId)
    {
        // Prepare URL for the `Return HTML Template by ID` API call
        $url = "https://api.pdf.co/v1/templates/html/" . rawurlencode((string) $templateId);

        // Create request
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            "x-api-key: " . $apiKey,
            "Accept: application/json"
        ));
        curl_setopt($curl, CURLOPT_HTTPGET, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

        // Execute request
        $result = curl_exec($curl);
        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        $curlError = curl_error($curl);
        curl_close($curl);

        if ($result === false) {
            // Display CURL error
            echo "getHtmlTemplate(): " . $curlError . PHP_EOL;
            return;
        }

        if ($statusCode != 200) {
            // Display request error
            echo "getHtmlTemplate(): request error " . $statusCode . PHP_EOL . $result . PHP_EOL;
            return;
        }

        $json = json_decode($result, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            echo "getHtmlTemplate(): invalid JSON response: " . json_last_error_msg() . PHP_EOL;
            return;
        }

        if (!empty($json["error"])) {
            // Display service reported error
            echo "getHtmlTemplate(): " . ($json["message"] ?? "Unknown API error") . PHP_EOL;
            return;
        }

        // Display the returned template data
        echo json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL;
    }

    ?>
    ```
  </RequestExample>

  <ResponseExample>
    ```json 200 theme={null}
    {
      "body": "<!-- this simple sample templates shows how to use macros in Mustache https://mustache.github.io/mustache.5.html and Handlebars https://handlebarsjs.com/guide/  templates. See other templates for advanced functions like auto calculation of tax, total, discount -->\n<!doctype html>\n<html lang=\"en-US\">\n<head>\n<title>Invoice {{invoice_id}} {{client_name}}</title>\n\n<script>\n// helper to format numbers\nHandlebars.registerHelper('numberFormat', numberFormat);\nfunction numberFormat(value){\n    // Helper parameters\n    var dl = 2;\n    var ts = ',';\n    var ds = '.';\n\n    // Parse to float\n    var value = parseFloat(value);\n\n    // The regex\n    var re = '\\\\d(?=(\\\\d{3})+' + (dl > 0 ? '\\\\D' : '$') + ')';\n\n    // Formats the number with the decimals\n    var num = value.toFixed(Math.max(0, ~~dl));\n\n    // Returns the formatted number\n    return (ds ? num.replace('.', ds) : num).replace(new RegExp(re, 'g'), '$&' + ts);\n}\n\n</script>\n\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\">\n<style>\n  @page {\n    size: auto;\n  }\n</style>\n</head>\n<body>\n    {{#if paid}}\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)\">\n    PAID </div>\n    {{/if}}\n\n    <div class=\"container\">\n        <div class=\"\">\n            <div class=\"\">\n\n                <!-- invoice: header begin-->\n                <div class=\"row col-md-12\">\n                    <div class=\"col col-md-6\">\n                            <div class=\"font-weight-bold\">{{issuer_name}}</div>\n\n                            <div  class=\"\">{{issuer_company}}</div>\n                            <div class=\"\">{{issuer_address}}</div>\n                            <div class=\"\">{{issuer_email}}</div>\n                            <div class=\"\">{{issuer_website}}</div>\n                    </div>\n                    <div class=\"col col-md-6\">\n                        <div class=\"\">\n                            <div class=\"\">\n                                <span class=\"font-weight-bold\">Invoice Number:</span> {{invoice_id}}\n                            </div>\n                            <div class=\"\">\n                                <span class=\"font-weight-bold\">Invoice Date:</span> {{invoice_date}}\n                            </div>\n                            <div class=\"\">\n                                <span class=\"font-weight-bold\">Invoice Due Date:</span> {{invoice_dateDue}}\n                            </div>\n                        </div>\n                    </div>\n                </div>\n\n<div class=\"row col-md-12\">\n                    <div class=\"col col-md-6\"></div>\n\n                    <div class=\"col col-md-6\">\n                        <div class=\"font-weight-bold footer-title\">BILL TO</div>\n                        <div class=\"\">\n                            <div class=\"\"><strong>Name:</strong> {{client_name}}</div>\n                            <div class=\"\"><strong>Company:</strong> {{client_company}}</div>\n                            <div class=\"\"><strong>Address:</strong> {{client_address}}</div>\n                            <div  class=\"\"><strong>Email:</strong> {{client_email}}</div>\n                        </div>\n                    </div>\n                </div>\n\n                <div class=\"row col-md-12\">\n                    <div class=\"col col-md-12\">\n                    <table class=\"table table-striped\" cellspacing=\"0\">\n                        <thead>\n                            <tr class=\"table-head\">\n                                <th class=\"text-left\">Item</th>\n                                <th class=\"text-right\">Price</th>\n                            </tr>\n                        </thead>\n                        <tbody>\n                            {{#each items}}\n                            <tr>\n                                <td class=\"text-left\">{{name}}</td>\n                                <td class=\"text-right\">$ {{numberFormat price}}</td>\n                            </tr>\n                            {{/each}}\n                        </tbody>\n                    </table>\n                    </div>\n\n                </div>\n                <div class=\"row col-md-12\">\n                  <div class=\"col col-md-6\">\n                  </div>\n                    <div class=\"col col-md-6 text-right\">\n                        <div style=\"margin-bottom: 10px;\">Discount:   <span class=\"amount\">$ {{numberFormat discount}}</span></div>\n                        <div style=\"margin-bottom: 10px;\">Tax:   <span class=\"amount\">$ {{numberFormat tax}}</span></div>\n                        <div class=\"font-weight-bold footer-title alert-warning\">TOTAL: <span class=\"total-amount amount font-weight-bold\">$ {{numberFormat total}}</span></div>\n                    </div>\n\n                </div>\n                </div>\n            </div>\n        </div>\n        <div class=\"container text-muted\">{{note}}</div>\n\n        <center>\n<img src=\"[[barcode: QRCode Invoice {{invoice_id}} {{client_name}} ]]\" />\n</center>\n\n    </div>\n</body>\n</html>",
      "credits": 2,
      "description": "simple invoice template using Mustache macros replacement. For advanced templates with auto calculations and functions please see other sample templates",
      "id": 1,
      "remainingCredits": 88468,
      "test_json": "{\r\n    \"paid\": true,\r\n    \"invoice_id\": \"0021\",\r\n    \"invoice_date\": \"August 29, 2041\",\r\n    \"invoice_dateDue\": \"September 29, 2041\",\r\n    \"issuer_name\": \"Sarah Connor\",\r\n    \"issuer_company\": \"T-800 Research Lab\",\r\n    \"issuer_address\": \"435 South La Fayette Park Place, Los Angeles, CA 90057\",\r\n    \"issuer_website\": \"www.example.com\",\r\n    \"issuer_email\": \"info@example.com\",\r\n    \"client_name\": \"Cyberdyne Systems\",\r\n    \"client_company\": \"Cyberdyne Systems\",\r\n    \"client_address\": \"18144 El Camino Real, Sunnyvale, California\",\r\n    \"client_email\": \"sales@example.com\",\r\n    \"items\": [\r\n      {\r\n        \"name\": \"T-800 Prototype Research\",\r\n        \"price\": 1000.0\r\n      },\r\n      {\r\n        \"name\": \"T-800 Cloud Sync Setup\",\r\n        \"price\": 300.0\r\n      }\r\n    ],\r\n    \"discount\": 0.1,\r\n    \"tax\": 0.0725,\r\n    \"note\": \"Thank you for your support of advanced robotics.\"\r\n}\r\n  ",
      "title": "Simple Invoice using Mustache template and qr code barcode",
      "type": "system",
      "updated_at": "2022-10-12T12:15:29.075Z"
    }
    ```

    ```json 400 theme={null}
    {
      "error": true,
      "status": 400,
      "message": "Bad request. Typically due to bad input parameters or unreachable input URLs (e.g., access restrictions like login or password)."
    }
    ```

    ```json 401 theme={null}
    {
      "error": true,
      "status": 401,
      "message": "Unauthorized. Authentication is required and has failed or has not yet been provided."
    }
    ```

    ```json 402 theme={null}
    {
      "error": true,
      "status": 402,
      "message": "Not enough credits."
    }
    ```

    ```json 404 theme={null}
    {
      "error": true,
      "status": 404,
      "message": "The requested resource could not be found."
    }
    ```

    ```json 429 theme={null}
    {
      "error": true,
      "status": 429,
      "message": "Too many requests in a given time period."
    }
    ```

    ```json 500 theme={null}
    {
      "error": true,
      "status": 500,
      "message": "Something went wrong. Please try again or contact support."
    }
    ```
  </ResponseExample>
</Panel>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.