Convert HTML to PDF

An easy to use web service to convert HTML webpage to PDF

Try it!

Enter your url beginning with http - or a html string - to convert to a PDF or image file.

Your page doesn't have to be W3C compliant, but please be certain that the page your trying isn't missing links to images or files as we tend to reject pages like that by default :)



Automate your HTML to PDF conversion using our FREE API key.

Our Free Plan has 200 credits/month with 5 Mb per PDF file.

Large PDF files use 1 credit per 500kb of network traffic.

Now used commercially by 10,500+ companies! We've grown too big to be a completely free service - read the backstory.

Code examples available for asp.net, jquery/javascript, php, java, android and others

Conversions are done on multiple server clusters spread across different datacenters

How to convert an html string or save a url or webpage to PDF

    • ASP.NET / C#

    • string apiKey = "ABCD-1234";
      string value = "http://www.google.com"; // a url starting with http or an HTML string.  See php example #5 if you are using long strings  
      using (var client = new WebClient())
      {
                                                          client.QueryString.Add("apikey", apiKey);
                                                          client.QueryString.Add("value", value);
                                                          client.DownloadFile("https://api.html2pdfrocket.com/pdf/", @"c:\temp\mypdf.pdf");
      }
      
      string apiKey = "ABCD-1234";
      string value = "http://www.google.com"; // a url starting with http or an HTML string
      using (var client = new WebClient())
      {
          NameValueCollection options = new NameValueCollection();
          options.Add("apikey", apiKey);
          options.Add("value", value);
          ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;  //needed for older .net versions
                                              byte[] result = client.UploadValues("https://api.html2pdfrocket.com/pdf", options);
          System.IO.File.WriteAllBytes(Server.MapPath(Path.Combine("~/", @"c:\temp\mypdf.pdf")), result);
      }
      
    • See more ASP.NET / C# examples including MVC..

    • HTML

    • <a href="https://api.html2pdfrocket.com/pdf?value=http://www.google.com&apikey=ABCD-1234">Download PDF</a>
      
    • See more javascript examples

    • PHP

    • $apikey = 'ABCD-1234';
      $value = 'http://www.google.com'; // a url starting with http or an HTML string (1600 byte limit).  see example #5 if you have a long HTML string
      $result = file_get_contents("https://api.html2pdfrocket.com/pdf?apikey=" . urlencode($apikey) . "&value=" . urlencode($value));
      file_put_contents('mypdf.pdf',$result);
      
    • See more PHP examples including streaming to the browser..

    • Java

    • We've just added a Java example! Please check it out here

    • Android

    • We've just added an Android example! Please check it out here

    • RUBY

    • require 'net/http'
      apikey = 'ABCD-1234'
      value = 'http://www.google.com'   # a url starting with http or an HTML string
      uri = URI("https://api.html2pdfrocket.com/pdf?apikey=#{apikey}&value=#{value}")
      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
      
    • Batch/Asynchronous Process

    • For PDF conversion taking more than 30 seconds or input/output files more than 6 Mb, you need to use the batch/asynchronous parameters. Examples: C#, PHP

    • Batch
      true to send it through batch process. API will return a PdfToken that you could use for your next api call.
    • PdfToken
      Token to retrieve the pdf file that was passed in batch process. You will get a PdfLink as a return.
    • Webhook
      Instead of polling if the pdf file is already ready, you can send a webhook url where we could post once the file is ready.
    • PdfDownloadExpirySeconds
      Number of seconds before the PdfLink expires. Default and minimum is 300 seconds, max is 900 seconds.
    • Page Breaks

    • <!DOCTYPE html>
      <html>
      <head>
                      <style>
                      .page {
                      padding: 100px;
              }
      
                      @media screen {
                      .page {
                      page-break-before: always !important;
                  }
              }
                      </style>
      </head>
      <body>
                      <div class="page">
                      <div style="height: 20px; background-color: #f91">Page 1</div>
                      </div>
                      <div class="page">
                      <div style="height: 20px; background-color: #000">Page 2</div>
                      </div>
      </body>
      </html>
      
Try it!

Enter your url beginning with http - or a html string - to convert to a PDF or image file.

Your page doesn't have to be W3C compliant, but please be certain that the page your trying isn't missing links to images or files as we tend to reject pages like that by default :)



Example Webpages Converted

Automate your HTML to PDF conversion using our FREE API key.

Our Free Plan has 200 credits/month with 5 Mb per PDF file.

Large PDF files use 1 credit per 500kb of network traffic.

Please help us by spreading the word