Convert HTML to PDF files

PDF Rocket is a fast, easy to use web service to convert an HTML webpage into an image or PDF file

Now used commercially by 5000+ 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

Why HTML 2 PDF Rocket

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("http://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);
          byte[] result = client.UploadValues("http://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="http://api.html2pdfrocket.com/pdf?value=http://www.google.co.nz&apikey=ABCD-1234">Download PDF</a>
      
    • <a href="http://html2pdfrocket.com/html/topdf?apikey=ABCD-1234">Download Current Page as PDF</a>
      
    • If you wish to use extra parameters when doing API conversions, you must use follow the api.html2pdfrocket.com example. The http://html2pdfrocket.com/html/topdf shortcut example only works with the default parameters.

    • See more javascript examples

    • PHP

    • $apikey = 'ABCD-1234';
      $value = 'http://www.google.com'; // a url starting with http or an HTML string.  see example #5 if you have a long HTML string
      $result = file_get_contents("http://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! All the optional parameters below can be used. Please check it out here

    • Android

    • We've just added an Android example! All the optional parameters below can be used. 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("http://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
      
    • Optional PDF Parameters (See here for image thumbnail parameters)

    • MarginLeft
      Value of left margin - default is 0
    • MarginRight
      Value of right margin - default is 0
    • MarginTop
      Value of top margin - default is 0
    • MarginBottom
      Value of bottom margin - default is 0
    • UseGrayscale
      true to generate PDF in grayscale, false or leave blank for full colour
    • UseLandscape
      true to rotate page to landscape, false or leave blank for portrait
    • EnableForms
      true to turn html form fields into pdf form fields
    • LowQuality
      true to reduce the quality, which may lower your network usage if quality is still satisfactory
    • ImageQuality
      override the default image quality percentage (94) and use your own
    • DisableShrinking
      true to disable the intelligent shrinking process we use make the pixel/dpi ratio constant
    • DisableJavascript
      true to disable running JS on page, otherwise javascript runs
    • JavascriptDelay
      Milliseconds to wait for JS to finish executing before converting the page.  Useful for ajax calls.
    • UsePrintStylesheet
      true to use the print media stylesheet, false or leave blank to use normal stylesheet
    • FooterSpacing
      Spacing between the header and the content in mm - default is 0
    • HeaderSpacing
      Spacing between the footer and the content in mm - default is 0
    • PageSize
      Default size is A4 but you can use Letter, A0, A2, A3, A5, Legal, etc.
    • PageWidth
      Page width - if you use this, you must also use PageWidth
    • PageHeight
      Page height - if you use this, you must also use PageHeight
    • ViewPort
      e.g. 800x600 - Set if you have custom scrollbars or css attribute overflow to emulate window size
    • Dpi
      Explicitly set the DPI, which is 96 by default.  Also see Zoom settings
    • Zoom
      Default zoom is 1.00  You can use any floating point number, e.g. 0.5, 0.75, 1.10, 2.55, 3...
    • OutputFormat
      Must be either "pdf", "jpg", "png", "bmp" or "svg" if not supplied the default is PDF
    • FileName
      Optionally the name you want the file to be called when downloading or $unique$ for guid
    • Username
      For URL conversions, creates a secure basic authentication connection to your server
    • Password
      For URL conversions, creates a secure basic authentication connection to your server
    • Cookie
      Supply in format: NAME|||VALUE|||NAME|||VALUE (that's 2 cookies).  Often used for authentication.
    • Headers and footers, including automatic page numbering can be done by either passing in a url to HeaderUrl/HeaderHtml or FooterUrl/FooterHtml, or passing in a small snippet of plain text to HeaderLeft, HeaderRight, FooterLeft or FooterRight. Note that if you want to use a header or footer, you must also use a margin parameter like MarginTop or MarginBottom to ensure there is space for the header or footer. Your Html should also start with <!DOCTYPE html> and include the <html> and <body> tags

    • HeaderHtml
      To use an html header on each page - a string starting with <!DOCTYPE html>
    • FooterHtml
      To use an html footer on each page - a string starting with <!DOCTYPE html>
    • HeaderUrl
      To use an html header on each page - a url starting with http containing the html
    • FooterUrl
      To use an html footer on each page - a url starting with http containing the html
    • HeaderLeft
      Top left header text (can use replacement tags below)
    • HeaderRight
      Top right header text (can use replacement tags below)
    • FooterLeft
      Bottom left footer (can use replacement tags below)
    • FooterRight
      Bottom right footer (can use replacement tags below)
    • FooterFontName
      Footer font names - Arial by default
    • HeaderFontName 
      Header font names - Arial by default
    • FooterFontSize
      The font sizes - 12 by default.  Use the the plain value (do not use px or pt)
    • HeaderFontSize
      The font sizes - 12 by default.  Use the the plain value (do not use px or pt)
    • The replacement tags in the following table can be used to set the page numbering. For example, using FooterRight with a value of 'Page [page] of [toPage]', and remembering to also use a margin per above, e.g. MarginBottom with a value of 20

    • [page]
      Tag replaced with number of the pages currently being printed
    • [frompage]
      Tag replaced with the number of the first page to be printedr
    • [topage]
      Tag replaced with the number of the last page to be printed
    • [section]
      Tag replaced with the name of the current section
    • Let us know if you need extra parameters or other API features

Try it yourself

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 :)


We get feedback daily! Here is some of what our customers say

Thanks for an awesome API - Anmol, January 2017

Thanks for your support and your great service - Antonio, January 2017

Excellent! Thank you for the very quick response! - Rodriguez, January 2017

I truly appreciated the work you put on this service, and the face that it's free makes it very useful for developers like myself! - Ahmed, January 2017

Yours is the best HTML —> PDF converter I’ve discovered so far! - Ananda, January 2017

The service is working great! - Scott, January 2017

Thanks, looks like a great product and exactly what I'm looking for. Price point is awesome as well - Scott, January 2017

Can't thank you enough for the API. Super easy to use, and a total lifesaver for a quick feature addition this afternoon vs the headache of trying to do this myself - Will, January 2017

Thank you for your service, it is really helpful - Alessandro, January 2017

Thanks for the quick turnaround! - Khamsouk, January 2017

Good to hear from someone who gives a **** [ed goes on about compeditors] Phil, January 2017

Thank you for your great API :) ! - Cedric, January 2017

Keep up with your lovely service. Thanx - Sotirios, December 2016

Great product! - Matthew, December 2016

Thanks for your service and support - Dennis, December 2016

Very happy with the service - Taylor, December 2016

Just wanted to say thank you for your responses to my questions. Much appreciated! - Rob, December 2016

It's done its job brilliantly - Owen, December 2016

Thank you for your good service! - Silvan, December 2016

Thanks for your PDF service! - Jonty, December 2016

Thank you very much, you are the best - Dennis, December 2016

We have gone through with implementing your service. It’s fantastic for our needs - Shawn, December 2016

Your service has been solid for us and we are continually happy with it - Jared, December 2016

Excellent Tool with Excellent Support! - Prathik, November 2016

Thanks so much for the service. Amazing!! - Andrei, November 2016

Great API you have ;) - Good job must be recognized :) - João, November 2016

