Convert HTML to PDF with our API

 

 

You can use our API to convert webpages or raw HTML to PDF automatically in any programming language. You can control many options for the PDF and we guarantee fast PDF creation in our data centers around the world!

You control options like page size control, custom headers/footers and other standard options. But we also offer many unique functions, such as watermarking, merging multiple web pages into one PDF, converting long web pages into a single long one page PDF!

To get started just do this:

Refer to the API documentation to discover all the options and see more code examples!

API License


from $9 / month


  • Fast PDF creation
  • Many options
  • Code in any language
  • Easy to use

Sign Up!


Code Examples

It is very easy to convert a URL to PDF in PHP with our API. Just get the result of an API call to our service with the PHP function get_file_contents.

If you’d want to convert http://www.example.com to PDF then you’ll just do the following:

$apikey = 'abcde12345';    // you should fill in your own api key here
$url = urlencode('http://www.example.com');

$result = file_get_contents("http://api.htm2pdf.co.uk/urltopdf?apikey=$apikey&url=$url");
file_put_contents('/tmp/mypdf.pdf', $result);

Please check out the API documentation for documentation on options that you can use as well as more code examples. Note that we also have a PHP library with easy to use functions and error handling that you may want to check out.

It is very easy to convert a URL to PDF in Java with our HTML to PDF API.

To convert http://www.example.com to PDF you’d use the following Java code:

String apikey = "abcde12345";
String url = "http://www.example.com";
File outs = new File("C:\\temp\mypdf.pdf");

URL u = new URL("http://api.htm2pdf.co.uk/urltopdf?apikey=" + apikey + "&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();

This hopefully helps you to be on your way using the API for URL to PDF conversion in Java.
Please check out the API documentation if you want to see the full list of options you can use and see more code examples.

If you want to use our API in Ruby you just get the result of the API call with the Ruby class Net::HTTP.

Here’s a code example for convert the URL http://www.example.com to PDF:

require 'net/http'
apikey = 'abcde12345'
url = 'http://www.example.com'

uri = URI("http://api.htm2pdf.co.uk/urltopdf?apikey=#{apikey}&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

This hopefully helps you to be on your way using the API for URL to PDF conversion in Ruby.
Please refer to the API documentation for a full list of options and more code examples.

To convert a URL to PDF in C# with our HTML to PDF API you can easily get the result of the API call with the C# WebClient method.

Say you want to convert http://www.example.com to PDF. Then you could use the following code example:

string apiKey = "abcde12345";
string url = "http://www.example.com";

using (var client = new WebClient())
{
    client.QueryString.Add("apikey", apiKey);
    client.QueryString.Add("url", url);
    client.DownloadFile("http://api.htm2pdf.co.uk/urltopdf", @"c:\temp\mypdf.pdf");
}

This hopefully helps you to be on your way using the API for URL to PDF conversion in C#.

Please check the API specs for all the options you can use as well as more code examples in C#.

When you convert a URL to PDF in VB.net with our HTML to PDF API, you can use the VB.net WebClient.

The following code example shows how you can convert http://www.example.com to PDF.

Dim apiKey As String = "abcde12345"
Dim url As String = "http://www.example.com"

Using client As New WebClient
    client.QueryString.Add("apikey", apiKey)
    client.QueryString.Add("url", Url)
    client.DownloadFile("http://api.htm2pdf.co.uk/urltopdf", "c:\temp\mypdf.pdf")
End Using

If you want more VB.net examples or if you want to see all the features and options of the API then check out our HTML to PDF API documentation.

It is very easy to convert a URL to PDF in Python with our HTML to PDF API. Just get the result of our URL with the Python function urllib2.urlopen.

This code converts http://www.example.com to PDF.

import urllib2

data = {
   'apikey': 'abcde12345',
   'url': 'http://www.example.com'
}
requesturl = 'http://api.htm2pdf.co.uk/urltopdf?apikey={apikey}&url={url}'.format(**data)
result = urllib2.urlopen(requesturl)
localFile = open('mypdf.pdf', 'w')
localFile.write(result.read())
localFile.close()

This was just a simple example of how you can use the API for URL to PDF conversion in Python.

Please refer to the API page for a complete list of options that you can use as well as more code examples.

You can easily convert URLs to PDF in Perl with our HTML to PDF API. You can do it with several functions in Perl, like the File::Fetch or the LWP::Simple module.

use File::Fetch;

my $apikey = 'abcde12345';
my $url = "http://www.example.com";

my $ff = File::Fetch->new(uri => "http://api.htm2pdf.co.uk/urltopdf?apikey=$apikey&url=$url");
my $where = $ff->fetch( to => '/tmp/mypdf.pdf');

This should get you on on your way using the API for URL to PDF conversion in Perl.

More documentation and code examples can be found here where you’ll also find all the options that you can use.

If you are looking for code examples in different languages then please contact us


Let your visitors save web pages as PDF with one click

 

 

If you have one or more websites and you want your visitors to save pages of your website as PDF then look no further. Just by adding a link to our site you can get this done.

And of course you can choose which page size you’d like and many other options!

Just execute the following steps:

Just check out the full documentation on this functionality for more options and examples!

Save as PDF


from $45 / year


  • One click PDF
  • Many options
  • Easy to install

Sign Up!

Comments are closed.