HTML to PDF / HTTP API Examples
This page contains various examples of using the HTML to PDF API via HTTP API. The examples are complete and fully functional. Read more about how to convert HTML to PDF via HTTP API.
Basic examples
Advanced examples
- Customize the page size and the orientation
- Put the source URL in the header and the page number in the footer
- Create fillable PDF form
- Zoom the HTML document
- Set PDF metadata
- Create a Powerpoint like presentation from an HTML document
- Convert an HTML document section
- Inject an HTML code
- Convert a responsive web page as it appears on a large device
- Renderer debugging - highlight HTML elements
- Renderer debugging - borders with spacing around HTML elements
Template rendering examples
- Create PDF from JSON data
- Create PDF from XML data
- Create PDF from YAML data
- Create PDF from CSV data
Basic examples
Webpage to PDF file
curl -f -u "demo:demo" \ -o "example.pdf" \ -F "content_viewport_width=balanced" \ -F "url=http://www.example.com" \ https://api.pdfcrowd.com/convert/24.04/
HTML file to PDF file
curl -f -u "demo:demo" \ -o "MyLayout.pdf" \ -F "content_viewport_width=balanced" \ -F "file=@/path/to/MyLayout.html" \ https://api.pdfcrowd.com/convert/24.04/
HTML string to PDF file
curl -f -u "demo:demo" \ -o "HelloWorld.pdf" \ -F "content_viewport_width=balanced" \ --form-string "text=<html><body><h1>Hello World!</h1></body></html>" \ https://api.pdfcrowd.com/convert/24.04/ ## or read HTML from a pipe html_producer | curl -u "demo:demo" \ -o "HelloWorld.pdf" \ -F "content_viewport_width=balanced" \ -F "text=<-" \ https://api.pdfcrowd.com/convert/24.04/
Advanced examples
Customize the page size and the orientation
curl -f -u "demo:demo" \ -o "letter_landscape.pdf" \ -F "page_size=Letter" \ -F "orientation=landscape" \ -F "no_margins=true" \ -F "url=http://www.example.com" \ https://api.pdfcrowd.com/convert/24.04/
Put the source URL in the header and the page number in the footer
curl -f -u "demo:demo" \ -o "header_footer.pdf" \ -F "header_height=15mm" \ -F "footer_height=10mm" \ --form-string "header_html=<a class='pdfcrowd-source-url' data-pdfcrowd-placement='href-and-content'></a>" \ --form-string "footer_html=<center><span class='pdfcrowd-page-number'></span></center>" \ -F "margin_top=0" \ -F "margin_bottom=0" \ -F "url=http://www.example.com" \ https://api.pdfcrowd.com/convert/24.04/
Create fillable PDF form
curl -f -u "demo:demo" \ -o "form.pdf" \ -F "enable_pdf_forms=true" \ --form-string "text=<html><body>Enter name:<input type=text></body></html>" \ https://api.pdfcrowd.com/convert/24.04/ ## or read HTML from a pipe html_producer | curl -u "demo:demo" \ -o "form.pdf" \ -F "enable_pdf_forms=true" \ -F "text=<-" \ https://api.pdfcrowd.com/convert/24.04/
Zoom the HTML document
curl -f -u "demo:demo" \ -o "zoom_300.pdf" \ -F "scale_factor=300" \ -F "url=http://www.example.com" \ https://api.pdfcrowd.com/convert/24.04/
Set PDF metadata
Create a Powerpoint like presentation from an HTML document
curl -f -u "demo:demo" \ -o "slide_show.pdf" \ -F "page_layout=single-page" \ -F "page_mode=full-screen" \ -F "initial_zoom_type=fit-page" \ -F "orientation=landscape" \ -F "no_margins=true" \ -F "url=https://pdfcrowd.com/api/" \ https://api.pdfcrowd.com/convert/24.04/
Convert an HTML document section
curl -f -u "demo:demo" \ -o "html_part.pdf" \ -F "element_to_convert=#main" \ -F "url=https://pdfcrowd.com/api/" \ https://api.pdfcrowd.com/convert/24.04/
Inject an HTML code
curl -f -u "demo:demo" \ -o "html_inject.pdf" \ --form-string "custom_javascript=el=document.createElement('h2'); el.textContent='Hello from Pdfcrowd API'; el.style.color='red'; el_before=document.getElementsByTagName('h1')[0]; el_before.parentNode.insertBefore(el, el_before.nextSibling)" \ -F "url=http://www.example.com" \ https://api.pdfcrowd.com/convert/24.04/
Convert a responsive web page as it appears on a large device
curl -f -u "demo:demo" \ -o "bootstrap.pdf" \ -F "content_viewport_width=large" \ -F "no_margins=true" \ -F "url=https://getbootstrap.com/" \ https://api.pdfcrowd.com/convert/24.04/
Renderer debugging - highlight HTML elements
curl -f -u "demo:demo" \ -o "highlight_background.pdf" \ --form-string "custom_javascript=libPdfcrowd.highlightHtmlElements({backgroundColor: 'rgba(255, 191, 0, 0.1)', borderColor:null})" \ -F "url=http://www.example.com" \ https://api.pdfcrowd.com/convert/24.04/
Renderer debugging - borders with spacing around HTML elements
curl -f -u "demo:demo" \ -o "highlight_borders.pdf" \ --form-string "custom_javascript=libPdfcrowd.highlightHtmlElements({borderColor: 'orange', backgroundColor: null, padding: '4px', margin: '4px'})" \ -F "url=http://www.example.com" \ https://api.pdfcrowd.com/convert/24.04/
Template rendering examples
Create PDF from JSON data
curl -f -u "demo:demo" \ -o "output.pdf" \ --form-string "data_string={ \"name\": \"World\", \"product\": \"Pdfcrowd API\" }" \ --form-string "text=Hello {{ name }} from {{ product }}" \ https://api.pdfcrowd.com/convert/24.04/ ## or read HTML from a pipe html_producer | curl -u "demo:demo" \ -o "output.pdf" \ --form-string "data_string={ \"name\": \"World\", \"product\": \"Pdfcrowd API\" }" \ -F "text=<-" \ https://api.pdfcrowd.com/convert/24.04/
Create PDF from XML data
curl -f -u "demo:demo" \ -o "output.pdf" \ --form-string "data_string=<?xml version=\"1.0\" encoding=\"UTF-8\"?> <data> <name>World</name> <product>Pdfcrowd API</product> </data>" \ --form-string "text=Hello {{ data.name }} from {{ data.product }}" \ https://api.pdfcrowd.com/convert/24.04/ ## or read HTML from a pipe html_producer | curl -u "demo:demo" \ -o "output.pdf" \ --form-string "data_string=<?xml version=\"1.0\" encoding=\"UTF-8\"?> <data> <name>World</name> <product>Pdfcrowd API</product> </data>" \ -F "text=<-" \ https://api.pdfcrowd.com/convert/24.04/
Create PDF from YAML data
curl -f -u "demo:demo" \ -o "output.pdf" \ -F "data_string=name: World product: Pdfcrowd API" \ --form-string "text=Hello {{ name }} from {{ product }}" \ https://api.pdfcrowd.com/convert/24.04/ ## or read HTML from a pipe html_producer | curl -u "demo:demo" \ -o "output.pdf" \ -F "data_string=name: World product: Pdfcrowd API" \ -F "text=<-" \ https://api.pdfcrowd.com/convert/24.04/
Create PDF from CSV data
curl -f -u "demo:demo" \ -o "output.pdf" \ -F "data_string=name,product World,Pdfcrowd API" \ --form-string "text=Hello {{ name }} from {{ product }}" \ https://api.pdfcrowd.com/convert/24.04/ ## or read HTML from a pipe html_producer | curl -u "demo:demo" \ -o "output.pdf" \ -F "data_string=name,product World,Pdfcrowd API" \ -F "text=<-" \ https://api.pdfcrowd.com/convert/24.04/