Get a Free Trial

Free HTML to PDF API: Convert HTML Programmatically

HTML to PDF API
Looking to capture JPGs, PNGs, TIFFs? Head over to our dedicated HTML to Image API.

A powerful, reliable HTML to PDF API. GrabzIt utilizes a full web browser instance to capture your raw HTML or URLs, ensuring pixel-perfect rendering of complex document layouts, CSS3 Grid, and custom web fonts.

Generate searchable, paginated, client-ready PDF documents programmatically in minutes.

Convert HTML to PDF

Note: Free tier and trial API conversions include a GrabzIt watermark. Upgrade to a premium plan for unbranded, production-ready documents.

When converting HTML, you need to include all CSS and image content in the HTML code or use absolute URLs to link to them. One example of this would be a CSS file referenced in the HTML code, using an absolute URL. Another choice is to use a Data URL, which lets you put resources like images directly in the HTML code.

Check out the demo above to see how easy it is to convert HTML into an PDF. GrabzIt's APIs assist developers in creating different types of content effortlessly.

Not a developer? You don't need to write code! Choose the right tool for your needs:

For Developers: HTML to PDF API

We believe GrabzIt is one of the best PDF API's on the market. Our API offers a simple and straightforward integration into any programming language. With GrabzIt, you can customize the appearance of your PDF, including adding headers and footers. You can also enhance security by protecting the PDF with a password.

We offer efficient, built-in compression. If your high-resolution renderings result in large PDF files, you can reduce the file size by adjusting the PDF quality.

Of course you can also convert HTML files to PDF. If you have HTM or HTML files and use PHP, you can generate PDFs from these documents on the server side. Just use the appropriate FileToPDF method for the language you are using instead.

Having related content split across multiple pages in a PDF document often makes it difficult to read. Which, is why it is often necessary to specify where you want page breaks to appear in a PDF file. To do this you need to specify the special page break HTML syntax as explained in this tutorial.

Easily enable your app to convert HTML to PDF by using GrabzIt's simple to use API. Accessible in nine different ways. Just choose your required method from below and then follow the relevant instructions.

The example code below shows how easy it is to use our API to convert HTML to PDF using C#, although GrabzIt's ASP.NET library is compatible with any .NET language. To start creating PDF's just download the ASP.NET Library, get your key and secret and then use the demo contained within. Then check out the API documentation for ASP.NET to learn all the ways you can use GrabzIt's API.

//The client should be stored somewhere and reused!
GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret", client);
grabzIt.HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>"); 
await grabzIt.SaveToAsync("documents/result.pdf");

The example code below shows how easy it is to use our HTML to PDF Java Library. To start creating PDF's just download the Java Library, get your key and secret and then use the demo contained within. Then check out the API documentation for Java to learn all the ways you can use GrabzIt's API.

GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
grabzIt.HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>"); 
grabzIt.SaveTo("documents/result.pdf");

The example code below shows how easy it is to use our convert HTML to PDF using JavaScript. To start creating PDF's download GrabzIt's JavaScript Library. Then get your key and secret, add the domain you want to use the JavaScript on and then check out the API documentation for JavaScript to learn all the ways you can use GrabzIt's API.

<script src="https://cdn.jsdelivr.net/npm/@grabzit/js@/grabzit.min.js"></script>
<script>
GrabzIt("Sign in to view your Application Key").ConvertHTML("<html><body><h1>Hello World!</h1></body></html>",
{"format": "pdf"}).Create();
</script>

The example code below shows how easy it is to use our API to perform an HTML to PDF conversion using Node.js. To start creating PDF's just download the Node.js Package, get your key and secret and then use the demo contained within. Then check out the API documentation for Node.js to learn all the ways you can use GrabzIt's API.

var grabzit = require('grabzit');

var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret");
client.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>");
client.save_to("documents/result.pdf", function (error, id){
    if (error != null){
        throw error;
    }
});

The example code below shows how easy it is to do HTML to PDF conversion using Perl. To start creating PDF's just download the Perl Library, get your key and secret and then use the demo contained within. Then check out the API documentation for Perl to learn all the ways you can use GrabzIt's API.

#!/usr/bin/perl

use GrabzItClient;

$grabzIt = GrabzItClient->new("Sign in to view your Application Key", "Sign in to view your Application Secret");
$grabzIt->HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>");
$grabzIt->SaveTo("documents/result.pdf");

The example code below shows how easy it is to use our API to convert HTML to PDF using PHP. To start generating PDF files just download the PHP Library, get your key and secret and then use the demo contained within. Then check out the API documentation for PHP to learn all the ways you can use GrabzIt's API.

include("GrabzItClient.php");

$grabzIt = new \GrabzIt\GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
$grabzIt->HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>"); 
$grabzIt->SaveTo("documents/result.pdf");

The example code below shows how easy it is to use our PDF Convertor with Python. To start creating PDF's just download the Python Library, get your key and secret and then use the demo contained within. Then check out the API documentation for Python to learn all the ways you can use GrabzIt's API.

from GrabzIt import GrabzItClient

grabzIt = GrabzItClient.GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret")
grabzIt.HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>") 
grabzIt.SaveTo("documents/result.pdf") 

The example code below shows how easy it is to convert HTML to PDF using our REST API. Then check out the API documentation for the REST API to learn all the ways you can customize your captures.

curl 
-d key=Sign in to view your Application Key
-d format=pdf 
-d html=%3Chtml%3E%3Cbody%3E%3Ch1%3EHello%20World%21%3C%2Fh1%3E%3C%2Fbody%3E%3C%2Fhtml%3E
https://api.grabz.it/convert 

The example code below shows how easy it is to use our API to convert HTML to PDF using Ruby. To start creating PDF's just download the Ruby Gem, get your key and secret and then use the demo contained within. Then check out the API documentation for Ruby to learn all the ways you can use GrabzIt's API.

require 'grabzit'

grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret")
grabzItClient.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>")	
grabzItClient.save_to("documents/result.pdf") 	

Several popular use cases for converting HTML to PDF exist. One of them is for code documentation. Many developers prefer to have their code in a PDF format for easier sharing and printing.

Another popular use case for converting HTML to PDF is for creating reports or invoices from web pages. This is where a code to PDF API is useful. These APIs allow you to simply input your HTML code and convert it into a PDF document with just a few lines of code.