Our API makes PDFs from webpages or HTML. Fast, easy and reliable!
Try it with any URL below or scroll down to the code examples.
Below you'll find basic examples for all major programming languages. With just a few lines of code you can convert any URL or HTML to PDF. You can find all options and examples in our API documentation and the description of the click to PDF links.
// the following code converts the URL https://example.com to PDF in PHP
$url = urlencode("https://example.com");
$license = "yourlicensekey";
// now we call the HTML2PDF API
$pdf = file_get_contents("https://api.html2pdf.co.uk/?license={$license}&url={$url}";
// the PDF is stored in the parameter $pdf now
Note - we also have a HTML2PDF PHP library available!
// the following code converts the URL https://example.com to PDF in C#/ .NET
string license = "yourlicensekey";
string url = System.Net.WebUtility.UrlEncode("https://example.com");
using (var client = new WebClient())
{
client.QueryString.Add("license", license);
client.QueryString.Add("url", url);
client.DownloadFile("https://api.html2pdf.co.uk/", @"c:\temp\mypdf.pdf");
}
// the following code converts the URL https://example.com to PDF in Java
String license = "yourlicensekey";
String url = URLEncoder.encode("https://example.com",java.nio.charset.StandardCharsets.UTF_8.toString() );
File outs = new File("C:\\temp\mypdf.pdf");
URL u = new URL("https://api.html2pdf.co.uk/?license=" + license + "&url=" + url);
URLConnection uc = u.openConnection();
BufferedInputStream is = new BufferedInputStream(uc.getInputStream());
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(outs));
byte[] b = new byte[8 * 1024];
int read = 0;
while ((read = is.read(b)) > -1) {
bout.write(b, 0, read);
}
bout.flush();
bout.close();
is.close();
// the following code converts the URL https://example.com to PDF in Python
import urllib2
data = {
'license': 'yourlicensekey',
'url': 'https://example.com'
}
requesturl = 'https://api.html2pdf.co.uk/?license={license}&url={url}'.format(**data)
result = urllib2.urlopen(requesturl)
localFile = open('mypdf.pdf', 'w')
localFile.write(result.read())
localFile.close()
# the following code converts the URL https://example.com to PDF in Ruby
require 'net/http'
license = 'yourlicensekey'
url = 'https://example.com'
uri = URI("https://api.html2pdf.co.uk/?license=#{license}&url=#{url}")
Net::HTTP.start(uri.host, uri.port) do |http|
request = Net::HTTP::Get.new uri.request_uri
http.request request do |response|
open 'mypdf.pdf', 'w' do |io|
response.read_body do |chunk|
io.write chunk
end
end
end
end
# the following code converts the URL https://example.com to PDF in Perl
use File::Fetch;
use URI::Escape;
my $license = "yourlicensekey";
my $url = uri_escape("https://example.com");
my $ff = File::Fetch->new(uri => "https://api.html2pdf.co.uk/?license=$license&url=$url");
my $where = $ff->fetch( to => '/tmp');
# The following cURL command converts the URL https://example.com to a PDF with the name result.pdf
curl -d "license=yourlicensekey" \
--data-urlencode "url=https://example.com" \
-o result.pdf \
-H "Content-Type: application/x-www-form-urlencoded" \
-X POST https://api.html2pdf.co.uk/
# If you want to use HTML instead, then you can use the following cURL command to convert a file html.html with HTML to PDF
curl -d "license=yourlicensekey" \
--data-urlencode html@html.html \
-o result.pdf \
-H "Content-Type: application/x-www-form-urlencoded" \
-X POST https://api.html2pdf.co.uk/
# The following Wget command converts the URL https://example.com to a PDF with the name result.pdf
wget -O result.pdf --post-data="license=yourlicensekey&url=https://example.com" https://api.html2pdf.co.uk/
<!-- If you want to add a Click to PDF link to your pages, then just add the following link -->
<a href="javascript:location.href='https://api.html2pdf.co.uk/?url='+escape(location.href)">Click to PDF</a>
The easiest service to use with the best support!
You can set all your conversion options in a WYSIWIG members area and use our API with just a few lines of code.
Custom page sizes, header, footer and many more easy to configure settings at your disposal.
PDFs that look EXACTLY like what you see on the screen and that can be used in professional settings.
We love what we do and have been doing it since 2008. We know what you need and are happy to help!
We have been around for a long time and thousands of customers trust and have trusted us. You can too!
99.9% Uptime and the latest technology in use. You can let us worry about delivering and maintaining!
We are running HTML2PDF since 2008 and hundreds of companies have trusted our service in the past.
" We're running this without fail for years now. Excellent! "
" Thanks for all your help. I appreciate how kind your support is!"
" Thanks for the great solution and the speedy support. You're a lifesaver!"
If you want to try our API first, then please feel free to get a free trial!