Convert HTML content to PDF documents with our reliable and easy-to-use API.
The PDF Generation API allows you to convert HTML content into high-quality PDF documents. This is useful for generating reports, invoices, certificates, and other documents that need to be distributed in PDF format.
Our API uses Playwright under the hood for accurate rendering, ensuring that your PDFs look exactly as intended with proper CSS styling, images, and layout.
https://wiseapis.com/api/generate-pdf
Converts HTML content to a PDF document.
Parameter | Type | Required | Description |
---|---|---|---|
api_key | string | Yes | Your API key |
api_name | string | Yes | Must be "generate-pdf" |
html | string | Yes | The HTML content to convert to PDF |
filename | string | No | Custom filename for the PDF (default: "document.pdf") |
download | string | No | Set to "true" to download the PDF directly instead of returning a URL |
include_base64 | string | No | Set to "true" to include the PDF as base64-encoded data in the response |
The API returns JSON with the following structure:
{ "success": true, "execution_time": 1.25, "file_size": 125840, "pdf_url": "https://wiseapis.com/pdfs/6123a8b7c9d0e/document.pdf", "error": null }
If base64 encoding is requested, the response includes the PDF data:
{ "success": true, "execution_time": 1.25, "file_size": 125840, "pdf_base64": "JVBERi0xLjUKJcOkw7...[truncated]", "error": null }
Status Code | Description | Example |
---|---|---|
400 | Bad Request - Missing or invalid parameters | {"success": false, "error": "HTML content is required"} |
401 | Unauthorized - Invalid API key | {"success": false, "error": "API key is required"} |
429 | Too Many Requests - Rate limit exceeded | {"success": false, "error": "Rate limit exceeded. Try again later."} |
500 | Internal Server Error | {"success": false, "error": "PDF generation failed"} |
curl -X POST https://wiseapis.com/api/API.php \ -F "api_key=your_api_key" \ -F "api_name=generate-pdf" \ -F "html=<html><body><h1>Hello World</h1><p>This is a test.</p></body></html>" \ -F "filename=my-document.pdf"
<?php $apiKey = "your_api_key"; $html = "<html><body><h1>Hello World</h1><p>This is a test.</p></body></html>"; $postData = [ 'api_key' => $apiKey, 'api_name' => 'generate-pdf', 'html' => $html, 'filename' => 'my-document.pdf', 'include_base64' => 'true' ]; $ch = curl_init('https://wiseapis.com/api/API.php'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); $response = curl_exec($ch); curl_close($ch); $result = json_decode($response, true); if ($result['success']) { // Base64 PDF data is in $result['pdf_base64'] $pdfData = base64_decode($result['pdf_base64']); file_put_contents('downloaded-document.pdf', $pdfData); echo "PDF successfully generated and saved!"; } else { echo "Error: " . $result['error']; } ?>
// Using fetch API const generatePDF = async () => { const apiKey = 'your_api_key'; const html = '<html><body><h1>Hello World</h1><p>This is a test.</p></body></html>'; const formData = new FormData(); formData.append('api_key', apiKey); formData.append('api_name', 'generate-pdf'); formData.append('html', html); formData.append('filename', 'my-document.pdf'); try { const response = await fetch('https://wiseapis.com/api/API.php', { method: 'POST', body: formData }); const result = await response.json(); if (result.success) { console.log('PDF generated successfully!'); console.log('PDF URL:', result.pdf_url); // Open the PDF in a new tab window.open(result.pdf_url, '_blank'); } else { console.error('Error:', result.error); } } catch (error) { console.error('Request failed:', error); } }; generatePDF();
import requests api_key = "your_api_key" html = "<html><body><h1>Hello World</h1><p>This is a test.</p></body></html>" payload = { 'api_key': api_key, 'api_name': 'generate-pdf', 'html': html, 'filename': 'my-document.pdf' } response = requests.post('https://wiseapis.com/api/API.php', data=payload) result = response.json() if result['success']: # Download the PDF pdf_url = result['pdf_url'] pdf_response = requests.get(pdf_url) # Save the PDF with open('downloaded-document.pdf', 'wb') as f: f.write(pdf_response.content) print("PDF successfully generated and saved!") else: print(f"Error: {result['error']}")
This API is limited to 100 requests per hour per API key. If you exceed this limit, your requests will be rejected until the limit resets.
For security reasons, only a subset of HTML tags are allowed:
PDFs generated with this API are stored temporarily and will be automatically deleted after 24 hours. If you need long-term storage, download the file or use the base64 encoding option.