HTML to PDF API Endpoint - Free Public API

Endpoint URL:
https://aisenseapi.com/services/v1/html2pdf


Description:

This endpoint converts HTML content into a temporary PDF file. HTML can be submitted through a JSON payload using the html field, through a JSON payload using the data field, or directly as the raw request body. Optional PDF settings can be provided to control page size, orientation, and margins. The generated PDF is stored temporarily and returned as a storage URL together with a unique storage ID and an expiration timestamp. All generated PDF files are automatically deleted after 24 hours.


Functionality:

  1. Convert HTML to PDF:
    • Send HTML content to the endpoint using JSON or a raw request body.
    • The endpoint creates a PDF file from the submitted HTML.
    • The generated PDF is stored temporarily and can be retrieved using the returned storage URL.
  2. Optional PDF Settings:
    • Supported page sizes are A4, A3, A5, Letter, Legal, and Tabloid.
    • Supported orientations are Portrait and Landscape.
    • Margins can be set using margin-top, margin-bottom, margin-left, and margin-right.
    • Margin values may be provided as numbers or with units such as mm, cm, or in.

Response Format:

Content-Type: application/json

Example Success Response:

  1. HTML Converted to PDF: json
    {
    "storage_id": "7f4c8d2a-1b6e-4c9f-9a31-82d6e5f0c123",
    "storage_url": "https://aisenseapi.com/services/v1/storage/7f4c8d2a-1b6e-4c9f-9a31-82d6e5f0c123",
    "expire_timestamp": 1760000000
    }

Example Error Responses:

  1. No HTML Data Provided: json
    {
    "error": "No HTML data to convert"
    }
  2. UUID Generation Failed: json
    {
    "error": "UUID generation failed"
    }
  3. Temporary HTML File Write Failed: json
    {
    "error": "Failed to write temporary HTML file"
    }
  4. PDF Generation Failed: json
    {
    "error": "PDF generation failed"
    }

Input Requirements:

  1. Submit HTML as JSON:
    • Send a POST request with request content-type: application/json.
    • Use the html field for the HTML content.
    {
    "html": "<html><body><h1>Hello PDF</h1><p>This content will be converted to PDF.</p></body></html>"
    }
  2. Submit HTML as JSON with Options:
    • Send a POST request with request content-type: application/json.
    • Use the html field for HTML content and the options object for PDF settings.
    {
    "html": "<html><body><h1>Invoice</h1><p>This PDF was generated from HTML.</p></body></html>",
    "options": {
    "page-size": "A4",
    "orientation": "Portrait",
    "margin-top": "10mm",
    "margin-bottom": "10mm",
    "margin-left": "10mm",
    "margin-right": "10mm"
    }
    }
  3. Submit HTML Using the Data Field:
    • Send a POST request with request content-type: application/json.
    • Use the data field as an alternative to the html field.
    {
    "data": "<html><body><h1>Hello PDF</h1></body></html>"
    }
  4. Submit HTML as Raw Body:
    • Send a POST request with request content-type: text/html or text/plain.
    • Place the HTML directly in the request body.
    <html>
    <body>
    <h1>Hello PDF</h1>
    <p>This raw HTML body will be converted to PDF.</p>
    </body>
    </html>

Use Cases:

  1. Generate PDF Documents:
    • Create PDF files from HTML templates, reports, invoices, receipts, forms, or generated content.
  2. Temporary PDF Sharing:
    • Generate a PDF and share it through a temporary storage URL.
  3. Automated Workflows:
    • Let systems create documents automatically and retrieve the finished PDF using the returned storage URL.
  4. API Based Document Rendering:
    • Convert HTML output from another system into a downloadable PDF file.

How to Use:

  1. Convert HTML to PDF:
    • Send a POST request to the endpoint URL.
    • Include HTML content using the html field, the data field, or the raw request body.
    • Optionally include PDF settings such as page size, orientation, and margins.
    • Receive a storage_id, storage_url, and expire_timestamp in the response.
  2. Retrieve Generated PDF:
    • Send a GET request to the returned storage_url.
    • The generated PDF file will be returned from temporary storage. 

Test online:

Scroll to Top