|
1 | | -# Standalone export server |
| 1 | +# PDF export server |
2 | 2 |
|
3 | | -This package contains the sources for an executable service which builds PDF and PNG files out of HTML fragments. |
| 3 | +This repository contains sources for a server which builds PDF and PNG files out of HTML fragments. |
| 4 | +Server is designed to work with [Bryntum PDF Export feature](https://bryntum.com/products/grid/docs/api/Grid/feature/export/PdfExport). |
| 5 | +See compatibility table between Export server and other Bryntum products in this [table](docs/compatibility.md). |
4 | 6 |
|
| 7 | +Live demos available here: |
| 8 | +- [Gantt](https://bryntum.com/products/gantt/examples/export/) |
| 9 | +- [Scheduler](https://bryntum.com/products/scheduler/examples/export/) |
| 10 | +- [Grid](https://bryntum.com/products/grid/examples/export/) |
| 11 | + |
| 12 | +#### Features |
5 | 13 | - Uses headless chromium browser. |
6 | | -- Easy OS (Linux, Windows, Mac) independent build/install into binary or runnable as NodeJS instance. |
| 14 | +- Runnable as NodeJS instance. |
| 15 | +- Docker container available at [Docker Hub](https://hub.docker.com/r/bryntum/pdf-export-server) |
7 | 16 | - Written in JavaScript and fully adaptable. |
8 | | -- Can be used as standalone service or as an intermediary between your (C#, Java, PHP) frontend and backend. Just catch |
9 | | -the HTML fragments, call the service and serve the binary. |
10 | | - |
11 | | -## Compatibility |
12 | | - |
13 | | -| pdf-export-server | ExtScheduler/ExtGantt | Bryntum Grid/Scheduler/Gantt | |
14 | | -|---|---|---| |
15 | | -| 1.0.0 | * | * | |
| 17 | +- Can be used as standalone service or as an intermediary between your (C#, Java, PHP) frontend and backend. |
16 | 18 |
|
17 | | -## Usage |
| 19 | +## Getting started |
18 | 20 |
|
19 | | -To start PDF export server you only need to install packages and run a node command: |
| 21 | +### Using NodeJS |
20 | 22 |
|
| 23 | +1. Check out this repository |
| 24 | +```shell |
| 25 | +~$ git clone git@github.com:bryntum/pdf-export-server.git |
| 26 | +~$ cd pdf-export-server |
| 27 | +``` |
| 28 | +2. Install packages |
21 | 29 | ```shell |
22 | 30 | pdf-export-server$ npm i |
23 | | -pdf-export-server$ node ./src/server.js |
| 31 | +``` |
| 32 | +3. Start the server |
| 33 | +```shell |
| 34 | +pdf-export-server$ npm run start |
24 | 35 | Access-Control-Allow-Origin: * |
25 | 36 | Http server started on port 8080 |
26 | 37 | ``` |
27 | 38 |
|
28 | | -<a name="cli"></a> |
29 | | - |
30 | | -## Configuration |
| 39 | +Multiple configuration options are available as you can see in the [configuration](docs/configuration.md) guide. |
31 | 40 |
|
32 | | -You can specify application options in the app.config.js or by passing them from the CLI. |
33 | 41 |
|
34 | | -```shell |
35 | | -pdf-export-server$ node ./src/server.js --help |
36 | | - |
37 | | -Usage: ./server [OPTION] |
38 | | - |
39 | | - -h, --http=PORT Start http server on port |
40 | | - -H, --https=PORT Start https server on port |
41 | | - -c, --cors=HOST CORS origin, default value "*". Set to "false" to disable CORS |
42 | | - -m, --maximum=SIZE Maximum upload size (default 50mb) |
43 | | - -r, --resources=PATH The absolute path to the resource directory. This path will be accessible via the webserver |
44 | | - --max-workers=WORKERS Maximum amount of workers (puppeteer instances) (default: 5) |
45 | | - --level=LEVEL Specify log level (error, warn, verbose). Default "error" |
46 | | - --timeout=TIMEOUT Request timeout time in seconds |
47 | | - --quick Provide to only wait for page load event |
48 | | - --no-sandbox Provide to pass no-sandbox argument to chromium |
49 | | - --no-config Provide to ignore app.config.js |
50 | | - --verbose Alias for --level=verbose |
51 | | - --help Show help message |
52 | | -``` |
| 42 | +### Using image from Docker Hub |
53 | 43 |
|
54 | | -The following command starts a server with HTTP and HTTPS on ports 8080 and 8081 respectively: |
| 44 | +For your convenience we have pre-built container available on |
| 45 | +[Docker Hub](https://hub.docker.com/r/bryntum/pdf-export-server). |
55 | 46 |
|
| 47 | +1. Pull it |
56 | 48 | ```shell |
57 | | -pdf-export-server$ node ./src/server.js -h 8080 -H 8081 -m 100mb |
| 49 | +$ docker pull bryntum/pdf-export-server |
58 | 50 | ``` |
59 | | - |
60 | | -The flag -m above extends the upload capacity to 100 MB. |
61 | | - |
62 | | -##### Workers |
63 | | - |
64 | | -To speed up the export we parallelize it using puppeteer instances (workers). It is slower than using tabs, but much |
65 | | -easier to restart the export if browser or tab fails. By default, there are 5 workers which feel fine on machines with |
66 | | -as much as 1 GB RAM. In general, it takes about 2-3 seconds to generate one PDF page, depending on network speed and |
67 | | -overall system performance. Workers amount is not limited. |
68 | | - |
69 | | -##### Resources |
70 | | -<a name="CORS"></a> |
71 | | -When sending HTML fragments to the server, the server launches puppeteer and tries to generate PDF-files based on the |
72 | | -provided input. In case the CSS stylesheets are not accessible to the server (for example the resources are protected |
73 | | -by a login session), you can make use of the built-in web-server to serve resources. |
74 | | - |
75 | | -In this case configure the export feature with `translateURLsToAbsolute`. |
76 | | - |
77 | | -```javascript |
78 | | -new Grid({ |
79 | | - features : { |
80 | | - pdfExport : { |
81 | | - exportServer : 'http://export-host:8081', |
82 | | - translateURLsToAbsolute : 'http://export-host:8081/resources' |
83 | | - } |
84 | | - } |
85 | | -}) |
| 51 | +2. Create `docker-compose.yml` and configure image/port forwarding |
| 52 | +```yaml |
| 53 | +version: "3.9" |
| 54 | +services: |
| 55 | + web: |
| 56 | + image: "bryntum/pdf-export-server:1.0.1" |
| 57 | + ports: |
| 58 | + - "8080:8080" |
86 | 59 | ``` |
87 | | - |
88 | | -This tells the export plugin to change all the used stylesheet URLs to be fetched from |
89 | | -`http://export-host:8081/resources`. Then copy all the resources your application uses to the export server keeping the |
90 | | -folder hierarchy. After this map the virtual `http://export-host:8081/resources` to the real folder on your export |
91 | | -server: |
92 | | - |
| 60 | +3. Start container |
93 | 61 | ```shell |
94 | | -pdf-export-server$ node ./src/server.js -r /web/application/styles |
| 62 | +$ docker compose -f docker-compose.yml up |
95 | 63 | ``` |
96 | 64 |
|
97 | | -The path can be either absolute (`/web/application/styles`) or relative (`web/application/styles`), |
98 | | -for example when you start the export server with the export demo locally. |
99 | | - |
100 | | -So if you're running the export demo from the localhost, for example `http://lh/bryntum-suite/grid/examples/export/`, |
101 | | -you need to copy the folders starting from the `bryntum-suite` to the `examples/_shared/server/web/application/styles`, |
102 | | -keeping only resources the demo uses (css files, fonts etc.). |
103 | | - |
104 | | -##### Security |
105 | | - |
106 | | -Be careful which folder to set open with the -r option; php, aspx/cs, config files won't be interpreted but served as |
107 | | -download when hit. Only point folders which contain resources needed for generating the page, like fonts, CSS or image |
108 | | -files. |
109 | | - |
110 | 65 | ## Links |
111 | 66 | - [Architecture](docs/architecture.md) |
112 | 67 | - [Server protocol](docs/protocol.md) |
113 | 68 | - [Building executable](docs/building.md) |
114 | 69 | - [Docker](docs/docker.md) |
| 70 | +- [Compatibility table](docs/compatibility.md) |
| 71 | +- [Configuration options](docs/configuration.md) |
| 72 | +- [Troubleshooting](docs/troubleshooting.md) |
115 | 73 |
|
116 | 74 | ## FAQ |
117 | 75 |
|
118 | 76 | ### Exported PDF/PNG doesn't look correct |
119 | 77 |
|
120 | 78 | Most likely server couldn't get access to the resources. See [architecture](docs/architecture.md) guide for detailed |
121 | | -information or [resources section](#CORS) for short summary. |
| 79 | +information, [resources section](#CORS) for short summary and [troubleshooting](docs/troubleshooting.md) guide for |
| 80 | +debugging tips. |
| 81 | + |
| 82 | +### PDF/PNG file is not generated |
| 83 | + |
| 84 | +Most likely there is a problem on the server, see [troubleshooting](docs/troubleshooting.md) guide for help. |
122 | 85 |
|
123 | 86 | ### Cannot export using HTTPS |
124 | 87 |
|
|
0 commit comments