Why PDF.co Web API

Convert HTML to PDF
HTML to PDF Web API helps convert your raw HTML codes or web pages into PDF ready for printing or archiving. You can customize the PDF output by its page size, orientation, and margins. You can also add HTML markups in the header and footer, such as the current page number out of total pages. The Web API can generate PDF from HTML in Python, JavaScript, C#, Java, cURL, PHP, and any programming language you need. Full documentation of PDF.co Web API is here.

PDF.co Web API runs on the secure and certified Amazon AWS infrastructure. All data transfers are encrypted by SSL/TLS encryption. See the security page for details. The on-prem version can run on any hosting provider and cloud storage of your choice.

Battle-tested by thousands of production users. Our engines are tested in production by thousands of enterprise users.

SIGN UP FOR FREE

 

HTML to PDF Web API Benefits

Mustache and Handlebar Template

The HTML to PDF Web API supports Mustache and Handlebar style HTML templates. We have ready-made HTML templates that you can use to generate PDF Invoices.

Custom Script Support

You can use the Custom Script to disable clickable links in your PDF output. You can also use it to hide elements by class name or id.

Add HTML Markup

The Web API supports adding HTML markup in the header and footer. 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.

On-Premise API Server

HTML to PDF Web API can be hosted on your server. We have an on-premise API Server version that we made specifically for businesses and enterprises with high volumes. To try it out, you may contact our support team.

Credits-based system

For every page/image processed credits are reduced on your account. You can purchase credits with one-time payments or subscribe for monthly credits. Separate methods like uploading, background job also consume credits. (cloud version only) You can check how many credits are left using credits property in output or and remaining credits property to check how many credits are left. For details please explore your API logs.

Asynchronous mode

It is supported so you can process large files and documents with hundreds of pages in the cloud.

SIGN UP FOR FREE

 

HTML to PDF Web API Integrations

PDF.co has over 300+ app integration. Kindly explore our following plugins:

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

If you are not from a programming background then also you can easily automate your PDF operations through business automation platforms such as Zapier, Integromat, and hundreds of others. PDF.co Web API uses lossless compression which makes your PDF compact in size. As PDF is using high-quality images and high-quality text, the lossless algorithm helps to compress high-quality text. Actually, lossless compression is a compression type that is used by PDF documents containing text. Its algorithm creates reference points for textual patterns, stores them in a catalog, and then brings them back to your file.

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 Sample Apps on Github. Stay tuned and stay updated with us to get more of these.

Related Samples: