Why PDF.co Web API is great for generating a full-featured PDF from HTML, Raw HTML to PDF, URL to PDF

Generate-PDF-Files
HTML to PDF Web API provides an easy and powerful way to generate new PDF files from:

  • HTML code. You can provide raw HTML code for creating PDF files;
  • URL to existing pages on the internet. If you already generating HTML reports in your app then using this function is the easiest and fastest way to add PDF reports to your app;
  • HTML templates + input data in JSON or CSV format. Templates may include conditional logic, variables, custom code via advanced {{Mustache}} and Handlebars templates. Read more about HTML templates.

SIGN UP FOR FREE

 

HTML To PDF With Custom Margin, Paper Size, Header, And Footer
HTML to PDF with Custom Margin, Paper Size, Header, and Footer

PDF.co HTML to PDF API also can help with converting your raw HTML code or web page links into PDF ready for printing, archiving, or sharing. You can customize page size, orientation, margins, and other settings for PDF output.

You can also add HTML markups in the header and footer, such as the current page number out of total pages. PDF.co Web API works from  Python, JavaScript, C#, Java, cURL, PHP, and any programming language. Full documentation for PDF.co Web API is here.

Battle-tested by thousands of production users. Our PDF engine is used in production by thousands of enterprise users.

 

HTML to PDF Web API Benefits

Custom Header & Footer

The Web API supports header and footer customization. You can use it to add more information such as the print date, document title, documentation location, current page number, and total pages.

Custom Size

HTML to PDF Web API supports PDF output page customization. You can set the orientation, margins, and paper size. The margins and paper sizes are in pixels, millimeters, or inches.

Print-friendly Format

HTML to PDF Web API is great for creating a print-friendly version of your website. You can easily share web pages such as an Invoice Checkout page that allows your users to view it offline or add it as an email attachment.

SIGN UP FOR FREE

Web API Supports Multiple Languages

PDF.co platform can be used by software developers from programming languages such as PHP, Javascript, .NET and ASP.NET, C#, Java, Visual Basic, and many others. Find source code samples in our API documentation.

Business Automation Platforms Integrations

If you are not a developer, you can also easily automate your PDF operations via popular business automation platforms: ZapierMakeAirtableSalesforceGoogle Apps Script, and 300+ more.

How to Use HTML to PDF Web API

In this demonstration, we will convert a 2-line HTML code to PDF using the /v1/pdf/convert/from/html endpoint. The output will look like a web page in PDF format. Below is the image of the input and output files.

Raw HTML To PDF Input And Output
HTML To PDF Input And Output

Let’s go over the /v1/pdf/convert/from/html endpoint’s parameters and their corresponding uses.

Endpoint

URL: https://api.pdf.co/v1/pdf/convert/from/html
Method: POST
Parameter Description
html required. Input HTML code to be converted.
margins optional. set to css style margins like 10px, 5mm, 5in for all sides or 5px 5px 5px 5px
paperSize optional. Letter is set by default.
name optional. Filename for the generated output.
async optional. Runs processing asynchronously. Returns jobId to use with job/check: true or false
orientation optional. Set to Portrait or Landscape.
printBackground optional. true by default.
DoNotWaitFullLoad optional. false by default.
expiration optional. Output link expiration in minutes.
profiles optional. Must be a String. Set custom configuration. See profiles examples here

cURL Code Snippet

curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/from/html' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
    "html": "<h1>Hello World!</h1><a href='\''https://pdf.co'\''>Go to PDF.co</a>",
    "name": "result.pdf",
    "margins": "5px 5px 5px 5px",
    "paperSize": "Letter",
    "orientation": "Portrait",
    "printBackground": true,
    "header": "",
    "footer": "",
    "async": false,
    "encrypt": false
}'

The HTML to PDF Web API cURL sample code is available here.

Raw HTML To PDF Web API Demo
HTML To PDF Web API Demo

The HTML to PDF Web API JavaScript sample code is available here.

The HTML to PDF Web API PHP sample code is available here.

The HTML to PDF Web API Python sample code is available here.

The HTML to PDF Web API Java sample code is available here.

The HTML to PDF Web API C# sample code is available here.

SIGN UP FOR FREE

 

PDF.co Web API can be used by software developers from programming languages such as Javascript, Python, PHP, Java, C#, Visual Basic, ASP.NET, Powershell, CLI. We have hundreds of ready-to-copy-paste source code samples for other features also! You can explore our Hundreds of Source Code Samples.