Authentication is done by simply passing apiKey parameter to the request, using GET or POST method. You will get the apiKey parameter to your email after the registration.
A simple example could be like this:
https://api.html2pdf.app/v1/generate?html=https://example.com&apiKey={your-api-key}
Parameter | Type | Description | Default |
---|---|---|---|
html | string | HTML code or website URL you want to generate | required |
apiKey | string | Your api key which you will get after registration, and can find in a dashboard | required |
callBackUrl | string | Generates document in a background and sends result in your callback url. We will send generated pdf document (encoded with base64) to your provided callback url in this structure: {"document": "..."} | null |
state | string | This is custom parameter provided by the user which will be sent to the callBackUrl when document is generated. | null |
landscape | boolean | Activates landscape mode | false |
format | string | Format of the document, can have one of values:Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6 | A4 |
width | integer | Custom width of the pdf size (use in conjunction with height parameter) | null |
height | integer | Custom height of the pdf size (use in conjunction with width parameter) | null |
marginTop marginRight marginBottom marginLeft | integer | Empty spaces between the outer and the beginning of the content (integer value which is equal to pixels) | 0 |
filename | string | Filename header will be returned | null |
waitFor | integer | Parameter to wait for some time (in seconds) before generate the pdf document. It is useful if you have some javascript code running in the background after page was loaded. Available values from 0 to 10 . | 0 |
media | string | Use value to generate pdf using print mode styles, can have one of values: print , screen | screen |
scale | number | Defines the scale of the pdf document content. Scale range is from 0.1 to 2 | 1 |
headerTemplate footerTemplate | string | Parameter to provide header / footer of the page. HTML code should be provided and used in conjunction with marginTop / marginBottom to be visible | null |
We support fonts listed bellow.
Andale Mono | Comic Sans MS | NotoSans | Verdana |
Arial | Courier New | NotoSerif | Webdings |
Arial Black | Georgia | Tahoma | |
Arial Narrow | Impact | Times New Roman | |
Arial Unicode | Microsoft Sans Serif | Trebuchet MS |
A HTML code example if you want to force a page break at a certain point in an HTML document:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Paginated HTML</title>
<style>
div.page {
page-break-after: always;
page-break-inside: avoid;
}
</style>
<head>
<body>
<div class="page">
<h1>This is Page 1</h1>
</div>
<div class="page">
<h1>This is Page 2</h1>
</div>
<div class="page">
<h1>This is Page 3</h1>
</div>
</body>
</html>
When encrypting a PDF document, you can provide a userPassword
and an ownerPassword
. The user password is used to restrict certain operations like viewing, printing, copying, and modifying the PDF. The owner password grants full access to the document, including the ability to change permissions and encryption settings.
To trigger encryption process parameter userPassword
needs to be set. By default, the value of the permissions
parameter is set to "print", which means that users who enter the password will only be allowed to print the document."
Parameter | Type | Description | Default |
---|---|---|---|
userPassword | string | The password that you want users to use for opening the PDF. | null |
ownerPassword | string | The owner password grants the ability to perform all actions and also allows for the modification of permissions. Providing non empty ownerPassword determines that this file has such limitations. | null |
permissions | array | Field controlling what actions a user entering userPassword can perform. print - allow printing.modify - allow template creation, signing, filling form fields.copy - allow content copying and copying for accessibility.edit - allow commenting.fillform - allow filling of form fields.extract - allow content copying for accessibility.assemble - allow assembling the document. rotate, insert, delete pages, bookmarks and thumbnails.printbest - allow high resolution printing when 'print' is allowed. | ["print"] |
curl --output example.pdf --request POST \
--url https://api.html2pdf.app/v1/generate \
--header 'Content-Type: application/json' \
--data '{
"apiKey": "f117a90d3a0864645264f700b79161d5da8cb...",
"html": "https://example.com",
"userPassword": "user",
"ownerPassword": "owner",
"permissions": ["print", "modify", "copy"]
}'