Based on Playwright, convert HTML content to PDF via API.
Send GET request on /api/convert
, like https://myserver.com/api/convert?html=<h1>Hello</h1>
.
Support POST request on /api/convert
with body data.
Server will return url where document is available, example : https://myserver.com/public/pdf/02132102983-533083.pdf
.
Documents are deleted after 1 hour.
HTML template, ie: <h1>Hello</h1>
Customize top margin for html content only, header/footer templates are not affected.
Can be number : px
or string : px
, in
, cm
, mm
Same as marginTop option
Same as marginTop option
Same as marginTop option
HTML template, ie: <div style="margin-left: 20px">header</div>
.
Be careful :
- Header template is not affected by content margin, so you have to specify it inside your HTML.
- Image
src
tag in header template must be a Base64, it can't be ahttp(s)://
link (see issue) - Header template is kinda "zoomed in", so you may have to lower font-sizes/widths/heights/margins/paddings values (ie: font-size: 11px -> font-size: 8px) (see issue)
Add tag with following classes to put content inside :
- date : formatted print date
- title : document title
- url : document location
- pageNumber : current page number
- totalPages : total pages in the document
Example :
<div class="date"></div>
<p><span class="pageNumber"></span>/<span class="totalPages"></span></p>
Same as headerTemplate option
CSS rules
Specify PDF orientation, by default it is portrait.
You can set at landscape with 'true'
value.
Paper width, accepts values labeled with units.
Can be number : px
or string : px
, in
, cm
, mm
Paper height, accepts values labeled with units.
Can be number : px
or string : px
, in
, cm
, mm
Paper format. If set, takes priority over width or height options. Defaults to 'Letter'.
Values :
Letter
(8.5in x 11in)Legal
(8.5in x 14in)Tabloid
(11in x 17in)Ledger
(17in x 11in)A0
(33.1in x 46.8in)A1
(23.4in x 33.1in)A2
(16.54in x 23.4in)A3
(11.7in x 16.54in)A4
(8.27in x 11.7in)A5
(5.83in x 8.27in)A6
(4.13in x 5.83in)
Specify your own filename. PDF with same filenames will be overwritten. By default, it will be a unique generated name.
- Docker and docker-compose must be installed
- Docker Environment file
.env
must be present to project's root - Node configuration file
config.ts
must be present intoapp/config
folder
docker-compose down
docker-compose build
docker-compose up
- Node.js must be installed
- Docker Environment file
.env
must be present to project's root - Node configuration file
config.ts
must be present intoapp/config
folder
cd app
npm i
cd app
tsc && node app.js