Skip to content

Commit 865a439

Browse files
committed
-
1 parent 0e5fb1e commit 865a439

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Grump
3+
Copyright (c) 2023 GrumpSolutions
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
# Template renderer
22

3-
A combination of three remarkable open source projects makes it easy to create PDF documents from HTML templates. With only a few lines of code Puppeteer and mustache.js can be combined to create PDF's from HTML. This is demonstrated in template-renderer.js. Paged.js can be used to create documents with a table of contents and page numbers. This is demonstrated in tests/pagedjs/pagedjs.html.
4-
5-
Creating PDF's is a common task in software development. This repository shows a free and open source alternative to commercial packages like Aspose.Pdf or Exstream.
6-
7-
## Security
8-
9-
Some remarks concerning security.
10-
11-
- Ensure user input is validated.
12-
- Ensure the npm packages and docker image are up to date.
13-
- Only allow access from trusted services. This is often achieved using json web tokens. Thanks to the package [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) this was easily implemented in template-renderer.js.
14-
- For serving over https see <https://expressjs.com/en/5x/api.html#app.listen> and <https://nodejs.org/api/https.html#httpscreateserveroptions-requestlistener>.
3+
Creating PDF documents is a common task in software development. This repository shows how to create PDF's from HTML templates with the help of three remarkable open source projects. It shows a free and open source alternative to commercial software like Aspose.Pdf or Exstream.
154

165
## General information
176

@@ -24,10 +13,8 @@ License: See project, Apache License 2.0 at time of writing
2413

2514
### mustache.js
2615

27-
An open source javascript library to render mustache templates.\
28-
<https://github.com/janl/mustache.js>\
29-
<https://mustache.github.io>\
30-
License: See project, MIT License at time of writeing
16+
An open source javascript library to render mustache templates. The [mustache template syntax](https://github.com/janl/mustache.js#templates) is explained in the [mustache.js github repository](https://github.com/janl/mustache.js#templates). The mustache template engine is [widely available](https://mustache.github.io).\
17+
License: See project, MIT License at time of writing
3118

3219
### Paged.js
3320

@@ -38,6 +25,11 @@ An open source library to paginate HTML content for printing to PDF. This librar
3825
<https://www.adamhyde.net/some-pagedjs-info>\
3926
License: See project, MIT license at time of writing
4027

28+
### Implementation
29+
30+
- template-renderer.js - Combines Puppeteer and mustache.js with just a few lines to create PDF's from mustache HTML templates.
31+
- tests/pagedjs/pagedjs.html - Uses Paged.js to create a document with a table of contents and page numbers.
32+
4133
### Typesetting with CSS
4234

4335
Browsers provide some interesting options for typesetting. For example the following CSS styles.
@@ -51,26 +43,36 @@ Browsers provide some interesting options for typesetting. For example the follo
5143

5244
**Note:** It seems that Puppeteer does not yet handle hyphens correctly. Two possible workarrounds are [hyphen](https://www.npmjs.com/package/hyphen) (node) and [Hyphenopoly](https://github.com/mnater/Hyphenopoly) (browser).
5345

46+
## Security
47+
48+
Some remarks concerning security.
49+
50+
- Ensure user input is validated.
51+
- Ensure the npm packages and docker image are up to date.
52+
- Only allow access from trusted services. This is often achieved using json web tokens. Thanks to the package [jsonwebtoken](https://github.com/auth0/node-jsonwebtoken) this was easily implemented in template-renderer.js.
53+
- For serving over https see <https://expressjs.com/en/5x/api.html#app.listen> and <https://nodejs.org/api/https.html#httpscreateserveroptions-requestlistener>.
54+
55+
5456
## Getting started
5557

5658
### Npm commands
5759

58-
See package.json for some scripts to run, build and test template-renderer.js and some example templates.
60+
See package.json for scripts to run, build and test template-renderer.js and some example templates.
5961

60-
- Run `npm run generate-keys jwt` to create a private and public key used by template-renderer.js for validating JWT's.
62+
- Run `npm run generate-keys jwt` to create a private and public key. The public key is used by template-renderer.js for validating JWT's.
6163
- Run `npm run start:test` to serve template-renderer.js on port 5000 and a HTML test page on port 5021. See tests directory for some templates which can be used for testing.
6264

6365
### Docker image
6466

65-
See <https://pptr.dev/guides/docker> and <https://github.com/puppeteer/puppeteer/tree/main/docker> for more information.
67+
A Dockerfile is included in this is repository. See <https://pptr.dev/guides/docker> and <https://github.com/puppeteer/puppeteer/tree/main/docker> for more information.
6668

6769
### Some example templates
6870

6971
- tests/a4-pages.html
70-
- tests/email.html
71-
- tests/image.html
72+
- tests/email
73+
- tests/image
7274
- tests/mustache.html
73-
- tests/pagedjs.html
75+
- tests/pagedjs
7476

7577
### Validating JWKS tokens
7678

@@ -110,23 +112,23 @@ _For local testing -_ Extra self-signed certificate(s) can be provided with a no
110112
111113
## Packages
112114
113-
- Puppeteer: library providing control to Chrome or Chromium
114-
- mustache.js: library to render mustache templates
115-
- Paged.js: library to paginate HTML content for printing to PDF
116-
- winston: a simple logging library with support for multiple transports
117-
- jsonwebtoken: an implementation of JSON Web Tokens use for signing and verifying JWT's
118-
- jwks-rsa: a library to retrieve signing keys from a JWKS endpoint
115+
- Puppeteer - library providing control to Chrome or Chromium
116+
- mustache.js - library to render mustache templates
117+
- Paged.js - library to paginate HTML content for printing to PDF
118+
- winston - a simple logging library with support for multiple transports
119+
- jsonwebtoken - an implementation of JSON Web Tokens used for signing and verifying JWT's
120+
- jwks-rsa - a library to retrieve signing keys from a JWKS endpoint
119121
120122
### Packages for testing
121123
122-
- axios: node package for http requests
123-
- http-server: serve files to test HTML locally
124-
- json5: for parsing json written by hand
125-
- juice: inline web resources (styles, scripts, images)
126-
- nodemon: run script and restart when changed
127-
- npm-run-all: run multiple npm scripts with one command
128-
- web-resource-inliner: inline web resources without any changes (preserves all Paged.js styles)
124+
- axios - node package for http requests
125+
- http-server - serve files locally for testing
126+
- json5 - for parsing json written by hand
127+
- juice - inline web resources (styles, scripts, images)
128+
- nodemon - run script and restart when changed
129+
- npm-run-all - run multiple npm scripts with one command
130+
- web-resource-inliner - inline web resources without any changes (preserves all Paged.js styles)
129131
130132
### Package for formatting
131133
132-
- prettier: opinionated code formatter (run with `npx prettier . --check` or `npx prettier . --write`)
134+
- prettier - opinionated code formatter (run with `npx prettier . --check` or `npx prettier . --write`)

0 commit comments

Comments
 (0)