> For the complete documentation index, see [llms.txt](https://docs.htmlcsstoimg.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.htmlcsstoimg.com/api-reference/pdf-munk-api-reference.md).

# PDF Munk API Reference

## Generate PDF from HTML or URL

> Creates a PDF from either HTML content or a URL. Supports custom page sizes, \
> fonts, viewport dimensions, and dynamic parameters.\
> \
> \*\*Note:\*\* Either \`url\` or \`html\_content\` must be provided, but not both.<br>

```json
{"openapi":"3.0.3","info":{"title":"PDFMunk API","version":"1.0.0"},"tags":[{"name":"PDF Generation","description":"Generate PDFs from HTML or URLs"}],"servers":[{"url":"https://pdfmunk.com/api","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"CLIENT-API-KEY","description":"API key for authentication. Get your key from https://pdfmunk.com/dashboard"}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"Error message"},"success":{"type":"boolean"},"details":{"type":"string","description":"Additional error details (optional)"}},"required":["error","success"]}}},"paths":{"/v1/generatePdf":{"post":{"tags":["PDF Generation"],"summary":"Generate PDF from HTML or URL","description":"Creates a PDF from either HTML content or a URL. Supports custom page sizes, \nfonts, viewport dimensions, and dynamic parameters.\n\n**Note:** Either `url` or `html_content` must be provided, but not both.\n","operationId":"generatePdf","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["html_content"],"properties":{"url":{"type":"string","format":"uri","description":"URL of the webpage to convert to PDF"},"html_content":{"type":"string","description":"HTML content to convert to PDF"},"css_content":{"type":"string","description":"Optional CSS to apply to the HTML"},"output_format":{"type":"string","enum":["url","pdf","binary","file"],"default":"url","description":"Output format:\n- `url`: Returns a URL to the uploaded PDF (default)\n- `pdf`, `binary`, `file`: Returns the PDF file directly\n"},"paper_size":{"type":"string","enum":["A4","A3","A5","Letter","Legal","Tabloid"],"default":"A4","description":"Paper size for the PDF"},"landscape":{"type":"boolean","default":false,"description":"Set to true for landscape orientation"},"printBackground":{"type":"boolean","default":true,"description":"Whether to print background graphics"},"displayHeaderFooter":{"type":"boolean","default":false,"description":"Whether to display header and footer"},"preferCSSPageSize":{"type":"boolean","default":true,"description":"Whether to prefer CSS-defined page size"},"page_size":{"type":"integer","minimum":1,"maximum":20,"description":"Maximum number of pages to generate (tier-dependent)"},"paperWidth":{"type":"number","description":"Custom paper width in pixels"},"paperHeight":{"type":"number","description":"Custom paper height in pixels"},"viewPortWidth":{"type":"integer","default":1080,"description":"Viewport width for rendering"},"viewPortHeight":{"type":"integer","default":720,"description":"Viewport height for rendering"},"font":{"type":"string","description":"Google Font name(s) to include (use | separator for multiple)"},"wait_till":{"type":"integer","default":0,"description":"Time to wait in seconds before generating PDF"},"dynamic_params":{"type":"object","description":"Dynamic parameters to replace in HTML (e.g., {{name}} becomes value)","additionalProperties":true}}}}}},"responses":{"200":{"description":"PDF generated successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"pdf_url":{"type":"string","format":"uri","description":"URL to download the PDF (when output_format is 'url')"},"file_size_bytes":{"type":"integer"},"file_deletion_date":{"type":"string","format":"date","description":"Date when the file will be deleted (30 days)"},"source_type":{"type":"string","enum":["url","html"]}}}},"application/pdf":{"schema":{"type":"string","format":"binary","description":"PDF file (when output_format is 'pdf', 'binary', or 'file')"}}}},"400":{"description":"Bad request - validation error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Unauthorized - invalid or missing API key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Generate image from HTML or URL

> Creates a PNG image from either HTML content or a URL. Supports custom dimensions,\
> quality settings, fonts, and dynamic parameters.\
> \
> \*\*Note:\*\* Either \`url\` or \`html\_content\` must be provided, but not both.<br>

```json
{"openapi":"3.0.3","info":{"title":"PDFMunk API","version":"1.0.0"},"tags":[{"name":"Image Generation","description":"Generate images from HTML or URLs"}],"servers":[{"url":"https://pdfmunk.com/api","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"CLIENT-API-KEY","description":"API key for authentication. Get your key from https://pdfmunk.com/dashboard"}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"Error message"},"success":{"type":"boolean"},"details":{"type":"string","description":"Additional error details (optional)"}},"required":["error","success"]}}},"paths":{"/v1/generateImage":{"post":{"tags":["Image Generation"],"summary":"Generate image from HTML or URL","description":"Creates a PNG image from either HTML content or a URL. Supports custom dimensions,\nquality settings, fonts, and dynamic parameters.\n\n**Note:** Either `url` or `html_content` must be provided, but not both.\n","operationId":"generateImage","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","format":"uri","description":"URL of the webpage to capture as image"},"html_content":{"type":"string","description":"HTML content to render as image"},"css_content":{"type":"string","description":"Optional CSS to apply to the HTML"},"output_format":{"type":"string","enum":["url","base64","both","image","png","binary","file"],"default":"url","description":"Output format:\n- `url`: Returns a URL to the uploaded image (default)\n- `base64`: Returns base64-encoded image string\n- `both`: Returns both URL and base64\n- `image`, `png`, `binary`, `file`: Returns the image file directly\n"},"width":{"type":"integer","default":1280,"description":"Width of the output image in pixels"},"height":{"type":"integer","default":720,"description":"Height of the output image in pixels"},"viewPortWidth":{"type":"integer","description":"Viewport width for rendering (if different from output width)"},"viewPortHeight":{"type":"integer","description":"Viewport height for rendering (if different from output height)"},"device_scale_factor":{"type":"number","default":1,"minimum":1,"maximum":3,"description":"Device scale factor for higher resolution"},"quality":{"type":"integer","minimum":30,"maximum":100,"default":80,"description":"Image quality (30-100)"},"full_page":{"type":"boolean","default":false,"description":"Capture full page (for URLs only)"},"wait_till":{"type":"integer","default":0,"description":"Time to wait in seconds before capturing"},"wait_until":{"type":"string","enum":["load","domcontentloaded","networkidle"],"default":"load","description":"When to consider navigation successful (for URLs)"},"font":{"type":"string","description":"Google Font name(s) to include (use | separator for multiple)"},"dynamic_params":{"type":"object","description":"Dynamic parameters to replace in HTML","additionalProperties":true}}}}}},"responses":{"200":{"description":"Image generated successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"image_url":{"type":"string","format":"uri","description":"URL to download the image (when output_format is 'url' or 'both')"},"image_base64":{"type":"string","description":"Base64-encoded image (when output_format is 'base64' or 'both')"},"file_size_bytes":{"type":"integer"},"file_deletion_date":{"type":"string","format":"date"},"request_id":{"type":"string","format":"uuid"},"execution_time_ms":{"type":"integer","description":"Time taken to generate the image in milliseconds"}}}},"image/png":{"schema":{"type":"string","format":"binary","description":"PNG file (when output_format is 'image', 'png', 'binary', or 'file')"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limit exceeded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal server error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Generate chart image using Chart.js

> Creates a chart image using Chart.js library. Supports various chart types\
> including line, bar, pie, doughnut, radar, and more.<br>

```json
{"openapi":"3.0.3","info":{"title":"PDFMunk API","version":"1.0.0"},"tags":[{"name":"Chart Generation","description":"Generate chart images using Chart.js"}],"servers":[{"url":"https://pdfmunk.com/api","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"CLIENT-API-KEY","description":"API key for authentication. Get your key from https://pdfmunk.com/dashboard"}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"Error message"},"success":{"type":"boolean"},"details":{"type":"string","description":"Additional error details (optional)"}},"required":["error","success"]}}},"paths":{"/v1/generateChart":{"post":{"tags":["Chart Generation"],"summary":"Generate chart image using Chart.js","description":"Creates a chart image using Chart.js library. Supports various chart types\nincluding line, bar, pie, doughnut, radar, and more.\n","operationId":"generateChart","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["chart_type","data"],"properties":{"chart_type":{"type":"string","enum":["line","bar","pie","doughnut","radar","polarArea","bubble","scatter"],"description":"Type of chart to generate"},"data":{"type":"object","description":"Chart.js data configuration","properties":{"labels":{"type":"array","items":{"type":"string"},"description":"Labels for the chart (required for line, bar, radar)"},"datasets":{"type":"array","description":"Array of datasets","items":{"type":"object","properties":{"label":{"type":"string"},"data":{"type":"array","items":{"type":"number"}},"backgroundColor":{"oneOf":[{"type":"string"},{"type":"array","items":{"type":"string"}}]},"borderColor":{"type":"string"},"borderWidth":{"type":"integer"}}}}}},"options":{"type":"object","description":"Chart.js options configuration","additionalProperties":true},"width":{"type":"integer","default":800,"description":"Width of the chart in pixels"},"height":{"type":"integer","default":600,"description":"Height of the chart in pixels"},"output_format":{"type":"string","enum":["url","base64","both","image"],"default":"url","description":"Output format for the chart image"}}}}}},"responses":{"200":{"description":"Chart generated successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"chart_url":{"type":"string","format":"uri","description":"URL to the chart image (when output_format is 'url' or 'both')"},"chart_base64":{"type":"string","description":"Base64-encoded chart (when output_format is 'base64' or 'both')"},"file_size_bytes":{"type":"integer"},"file_deletion_date":{"type":"string","format":"date"},"request_id":{"type":"string","format":"uuid"},"execution_time_ms":{"type":"integer"}}}},"image/png":{"schema":{"type":"string","format":"binary"}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Compress an image

> Compresses an image from a URL or base64 string with adjustable quality settings.\
> Maximum file size: 3MB.<br>

```json
{"openapi":"3.0.3","info":{"title":"PDFMunk API","version":"1.0.0"},"tags":[{"name":"Image Compression","description":"Compress images with quality control"}],"servers":[{"url":"https://pdfmunk.com/api","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"CLIENT-API-KEY","description":"API key for authentication. Get your key from https://pdfmunk.com/dashboard"}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"Error message"},"success":{"type":"boolean"},"details":{"type":"string","description":"Additional error details (optional)"}},"required":["error","success"]}}},"paths":{"/v1/compress":{"post":{"tags":["Image Compression"],"summary":"Compress an image","description":"Compresses an image from a URL or base64 string with adjustable quality settings.\nMaximum file size: 3MB.\n","operationId":"compressImage","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"image_url":{"type":"string","format":"uri","description":"URL of the image to compress"},"base64_image":{"type":"string","description":"Base64-encoded image (alternative to image_url)"},"output_format":{"type":"string","enum":["url","base64"],"default":"url","description":"Format of the compressed image output"},"quality":{"type":"integer","minimum":1,"maximum":100,"default":85,"description":"Compression quality (1-100, higher = better quality)"}}}}}},"responses":{"200":{"description":"Image compressed successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"compressed_image_url":{"type":"string","format":"uri","description":"URL to compressed image (when output_format is 'url')"},"compressed_base64_image":{"type":"string","description":"Base64-encoded compressed image (when output_format is 'base64')"},"original_size_bytes":{"type":"integer"},"compressed_size_bytes":{"type":"integer"},"compressed_size_kb":{"type":"number","format":"float"},"compression_percentage":{"type":"number","format":"float","description":"Percentage of size reduction"},"file_deletion_date":{"type":"string","format":"date"}}}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Merge multiple PDFs

> Merges multiple PDF files from URLs into a single PDF document.\
> \
> \*\*Limits:\*\*\
> \- Maximum 15 input PDFs\
> \- Maximum 200 pages per PDF\
> \- Maximum 500 total pages combined<br>

```json
{"openapi":"3.0.3","info":{"title":"PDFMunk API","version":"1.0.0"},"tags":[{"name":"PDF Tools","description":"Merge and split PDF documents"}],"servers":[{"url":"https://pdfmunk.com/api","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"CLIENT-API-KEY","description":"API key for authentication. Get your key from https://pdfmunk.com/dashboard"}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"Error message"},"success":{"type":"boolean"},"details":{"type":"string","description":"Additional error details (optional)"}},"required":["error","success"]}}},"paths":{"/v1/pdf/merge":{"post":{"tags":["PDF Tools"],"summary":"Merge multiple PDFs","description":"Merges multiple PDF files from URLs into a single PDF document.\n\n**Limits:**\n- Maximum 15 input PDFs\n- Maximum 200 pages per PDF\n- Maximum 500 total pages combined\n","operationId":"mergePdfs","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["urls"],"properties":{"urls":{"type":"array","minItems":2,"maxItems":15,"items":{"type":"string","format":"uri"},"description":"Array of PDF URLs to merge"}}}}}},"responses":{"200":{"description":"PDFs merged successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"merged_pdf_url":{"type":"string","format":"uri"},"total_pages":{"type":"integer","description":"Total number of pages in merged PDF"},"input_count":{"type":"integer","description":"Number of input PDFs merged"},"file_deletion_date":{"type":"string","format":"date"}}}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Split or extract pages from a PDF

> Splits a PDF or extracts specific pages based on page ranges.\
> \
> \*\*Page Range Format:\*\*\
> \- Single page: \`"3"\`\
> \- Range: \`"1-5"\`\
> \- Multiple ranges: \`"1-3,5,7-10"\`\
> \- Open-ended: \`"10-"\` (from page 10 to end)\
> \
> \*\*Limits:\*\*\
> \- Maximum 200 pages per PDF<br>

```json
{"openapi":"3.0.3","info":{"title":"PDFMunk API","version":"1.0.0"},"tags":[{"name":"PDF Tools","description":"Merge and split PDF documents"}],"servers":[{"url":"https://pdfmunk.com/api","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"CLIENT-API-KEY","description":"API key for authentication. Get your key from https://pdfmunk.com/dashboard"}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"Error message"},"success":{"type":"boolean"},"details":{"type":"string","description":"Additional error details (optional)"}},"required":["error","success"]}}},"paths":{"/v1/pdf/split":{"post":{"tags":["PDF Tools"],"summary":"Split or extract pages from a PDF","description":"Splits a PDF or extracts specific pages based on page ranges.\n\n**Page Range Format:**\n- Single page: `\"3\"`\n- Range: `\"1-5\"`\n- Multiple ranges: `\"1-3,5,7-10\"`\n- Open-ended: `\"10-\"` (from page 10 to end)\n\n**Limits:**\n- Maximum 200 pages per PDF\n","operationId":"splitPdf","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["url","pages"],"properties":{"url":{"type":"string","format":"uri","description":"URL of the PDF to split"},"pages":{"type":"string","description":"Page range specification"}}}}}},"responses":{"200":{"description":"PDF split successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"split_pdf_url":{"type":"string","format":"uri"},"extracted_pages":{"type":"integer","description":"Number of pages extracted"},"original_pages":{"type":"integer","description":"Total pages in original PDF"},"file_deletion_date":{"type":"string","format":"date"}}}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Unlock a password-protected PDF

> Removes password protection from a PDF file. Supports both user and owner passwords.\
> \
> \*\*Maximum file size:\*\* 10MB<br>

```json
{"openapi":"3.0.3","info":{"title":"PDFMunk API","version":"1.0.0"},"tags":[{"name":"PDF Utilities","description":"Unlock password-protected PDFs"}],"servers":[{"url":"https://pdfmunk.com/api","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"CLIENT-API-KEY","description":"API key for authentication. Get your key from https://pdfmunk.com/dashboard"}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"Error message"},"success":{"type":"boolean"},"details":{"type":"string","description":"Additional error details (optional)"}},"required":["error","success"]}}},"paths":{"/v1/unlockPdf":{"post":{"tags":["PDF Utilities"],"summary":"Unlock a password-protected PDF","description":"Removes password protection from a PDF file. Supports both user and owner passwords.\n\n**Maximum file size:** 10MB\n","operationId":"unlockPdf","requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"type":"object","required":["file","password"],"properties":{"file":{"type":"string","format":"binary","description":"PDF file to unlock"},"password":{"type":"string","description":"Password to unlock the PDF"},"output_name":{"type":"string","description":"Optional custom name for output file"}}}}}},"responses":{"200":{"description":"PDF unlocked successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"message":{"type":"string"},"unlocked_pdf_url":{"type":"string","format":"uri"},"original_filename":{"type":"string"},"output_filename":{"type":"string"}}}}}},"400":{"description":"Bad request or incorrect password","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## Fetch HTML content from a URL

> Fetches and returns the HTML content of a webpage with configurable\
> wait conditions and viewport settings.<br>

```json
{"openapi":"3.0.3","info":{"title":"PDFMunk API","version":"1.0.0"},"tags":[{"name":"Utilities","description":"Helper utilities like URL to HTML conversion"}],"servers":[{"url":"https://pdfmunk.com/api","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"CLIENT-API-KEY","description":"API key for authentication. Get your key from https://pdfmunk.com/dashboard"}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"Error message"},"success":{"type":"boolean"},"details":{"type":"string","description":"Additional error details (optional)"}},"required":["error","success"]}}},"paths":{"/v1/url-to-html":{"post":{"tags":["Utilities"],"summary":"Fetch HTML content from a URL","description":"Fetches and returns the HTML content of a webpage with configurable\nwait conditions and viewport settings.\n","operationId":"urlToHtml","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["url"],"properties":{"url":{"type":"string","format":"uri","description":"URL to fetch HTML from"},"wait_till":{"type":"string","enum":["load","domcontentloaded","networkidle"],"default":"load","description":"When to consider navigation successful"},"timeout":{"type":"integer","default":30000,"description":"Maximum wait time in milliseconds"},"wait_for_selector":{"type":"string","description":"CSS selector to wait for before returning HTML"},"wait_for_timeout":{"type":"integer","default":0,"description":"Additional wait time in milliseconds after page load"},"viewport_width":{"type":"integer","default":1920,"description":"Viewport width"},"viewport_height":{"type":"integer","default":1080,"description":"Viewport height"},"user_agent":{"type":"string","description":"Custom user agent string"},"headers":{"type":"object","description":"Additional HTTP headers","additionalProperties":{"type":"string"}}}}}}},"responses":{"200":{"description":"HTML fetched successfully","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"url":{"type":"string","format":"uri"},"html":{"type":"string","description":"The HTML content of the page"},"timestamp":{"type":"integer","description":"Unix timestamp when content was fetched"}}}}}},"400":{"description":"Bad request","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}}}
```

## The Error object

```json
{"openapi":"3.0.3","info":{"title":"PDFMunk API","version":"1.0.0"},"components":{"schemas":{"Error":{"type":"object","properties":{"error":{"type":"string","description":"Error message"},"success":{"type":"boolean"},"details":{"type":"string","description":"Additional error details (optional)"}},"required":["error","success"]}}}}
```
