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:
- 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.
- Optional PDF Settings:
- Supported page sizes are
A4,A3,A5,Letter,Legal, andTabloid. - Supported orientations are
PortraitandLandscape. - Margins can be set using
margin-top,margin-bottom,margin-left, andmargin-right. - Margin values may be provided as numbers or with units such as
mm,cm, orin.
- Supported page sizes are
Response Format:
Content-Type: application/json
Example Success Response:
- 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:
- No HTML Data Provided: json
{
"error": "No HTML data to convert"
} - UUID Generation Failed: json
{
"error": "UUID generation failed"
} - Temporary HTML File Write Failed: json
{
"error": "Failed to write temporary HTML file"
} - PDF Generation Failed: json
{
"error": "PDF generation failed"
}
Input Requirements:
- Submit HTML as JSON:
- Send a POST request with request content-type: application/json.
- Use the
htmlfield for the HTML content.
{
"html": "<html><body><h1>Hello PDF</h1><p>This content will be converted to PDF.</p></body></html>"
} - Submit HTML as JSON with Options:
- Send a POST request with request content-type: application/json.
- Use the
htmlfield for HTML content and theoptionsobject 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"
}
} - Submit HTML Using the Data Field:
- Send a POST request with request content-type: application/json.
- Use the
datafield as an alternative to thehtmlfield.
{
"data": "<html><body><h1>Hello PDF</h1></body></html>"
} - 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:
- Generate PDF Documents:
- Create PDF files from HTML templates, reports, invoices, receipts, forms, or generated content.
- Temporary PDF Sharing:
- Generate a PDF and share it through a temporary storage URL.
- Automated Workflows:
- Let systems create documents automatically and retrieve the finished PDF using the returned storage URL.
- API Based Document Rendering:
- Convert HTML output from another system into a downloadable PDF file.
How to Use:
- Convert HTML to PDF:
- Send a POST request to the endpoint URL.
- Include HTML content using the
htmlfield, thedatafield, or the raw request body. - Optionally include PDF settings such as page size, orientation, and margins.
- Receive a
storage_id,storage_url, andexpire_timestampin the response.
- Retrieve Generated PDF:
- Send a GET request to the returned
storage_url. - The generated PDF file will be returned from temporary storage.
- Send a GET request to the returned