How to Generate PDFs from Authenticated Pages
Learn how to generate PDFs from login-protected or authenticated pages during HTML to PDF conversion.
Overview
This guide explains how to use our HTML to PDF API to generate PDFs from pages that require Basic Authentication.
In general, we strongly recommend that if you are generating PDFs from URLs on your website that contain users' personal information, you secure them with Basic Authentication credentials so they are not publicly accessible.
Get started example
In this example, we will generate a PDF from a protected URL. The API first authenticates against the target page and then renders it as a PDF.
url: The URL of the page you want to convert.authentication: Authentication object that contains the following parameters.authentication.username: The username used to authenticate.authentication.password: The password used during authentication.
curl --request POST \
--url https://api.pdfgate.com/v1/generate/pdf \
--header 'Authorization: Bearer YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"url": "https://httpbin.org/basic-auth/user/passwd",
"authentication": {
"username": "user",
"password": "passwd"
}
}' \
-o output.pdf
Additional Notes
When converting authenticated pages, you must use the url parameter. Authentication parameters are not applied when converting raw HTML content.
If your application uses more complex authentication flows (such as session cookies, tokens, or SSO), you may need to use request headers instead.
For a full list of supported options, see the HTML to PDF API Reference.