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.
Below is a tutorial video that shows two of the examples you'll find further down the page.
You can easily use cURL to convert webpages to PDF with our HTML to PDF API. It takes a license and either a URL or raw HTML as input and returns a PDF.
In this example we'll use a URL and then in the next one we'll do the same for raw HTML. For URL to PDF conversion you would send the following request, which converts http://www.example.com to PDF:
So let's look at what this looks like when you use cURL. With the following cURL command we're converting the URL https://www.example.com 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
Here's an explanation of the cURL parameters we use (for a complete overview see the official cURL manual):
You can use additional parameters in the API call by just adding more lines like --data-urlencode "parameter=value" \. This lets you use all our conversion options. These are all specified in the API conversion documentation.
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:
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 firstname.lastname@example.org \ -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.
Fun Fact Did you know that cURL is usually just pronounced as "curl"? Although this resource says that there are also people out there pronouncing it as the individual letters C, U, R and L. We thought you'd like to know!
If you'd like to see more cURL examples then please contact us about this.
For business use