URL to PDF API Reference
Convert any URL into a printable, high quality PDF document rendered by a real browser.
Service details and pricing: URL to PDF API
Request example
Query the endpoint via an HTTPS POST request (replace YOUR_API_KEY_HERE with your API key):
curl -X POST "https://api.apivoid.com/v2/url-to-pdf" \
-H "Content-Type: application/json" \
-H "X-API-Key: YOUR_API_KEY_HERE" \
-d '{"url": "https://apple.com/"}'The same request in PHP:
$url = 'https://apple.com/';
$apiKey = 'YOUR_API_KEY_HERE';
$curl = curl_init('https://api.apivoid.com/v2/url-to-pdf');
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json', 'X-API-Key: ' . $apiKey]);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode(['url' => $url]));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($httpCode === 200) {
$responseData = json_decode($response, true);
print_r($responseData);
// Save the "base64_file" data as PDF file
if (isset($responseData['rendered_file']['base64_file'])) {
$saveAs = __DIR__ . '/document.pdf';
file_put_contents($saveAs, base64_decode($responseData['rendered_file']['base64_file']));
if (file_exists($saveAs)) {
echo '<p>File document.pdf saved successfully!</p>';
} else {
echo '<p>Failed to create document.pdf file.</p>';
}
}
} else {
print_r('An error occurred: '.$response);
}Request parameters
Required
URL to submit, e.g. https://apple.com/.
⚠ Government and educational domains are blocked.
Optional
viewport_widthintegerDefault: 1920
Browser viewport width in pixels (max 5000).
viewport_heightintegerDefault: 1080
Browser viewport height in pixels (max 10000).
user_agentstringDefault: desktop
Can be desktop (default, a random desktop user agent) or mobile.
accept_languagestringDefault: en-US
Change the Accept-Language HTTP header, format like en-US.
delayintegerDefault: 0
Wait N seconds (max 10) before converting the URL to PDF.
basic_auth_usernamestring
Set username for Basic Authentication.
basic_auth_passwordstring
Set password for Basic Authentication.
authorization_bearerstring
Set the authorization bearer token.
custom_headerstring
A custom header, e.g. X-key: 690d1f9e-5a53-45ad-997d-a23143a0d068.
disable_jsbooleanDefault: false
Disable JavaScript.
disable_popupsbooleanDefault: true
Disable alerts, cookie consents and confirmation dialogs.
disable_imagesbooleanDefault: false
Disable loading of images.
disable_adsbooleanDefault: true
Disable advertisements.
emulate_mediastringDefault: screen
Emulate a media type, can be screen or print.
pdf_papersize_widthintegerDefault: 0
Change PDF paper width in pixels (max 5000).
pdf_papersize_heightintegerDefault: 0
Change PDF paper height in pixels (max 10000).
pdf_formatstringDefault: A4
Change PDF format, can be Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6.
pdf_marginintegerDefault: 0
Change PDF margin.
pdf_show_backgroundbooleanDefault: true
Show the background of the web page.
pdf_landscapebooleanDefault: false
Change the PDF orientation to landscape.
pdf_page_rangesstring
Select page ranges, can be 1 or 1-3 (for example).
pdf_scalefloat
Scale the PDF, must be between 0.1 and 2.
pdf_one_pagebooleanDefault: false
Try to fit the web page into a single PDF page.
Response example
A successful request returns HTTP 200 with a JSON body:
{
"url": "https://apple.com/",
"rendered_file": {
"format": "PDF",
"date_time_utc": "2024-11-29 19:00:32",
"base64_file": "JVBERi0xLjcKJeLjz9MKMSAwIG9iago8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFI+PgplbmRvYmoKMiAwIG9iago8PC9UICQUERBLEgWLA37KKoEbFrrKiINbH3rlhQsWHABhqxgQiKCg...",
"file_size_readable": "344.53 KB",
"file_size_bytes": 352795
},
"http_response": {
"final_url": "https://www.apple.com/",
"status_code": 200,
"content_type": "text/html",
"page_content_empty": false,
"ip": "69.192.160.210"
},
"html_info": {
"title": "Apple",
"description": "Discover the innovative world of Apple and shop everything iPhone, iPad, Apple Watch, Mac, and Apple TV, plus explore accessories, entertainment, and expert device support.",
"og_image": "https://www.apple.com/ac/structured-data/images/open_graph_logo.png?202110180743",
"icon": "",
"og_site_name": "Apple",
"ld_organization": "Apple",
"canonical": "https://www.apple.com/",
"robots": "",
"twitter_site": "",
"lang": "en-US"
},
"elapsed_ms": 5763
}Response fields
The fields returned in the JSON response:
urlstring
URL submitted for the PDF rendering.
rendered_file → formatstring
Format of the rendered file, e.g. PDF.
rendered_file → date_time_utcstring
Date and time (UTC) of when the file was rendered.
rendered_file → base64_filestring
The rendered PDF file encoded in base64.
rendered_file → file_size_readablestring
File size in human-readable format, e.g. 344.53 KB.
rendered_file → file_size_bytesinteger
File size in bytes.
http_response → final_urlstring
Final URL after following redirects.
http_response → status_codeinteger
HTTP status code returned by the server.
http_response → content_typestring
Content type of the page, e.g. text/html.
http_response → page_content_emptyboolean
Returns true if the page content is empty.
http_response → ipstring
IP address of the server that served the page.
html_info → titlestring
Title of the page.
html_info → descriptionstring
Meta description of the page.
html_info → og_imagestring
Open Graph image URL of the page.
html_info → iconstring
Favicon URL of the page.
html_info → og_site_namestring
Open Graph site name of the page.
html_info → ld_organizationstring
Organization name found in JSON-LD structured data.
html_info → canonicalstring
Canonical URL of the page.
html_info → robotsstring
Robots meta tag of the page.
html_info → twitter_sitestring
Twitter site handle of the page.
html_info → langstring
Language declared by the page, e.g. en-US.
elapsed_msinteger
Time taken to process the request, in milliseconds.