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
Template rendering examples

Basic examples

Webpage to PDF file

curl -f -u demo:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -o zoom_300.pdf \
    -F scale_factor=300 \
    -F url=http://www.example.com \
    https://api.pdfcrowd.com/convert/24.04/

Set PDF metadata

curl -f -u demo:ce544b6ea52a5621fb9d55f8b542d14d \
    -o with_metadata.pdf \
    -F author=Pdfcrowd \
    -F title=Hello World \
    -F subject=Demo \
    -F keywords=Pdfcrowd,demo \
    -F url=http://www.example.com \
    https://api.pdfcrowd.com/convert/24.04/

Create a Powerpoint like presentation from an HTML document

curl -f -u demo:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -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:ce544b6ea52a5621fb9d55f8b542d14d \
    -o output.pdf \
    -F "data_string=name,product
World,Pdfcrowd API" \
    -F "text=<-" \
    https://api.pdfcrowd.com/convert/24.04/