Convert HTML to PDF with cURL

We've made some easy to follow examples that show you how to use the PDFmyURL converter API with cURL on the command line. They will show you how to convert a URL to PDF on the command line or (if you prefer) raw HTML to PDF. These examples should be pretty much copy/paste, but if you find you need more help - please send us an email.

Example for cURL URL to PDF conversion

Our HTML to PDF API is very easy to use. It takes a license and either a URL or raw HTML as input and returns a PDF.

In this examples we'll use a URL and then in the next one we'll do the same for raw HTML. For URLs the API basically works by sending a request similar to this to our converter service, which converts http://www.example.com to PDF:

https://pdfmyurl.com/api?license=yourlicensekey&url=http://www.example.com

You can use a lot of additional parameters in the API call, which give you access to all the features for conversion. These are all specified in the API conversion documentation.

Here we're converting the example URL to PDF and storing it in a file called "result.pdf".

curl 	-d "license=yourlicensekey" \
	--data-urlencode "url=https://www.example.com" \
	-o result.pdf \
	-H "Content-Type: application/x-www-form-urlencoded" \
	-X POST https://pdfmyurl.com/api

Example for cURL HTML to PDF conversion

If you want to convert HTML to PDF with cURL then our API takes a license and the raw HTML as input and returns a PDF.

It basically works by sending a request similar to this to our converter service, which converts the text Hello (in bold) to PDF:

https://pdfmyurl.com/api?license=yourlicensekey&html=%3Cb%3EHello%3C%2Fb%3E

Note that we URL encoded the HTML so that it is passed correctly to our service. This is actually better for all parameters, but most parameters wouldn't normally contain special characters that make this important.

Here we're converting the example HTML to PDF and storing it in a file called "result.pdf".

curl 	-d "license=yourlicensekey" \
	--data-urlencode "html=<b>Hello</b>" \
	-o result.pdf \
	-H "Content-Type: application/x-www-form-urlencoded" \
	-X POST https://pdfmyurl.com/api

You can also read the HTML from a file instead if you like. In that way you don't have to change the cURL command and can just change the contents of the file.

Let's assume you are putting the raw HTML in a file named "html.html". You'd then use the following cURL command.

curl 	-d "license=yourlicensekey" \
	--data-urlencode html@html.html \
	-o result.pdf \
	-H "Content-Type: application/x-www-form-urlencoded" \
	-X POST https://pdfmyurl.com/api

These cURL examples should get you right on your way to convert URL to PDF or HTML to PDF with our converter API!

As explained earlier, you can use a lot of additional parameters in the API call and these are all specified in the API documentation.

If you'd like to see more cURL examples then please contact us about this.