Posted by & filed under HTML to PDF API, HTML to PDF conversion.

It’s a little known fact that our HTML to PDF API can also be used from the command line or the browser address bar directly. This may sound a little strange and geeky, but I assure you – it’s neither.

The reason behind this is that our API is based on sending a HTTP request with a certain set of parameters. And as you may know – sending a HTTP request can be done by typing a URL in the browser window. And in the Unix command line you can just use the WGET command. Before we look at some examples let’s answer the most basic of questions.

Why would I want to manually convert HTML to PDF?

Good question. You may think you can also just throw it in our online conversion service at the home page. While that works if you don’t want to pass any options, it will not take the defaults you have set in your members area nor will it accept any additional options. It’s a free service after all..

So if you want to use those defaults in the members area or if you want to pass the extra options that the API allows, you can quickly use the manual conversion option. You can use it to test if the parameters you’re passing in the code should do (so to test your code) or to quickly do a few manual conversions of documents that you need to have without using any code.

It’s basicly your cut and dry toolset for manual conversions and although we said it’s not geeky – it may be a little 😉

How do I manually convert a URL to PDF in the browser window?

Well this basicly couldn’t be easier. You just type in the URL with the right parameters!

So if your API key is ‘yourapikey’ and you want to convert ‘http://www.google.com’, you’ll throw the following in the browser address bar to get the PDF version of Google. By the way – of course you’ll first sign up to get your api key.

https://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com

And if you would like to add options for the conversion you just add them as parameters to the above. So if you want the PDF to be 400mm wide and 600mm high you’d make it:

http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com&width=400&height=600&unit=mm

An overview of all the options is available at the documentation page of our API.

How do I convert a URL to PDF from the command line?

Unix sports the wonderful WGET command and we can use this to convert HTML to PDF from the command line. So let’s take the examples that we used above again and see what they’ll look like.

To just convert google and save it in the file ‘google.pdf’ you’d use the following command:

wget -O google.pdf 'http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com'

Note that you’ll be using the -O option to indicate the filename and that you’re using quotes to escape the URL you’re calling.

And the other example of adding parameters would work as well. So if you want the PDF to be 400mm wide and 600mm high you’d make it:

wget -O google.pdf 'http://api.htm2pdf.co.uk/urltopdf?apikey=yourapikey&url=http://www.google.com&width=400&height=600&unit=mm'

Conclusion

Hopefully I made the point of how easy it is to use our API manually as well. If you want to know more about it – check out the documentation or just sign up for a monthly plan!

Leave a Reply

You must be logged in to post a comment.