Link Search Menu Expand Document

PDF from URL (URL to PDF)

Explore Samples

Description: Create PDF from URL. POST request.

Status Errors

CodeDescription
200The request has succeeded
400bad input parameters
401unauthorized
403not enough credits
405Timeout error. To process large documents or files please use asynchronous mode ( set async parameter to true) and then check the status using /job/check endpoint. If a file contains many pages then specify a page range using pages parameter. The number of pages of the document can be obtained using the endpoint /pdf/info

Available Methods

[POST] /pdf/convert/from/url

Generate PDF from URL or link to HTML page. You can set the following parameters:

Attributes
url required
URL to the source file. Supports links from Google Drive, Dropbox, and PDF.co built-in files storage. To upload files via API, Check out the Files Upload section.

Note: If you experience intermittent Too Many Requests or Access Denied errors, please try to add cache: to enable built-in URL caching. (e.g cache:https://example.com/file1.pdf)

For data security, you have the option to encrypt output files and decrypt input files. Learn more about user-controlled data encryption.
async optional
Set async to true for long processes to run in the background, API will then return a jobId which you can use with /job/check endpoint to check the status of the process and retrieve the output while you can proceed with other tasks without waiting for this process to finish.
name optional
File name for the generated output, The input must be in string format.
expiration optional
Set the expiration time for the output link in minutes (default is 60 i.e 60 minutes or 1 hour), After this specified duration, any generated output file(s) will be automatically deleted from PDF.co temporary files storage. The maximum duration for link expiration varies based on your current subscription plan. Learn more

To store permanent input files (e.g. re-usable images, pdf templates, documents), Consider using PDF.co built-in Files Storage.
margins optional
Set to CSS style margins like 10px, 5mm, 5in for all sides or 5px 5px 5px 5px (the order of margins is top, right, bottom, left).
paperSize optional
Letter is set by default. Can be Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6 or a custom size. Custom size can be set in px (pixels), mm or in (inches) with width and height separated by space like this: 200 300, 200px 300px, 200mm 300mm, 20cm 30cm or 6in 8in.
orientation optional
Set to Portrait or Landscape. Portrait by default.
printBackground optional
true by default. Set to false to disable printing of background.
mediaType optional
Uses print by default. Set to screen to convert HTML as it appears in a browser or print to convert as it appears for printing or none to set none as mediaType for CSS styles.
DoNotWaitFullLoad optional
false by default. Set to true to skip waiting for full load (like full video load etc that may affect the total conversion time).
profiles optional
Use this parameter to set additional configurations for fine-tuning and extra options, The input must be in string format. Explore PDF.co knowledgebase for profile examples.
header optional
Set to HTML for the header to be applied on every page at the header.
footer optional
Set to HTML for the footer to be applied on every page at the bottom.

The header and footer params should contain valid HTML markup with the following classes used to inject printing values into them:

date: formatted print date title: document title url: document location pageNumber: current page number totalPages: total pages in the document

For example, the following markup will generate Page N of NN page numbering:

<span style='font-size:10px'>Page <span class='pageNumber'></span> of <span class='totalPages'></span>.</span>

Sample URL To PDF with advanced header and footer. Note that the top and bottom page margins are important because page content may overlap the footer or header.

{
 "url": "https://wikipedia.org",
  "async": false,
  
  "name": "result.pdf",
  "margins": "40px 5px 40px 5px",
  "paperSize": "Letter",
  "orientation": "Portrait",
  "printBackground": true,
  "header": "<div style='width:100%'><span style='font-size:10px;margin-left:20px;width:50%;float:left'>LEFT SUBHEADER</span><span style='font-size:8px;width:30%;float:right'>RIGHT SUBHEADER</span></div>",
  "footer": "<div style='width:100%;text-align:right'><span style='font-size:10px;margin-right:20px'>Page <span class='pageNumber'></span> of <span class='totalPages'></span>.</span></div>"
}
  • Method: POST
  • URL: /v1/pdf/convert/from/url

Query parameters

No query parameters accepted.

Body payload

{
    "url": "https://wikipedia.org/wiki/Wikipedia:Contact_us",
    "margins": "5mm",
    "paperSize": "Letter",
    "orientation": "Portrait",
    "printBackground": true,
    "header": "",
    "footer": "",
    "mediaType": "print",
    "async": false,
    "profiles": "{ \"CustomScript\": \";; // put some custom js script here \"}"
}

Example responses

Code Snippet

CURL
curl --location --request POST 'https://api.pdf.co/v1/pdf/convert/from/url' \
--header 'x-api-key: ' \
--header 'Content-Type: application/json' \
--data-raw '{
    "url": "https://wikipedia.org/wiki/Wikipedia:Contact_us",
    "margins": "5mm",
    "paperSize": "Letter",
    "orientation": "Portrait",
    "printBackground": true,
    "header": "",
    "footer": "",
    "mediaType": "print",
    "async": false,
    "profiles": "{ \"CustomScript\": \";; // put some custom js script here \"}"
}'

Samples