PDF from URL (URL to PDF)
Description: Create PDF from URL. POST
request.
Status Errors
Code | Description |
---|---|
200 | The request has succeeded |
400 | bad input parameters |
401 | unauthorized |
403 | not enough credits |
405 | Timeout 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:
url
required. Link to input HTML file or website page to be converted. You can pass link to file from Google Drive, Dropbox or another online file service that can generate shareable links. You can also use built-in PDF.co cloud storage located at https://app.pdf.co/files or upload your file as temporary file right before making this API call (seeUpload and Manage Files
section for more details on uploading files via API).async
optional. Set totrue
to run as async job in background (recommended for heavy documents).name
optional. File name for generated output. Must be a String.expiration
optional. Output link expiration in minutes. Default is60
(i.e. 60 minutes or 1 hour). After this delay generated output file(s) (if any) will be auto-removed from PDF.co temporary files storage. Max allowed expiration period depends on your current subscription plan. To store permanent input files (e.g. re-usable images, pdf, documents), please use PDF.co built-in Files Storage instead.margins
optional. set to css style margins like10px
,5mm
,5in
for all sides or5px 5px 5px 5px
(the order of margins istop
,right
,bottom
,left
).paperSize
optional.Letter
is set by default. Can beLetter
,Legal
,Tabloid
,Ledger
,A0
,A1
,A2
,A3
,A4
,A5
,A6
or a custom size. Custom size can be set inpx
(pixels),mm
orin
(inches) with width and height separated by space like this:200 300
,200px 300px
,200mm 300mm
,20cm 30cm
or6in 8in
.orientation
optional. set toPortrait
orLandscape
.Portrait
by default.printBackground
optional.true
by default. Set tofalse
to disable printing of background.mediaType
optional. Usesprint
by default. Set toscreen
to convert HTML as it appears in a browser orprint
to convert as it appears for printing ornone
to setnone
as mediaType for css styles.DoNotWaitFullLoad
optional.false
by default. Set totrue
to skip waiting for full load (like full video load etc that may affect the total conversion time).header
optional. Set to HTML for header to be applied on every page at the header.footer
optional. Set to HTML for 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,
"encrypt": 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>"
}
```* `async` optional. Runs processing asynchronously. Returns `JobId` that you may use with `/job/check` to check state of the background job (possible states: `working`, `failed`, `aborted` and `success`). Must be one of: `true`, `false`.
- `profiles` optional. Must be a Strings containing JSON profile. You can set additional and extra options using this parameter that allows you to set custom configuration. See [profiles samples](https://apidocs.pdf.co/profiles) for examples.
* **Method:** POST
* **URL:** /v1/pdf/convert/from/url
### Query parameters
*No query parameters accepted.*
### Body payload
```json
{
"url": "https://wikipedia.org/wiki/Wikipedia:Contact_us",
"margins": "5mm",
"paperSize": "Letter",
"orientation": "Portrait",
"printBackground": true,
"header": "",
"footer": "",
"mediaType": "print",
"async": false,
"encrypt": false,
"profiles": "{ \"CustomScript\": \";; // put some custom js script here \"}"
}
Example responses
/pdf/convert/from/url (with header and footer)
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,
"encrypt": false,
"profiles": "{ \"CustomScript\": \";; // put some custom js script here \"}"
}'
Samples
- AWS Lambda - Convert Web Page To PDF From Link (Node.js)
- C# - Convert Web Page To PDF From Link
- C# - Convert Web Page To PDF From Link Asynchronously
- Java - Convert Web Page To PDF From Link
- JavaScript - Convert Web Page To PDF From Link (Node.js)
- JavaScript - Convert Web Page To PDF From Link (Node.js) - Async API
- PHP - Convert Web Page To PDF From Link
- PHP - Convert Web Page To PDF From Link Asynchronously
- PowerShell - Convert Web Page To PDF From Link
- PowerShell - Convert Web Page To PDF From Link Asynchronously
- Python - Convert Web Page To PDF From Link
- Python - Convert Web Page To PDF From Link Asynchronously
- VB.NET - Convert Web Page To PDF From URL
- VB.NET - Convert Web Page To PDF From URL Asynchronously
Copyright © 2016 - 2023 PDF.co