Web page to PDF API

Web page to PDF API

Convert any web page URL to PDF.
Free Plan $0.00 Monthly Subscribe
6 Requests / Monthly
Free for Lifetime
No Credit Card Required
MOST POPULAR
Starter Plan $9.99 Monthly Subscribe
500 Requests / Monthly
Standard Support
Simple and fast
Easy on budget
Able to fetch full page
Timeout is customizable
Pro Plan $19.99 Monthly Subscribe
3,000 Requests / Monthly
Standard Support
Simple and fast
Easy on budget
Able to fetch full page
Timeout is customizable
Custom Plan Volume Monthly Contact Us
Any requests volume you need
Simple and fast
Easy on budget
Able to fetch full page
Timeout is customizable

Renders the provided URL and prints it as a PDF file as it should be displayed in a Google Chrome browser.

This API has two modes.

Print Mode

This mode is triggered with print=true (default)parameter. When print is set to true, the PDF file will be generated by browser's print functionality and the elements in the resulting PDF will be vectors and texts will be selectable.

When in printing mode, you can also define grayscale=true in order to get images in grayscale.

The PDF will be printed on A4 pagesize by default. If you need larger pages such as A3, B4 or simply Letter or B5 just set it such as passing the pagesize=B4 parameter

Sometimes you have HTTP Realm authentications that requires username and passwords to reach the URLs. You can set them such as username=john&password=secret

A sample request with cURL is below:

curl --request GET \
--url 'https://api.apilayer.com/url_to_pdf?url=google.com&grayscale=true&pagesize=B4' \
--header 'apikey: YOUR API KEY'

Screenshot Mode

Some web pages are just not optimized for printers. So the result may be flaky. You may have no choice but to take a screenshot and then convert it to PDF. You can achieve this functionality by simply setting the print parameter to false.

When print=false, the API fetches the provided URL and takes a screenshot as it is displayed on an actual Chrome browser and then serves the output as a PDF file. The browser has a screen resolution of 1400x1080 pixels, so the output is sharp and clean.

The PDF will contain full page screenshots. It will scroll automatically and take a full height screenshot of your web page. (max height: 10.000 pixels)

You can also customize the wait time (in seconds) for taking a screenshot with the timeout parameter. Just pass timeout=5 or any value you desire for your needs. (max timeout value is 15 seconds)

We use up to date Up to date Chrome browsers to make pixel perfect screenshots and ensure support for all modern web features.

A sample cURL request to trigger screensot mode is below:

curl --request GET \
--url 'https://api.apilayer.com/url_to_pdf?url=google.com&print=false' \
--header 'apikey: YOUR API KEY'

Web page to PDF API Reference

This API is organized around REST. Our API has predictable resource-oriented URLs, accepts form-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.

Just Getting Started?

Check out our development quickstart guide.

Authentication

Web page to PDF API uses API keys to authenticate requests. You can view and manage your API keys in the Accounts page.

Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.

All requests made to the API must hold a custom HTTP header named "apikey". Implementation differs with each programming language. Below are some samples.

All API requests must be made over HTTPS. Calls made over plain HTTP will fail. API requests without authentication will also fail.

Endpoints

Takes a screenshot of a url and saves it as a PDF file

Parameters

url (required)

URL to fetch

Location: Query, Data Type: string

grayscale (optional)

If set to true, PDF will be grayscaled (defaults to false). Valid if print=true.

Location: Query, Data Type: string

pages (optional)

Comma seperated list of pages to print (starts with 1)

Location: Query, Data Type: string

pagesize (optional)

Pagesize for the PDF (defaults to A4). Valid if print=true, otherwise PDF width will be 1420 pixels and height is equal to the length of the page.

Location: Query, Data Type: string

password (optional)

If page is protected by HTTP realm, you can set the password here. Valid if print=true.

Location: Query, Data Type: string

print (optional)

Should the PDF generated by printing? (true/false). Defaults to true. If set to false it will take a screenshot and then convert to PDF. If you need pixel perfect output then set print=false.

Location: Query, Data Type: string

timeout (optional)

How many seconds shall we wait to take a screenshot. Valid if only print=false

Location: Query, Data Type: string

username (optional)

If page is protected by HTTP realm, you can set the username here. Valid if print=true.

Location: Query, Data Type: string

zoom (optional)

Zoom factor to apply to output. Defaults to 1.0. Valid only if print=true

Location: Query, Data Type: float

** A word enclosed with curly brackets "{ }" in the code means that it is a parameter and it should be replaced with your own values when executing. (also overwriting the curly brackets).
Returns

Below is a sample response from the endpoint


If you wish to play around interactively with real values and run code, see...

Rate Limiting

Each subscription has its own rate limit. When you become a member, you start by choosing a rate limit that suits your usage needs. Do not worry; You can upgrade or downgrade your plan at any time. For this reason, instead of starting with a larger plan that you do not need, we can offer you to upgrade your plan after you start with "free" or "gold plan" options and start using the API.

When you reach a rate limit (both daily and monthly), the service will stop responding and returning the HTTP 429 response status code (Too many requests) for each request with the following JSON string body text.

{
"message":"You have exceeded your daily\/monthly API rate limit. Please review and upgrade your subscription plan at https:\/\/apilayer.com\/subscriptions to continue."
}

A reminder email will be sent to you when your API usage reaches both 80% and 90%, so that you can take immediate actions such as upgrading your plan in order to prevent your application using the API from being interrupted.

You can also programmatically check your rate limit yourself. As a result of each request made to the APILayer, the following 4 fields provide you with all the necessary information within the HTTP Headers.

x-ratelimit-limit-month: Request limit per month
x-ratelimit-remaining-month: Request limit remaining this month
x-ratelimit-limit-day: Request limit per day
x-ratelimit-remaining-day: Request limit remaining today

You can contact our support unit if you need any assistance with your application regarding to handle the returned result by looking at the header information.

Error Codes

APILayer uses standard HTTP response codes to indicate the success or failure of an API request. In general: Codes in the 2xx range indicate success. Codes in the 4xx range indicate a clientside error, which means that failed given the information provided (e.g., a missing parameter, unauthorized access etc.). Codes in the 5xx range indicate an error with APILayer's servers (normally this should'nt happen at all).

If the response code is not 200, it means the operation failed somehow and you may need to take an action accordingly. You can check the response (which will be in JSON format) for a field called 'message' that briefly explains the error reported.

Status Code Explanation
400 - Bad Request The request was unacceptable, often due to missing a required parameter.
401 - Unauthorized No valid API key provided.
404 - Not Found The requested resource doesn't exist.
429 - Too many requests API request limit exceeded. See section Rate Limiting for more info.
5xx - Server Error We have failed to process your request. (You can contact us anytime)

You can always contact for support and ask for more assistance. We'll be glad to assist you with building your product.