Awesome - Mike, November 2016

BTW, the service has been performing great! - Joe, November 2016

Overall is a good service - Luca, November 2016

We prefer your service - Kent, November 2016

Appreciate your support - Mary, November 2016

Thanx again for having this great API - Gijsbert, November 2016

See more feedback

Monthly Credit Pricing

Each plan receives credits each month. Each credit allows one conversion. Large PDF files use 1 credit per 500kb of network traffic.


    • Always Free

    • $0 / Month

      • 200 credits
      • 5mb per PDF file
    • Get Key
    • Starter

    • $5/month

      • 500+ credits
      • 20mb per PDF file
    • Purchase
    • Basic

    • $10/month

      • 1000 credits
      • 20mb per file
    • Purchase
    • Standard

    • $20/month

      • 3000 credits
      • 20mb per file
    • Purchase
    • Pro

    • $25/month

      • 5000 credits
      • 20mb per file
    • Purchase
    • Advanced

    • $40/month

      • 10000 credits
      • 20mb per file
    • Purchase

Numbers don't fit into your budget or plan? drop us a line with what you do need - we have customers affordably doing 1.6 million PDF's per month

Top Four Frequently Asked Questions

What about security (and also testing on localhost) - do I have to make my webpage publically available?

No - you can send the html (instead of a url) - there is no need to put the page you want to convert publically on the web. This is also slighly faster as we don't have to download the webpage from the internet.

If I do use the URL option, what security options like SSL are there?

You can use basic authentication and pass in a username and password. Our API supports SSL and also reading from https pages. Alternatively some customers use a simple token system, e.g. by passing a secret parameter on the url that noone else will know, e.g. www.myurl.com/invoice?secret=abc123. The token could be simple - the same each time, or it could be time based and expire after a minute or so.

What about data privacy?

We take privacy very seriously and we do not store either the webpage content you sent to us or outputted PDF. Not even in audit trails or exception logs. HTML is processed and sent back to you, and to be perfectly honest, storing all that html, css, images etc or worse, the resulting PDFs would quickly result in terrabytes of useless data that would cost us a lot of money so doesn't make any sense - we also do not have time to sift though tens of thousands of PDF's to find one with something interesting.. Please see our privacy policy for more details

Can I run this on my own private server or cluster?

Yes - we have sent the API source code to several companies, and we can also spin up a dedicated server, or server cluster just for you drop us a line.


See more frequently asked questions

Example Webpages Converted

Get Started
Please help us by spreading the word