LogoDOCS
OverviewAuthenticationRate LimitsErrors
Logo
Sign in →

Generate PDF

The Generate PDF endpoint converts HTML content into a PDF document. You can provide the content either as a publicly accessible URL or as raw HTML in the request body.

By default, the endpoint returns the generated PDF as a binary file. If you prefer a JSON response, you can include the jsonResponse field in your request.

Request Body
htmlstringrequired if url field is not provided
urlstringrequired if html field is not provided
jsonResponseboolean

Default: false

Returns JSON response instead of file stream.

preSignedUrlExpiresInnumber

Minimum: 60 seconds

Maximum: 86400 seconds (24 hours)

Use this to control temporary authorized access to files. After this duration, the URL automatically expires and can no longer be used to download the PDF. The value must be provided in seconds.

If you need to generate a new pre-signed URL for an existing document, use the Get Document endpoint.

pageSizeTypestring

Default: ledger

Acceptable values:
a0a1a2a3a4a5a6ledgertabloidlegalletter
widthnumber

Custom PDF file width in pixels (px). It needs to be defined with the height field.

heightnumber

Custom PDF file height in pixels (px). It needs to be defined with the width field.

orientationstring

Default: portrait

Acceptable values:
portraitlandscape
headerstring
footerstring
marginobject
timeoutnumber

Default: 900000 - (15 minutes)

Maximum wait time (in milliseconds) to render the HTML content. The default and maximum value is 900000 ms (15 minutes). Use this parameter to stop the rendering process earlier if needed.

javascriptstring
cssstring
emulateMediaTypestring

Sets the CSS media type of the document.

Acceptable values:
screenprint
waitForSelectorstring

Waits for specific CSS selector to be loaded. It will timeout in 30 seconds.

clickSelectorstring

Waits and then clicks a specific CSS selector.

clickSelectorChainSetupobject

Provides advanced control for handling cookie banners, consent dialogs, pop-ups, and multi-step UI interactions before capturing the PDF.

When it is defined, the clickSelector field is ignored.

Value example
1"clickSelectorChainSetup": {2  "ignoreFailingChains": true,3  "chains": [4    { "selectors": ["#cookieDialog"] },5    { "selectors": [".popupClose"] },6  ]7}
waitForNetworkIdleboolean

Waits until there are no more network connections in the document.

delaynumber

Adds a delay in milliseconds before processing the HTML content into a PDF. This can be useful when asynchronous content needs extra time to render. The maximum value you can set is 20 seconds (20000 in ms).

loadImagesboolean

Waits for all images to finish loading before generating the PDF.

scalenumber

Default: 1

Sets the page scale factor when generating the PDF. Accepts values between 0.1 and 2.

pageRangesstring

Defines the page range to include in the PDF. Accepts formats like "1-5" or "1,3,5". If not specified, all pages are included.

printBackgroundboolean

Default: true

Includes background graphics in the PDF when set to true. If false, backgrounds are omitted and only main content is rendered.

userAgentstring

Set your own user agent string to control how the page content is served.

httpHeadersobject

Sets custom HTTP headers.

authenticationobject

Page authentication allows you to render pages that are protected by HTTP authentication.

It is supported only when rendering a URL and cannot be used with HTML content.

See the authenticated pages guide for a full example.

viewportobject

Page viewport allows you to control the visible area of the page before it is rendered.

enableFormFieldsboolean

If enabled, the generated PDF will include interactive form fields (e.g., text inputs, checkboxes) that users can fill out directly in PDF viewers.

Supported HTML tags

input[type='text']input[type='checkbox']textareaselectinput[type='email']input[type='number']input[type='datetime-local']input[type='date']input[type='time']input[type='radio']input[type='tel']

For digital signature field we support the following custom HTML tag

<pdfgate-signature-field />
Detailed documentation Generated PDF example
metadataobject

Sets custom data to your document record.

POST/v1/generate/pdf
CURL
NODE.JS
PYTHON
GO
PHP
JAVA
C#
RUBY
1curl \2  -H "Content-Type: application/json" \3  -H "Authorization: Bearer YOUR_API_KEY" \4  --request POST \5  --data '{"pageSizeType":"a4","url":"https://en.wikipedia.org/wiki/PDF"}' \6  https://api.pdfgate.com/v1/generate/pdf \7  -o output.pdf
File stream response
1File stream
JSON response - Document object
1{2  "id" : "6642381c5c61",3  "status" : "completed",4  "type" : "from_html",5  "fileUrl" : "https://api.pdfgate.com/file/open/:preSignedUrlToken",6  "size" : 1620006,7  "createdAt" : "2024-02-13T15:56:12.607Z"8}