Link Search Menu Expand Document

How to use GET request to call HTML to PDF and URL to PDF functions?

Yes, you can actually use GET request to call PDF.co API for HTML to PDF.

IMPORTANT: using GET request is not safe, because your data is passed as a part of link. Use it only there is no other way available. Recommended way is to use POST requests.

Example:

PDF.co endpoint: https://api.pdf.co/v1/pdf/convert/from/html

GET [https://api.pdf.co/v1/pdf/convert/from/html?apikey=INSERT_YOUR_PDFCO_API_KEY_HERE&templateId=1&name=newDocument.pdf&margins=40px%2020px%2020px%2020px&paperSize=Letter&orientation=Portrait&printBackground=true&templateData={%22invoice%22:{%22id%22:%2212345%22,%22date%22:%22August%2029,%202041%22,%22dateDue%22:%22September%2029,%202041%22},%22issuer%22:{%22name%22:%22Sarah%20Connor%22}}](https://api.pdf.co/v1/pdf/convert/from/html?apikey=INSERT_YOUR_PDFCO_API_KEY_HERE&templateId=1&name=newDocument.pdf&margins=40px%2020px%2020px%2020px&paperSize=Letter&orientation=Portrait&printBackground=true&templateData={%22invoice%22:{%22id%22:%2212345%22,%22date%22:%22August%2029,%202041%22,%22dateDue%22:%22September%2029,%202041%22},%22issuer%22:{%22name%22:%22Sarah%20Connor%22}})

This will return the following response:

{"url":"https://pdf-temp-files.s3.amazonaws.com/3323ea1b3cf44631a529a1a8eddcc49c/newDocument.pdf","pageCount":1,"error":false,"status":200,"name":"newDocument.pdf","remainingCredits":2409631,"credits":9}

Example 2

POST [https://api.pdf.co/v1/pdf/convert/from/html](https://api.pdf.co/v1/pdf/convert/from/html)
{
    "templateId": "1",
    "name": "newInvoice.pdf",
    "margins": "5px 5px 5px 5px",
    "paperSize": "Letter",
    "orientation": "Portrait",
    "printBackground": true,
    "header": "",
    "footer": "",
    "async": false,
    "encrypt": false,
    "templateData": "{\r\n        \"invoice\": {\r\n            \"id\": \"0021\",\r\n            \"date\": \"August 29, 2041\",\r\n            \"dateDue\": \"September 29, 2041\"\r\n        },\r\n        \"issuer\": {\r\n            \"name\": \"Sarah Connor\",\r\n            \"company\": \"T-800 Research Lab\",\r\n            \"address\": \"435 South La Fayette Park Place, Los Angeles, CA 90057\",\r\n            \"website\": \"www.example.com\",\r\n            \"email\": \"info@example.com\"\r\n        },\r\n        \"client\": {\r\n            \"name\": \"Cyberdyne Systems\",\r\n            \"company\": \"Cyberdyne Systems\",\r\n            \"address\": \"18144 El Camino Real, Sunnyvale, California\",\r\n            \"website\": \"www.example.com\",\r\n            \"email\": \"sales@example.com\"\r\n        },\r\n        \"items\": [\r\n            {\r\n                \"name\": \"T-800 Prototype Research\",\r\n                \"price\": \"$1000.00\"\r\n            },\r\n            {\r\n                \"name\": \"T-800 Cloud Sync Setup\",\r\n                \"price\": \"$300.00\"\r\n            },\r\n            {\r\n                \"name\": \"Skynet Domain Setup\",\r\n                \"price\": \"$50.00\"\r\n            },\r\n            {\r\n                \"name\": \"T-800 OS License\",\r\n                \"price\": \"$350.00\"\r\n            },\r\n            {\r\n                \"name\": \"T-800 Vision Testing\",\r\n                \"price\": \"$150.00\"\r\n            },\r\n        ],\r\n        \"discount\": \"$100.00%\",\r\n        \"tax\": \"$126.88 (7.5%)\",\r\n        \"total\": \"$1876.88\",\r\n        \"paid\": true,\r\n        \"note\": \"Thank you for your business with us.\",\r\n        \"primaryColor\": \"#E4135A\",\r\n        \"secondaryColor\": \"#00538B\",\r\n        \"textColor\": \"#3F4254\"\r\n    }"
}

Is equal to passing all information inside url params as the following (don’t forget to replace INSERT_YOUR_API_KEY_HERE with your PDF.co API key):

[https://api.pdf.co/v1/pdf/convert/from/html?apikey=INSERT_YOUR_API_KEY_HERE&templateId=1&name=newDocument.pdf&margins=40px](https://api.pdf.co/v1/pdf/convert/from/html?apikey=INSERT_YOUR_API_KEY_HERE&templateId=1&name=newDocument.pdf&margins=40px) 20px 20px 20px&paperSize=Letter&orientation=Portrait&printBackground=true&templateData={ "invoice": { "id": "12345", "date": "August 29, 2041", "dateDue": "September 29, 2041" }, "issuer": { "name": "Sarah Connor", "company": "T-800 Research Lab", "address": "435 South La Fayette Park Place, Los Angeles, CA 90057", "website": "www.example.com", "email": "info@example.com" }, "client": { "name": "Cyberdyne Systems", "company": "Cyberdyne Systems", "address": "18144 El Camino Real, Sunnyvale, California", "email": "sales@example.com" }, "items": [ { "name": "T-800 Prototype Research", "price": "$1000.00" }, { "name": "T-800 Cloud Sync Setup", "price": "$300.00" }, { "name": "Skynet Domain Setup", "price": "$50.00" }, { "name": "T-800 OS License", "price": "$350.00" }, { "name": "T-800 Vision Testing", "price": "$150.00" } ], "discount": "$100.00%25", "tax": "$126.88 (7.5%25)", "total": "$1,876.88", "paid": true, "note": "Thank you for your support of advanced robotics." }

We have to be careful when choosing this approach because using GET requests is unsafe and should be used only when no other ways are available. Also, it can lead to invalid URL or loss of information if certain characters are present in value of query string. For best results please use URL encoded characters for this. For example if query string value is $100%, use URL encoded value like $100%25.

Following table contains characters which should be URL encoded prior to passed as query string value.

CharacterURL Encoded Character
%%25
?%3F
&%26