Documentation

Authentication

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.

Note that your "apiKey" is private information, so don't expose it publicly!

A simple example could be like this:

https://api.html2pdf.app/v1/generate?html=https://example.com&apiKey={your-api-key}

Parameters

Note that parameters should be URL encoded when sending a GET request.
ParameterTypeDescriptionDefault
htmlstringHTML code or website URL you want to generaterequired
apiKeystringYour api key which you will get after registration, and can find in a dashboardrequired
callBackUrlstringGenerates 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
statestringThis is custom parameter provided by the user which will be sent to the callBackUrl when document is generated.null
landscapebooleanActivates landscape modefalse
formatstringFormat of the document, can have one of values:
Letter, Legal, Tabloid, Ledger, A0, A1, A2, A3, A4, A5, A6
A4
widthintegerCustom width of the pdf size (use in conjunction with height parameter)null
heightintegerCustom height of the pdf size (use in conjunction with width parameter)null
marginTop
marginRight
marginBottom
marginLeft
integerEmpty spaces between the outer and the beginning of the content (integer value which is equal to pixels)0
filenamestringFilename header will be returnednull
waitForintegerParameter 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
mediastringUse value to generate pdf using print mode styles, can have one of values: print, screenscreen
scalenumberDefines the scale of the pdf document content. Scale range is from 0.1 to 21
headerTemp
footerTemp
stringParameter to provide header / footer of the page. HTML code should be provided and used in conjunction with marginTop / marginBottom to be visiblenull

Fonts

We support fonts listed bellow.

As an alternative way, you can use any font you want using Google fonts or Web fonts.
Andale MonoComic Sans MSNotoSansVerdana
ArialCourier NewNotoSerifWebdings
Arial BlackGeorgiaTahoma 
Arial NarrowImpactTimes New Roman 
Arial UnicodeMicrosoft Sans SerifTrebuchet MS 

Page breaks

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>

Encryption

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.

We support AES encryption with 128 bits key to protect your PDF documents.

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."

 

ParameterTypeDescriptionDefault
userPasswordstringThe password that you want users to use for opening the PDF.null
ownerPasswordstringThe 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
permissionsarray
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 request example

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"]
}'