chromiumly 2.5.1 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -35
- package/dist/chromium/converters/converter.d.ts +1 -1
- package/dist/chromium/converters/converter.js +1 -1
- package/dist/chromium/converters/converter.js.map +1 -1
- package/dist/chromium/converters/html.converter.d.ts +13 -4
- package/dist/chromium/converters/html.converter.js +9 -2
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/dist/chromium/converters/markdown.converter.d.ts +9 -4
- package/dist/chromium/converters/markdown.converter.js +7 -3
- package/dist/chromium/converters/markdown.converter.js.map +1 -1
- package/dist/chromium/converters/url.converter.d.ts +9 -4
- package/dist/chromium/converters/url.converter.js +6 -2
- package/dist/chromium/converters/url.converter.js.map +1 -1
- package/dist/chromium/index.d.ts +3 -3
- package/dist/chromium/index.js.map +1 -1
- package/dist/chromium/interfaces/common.types.d.ts +13 -0
- package/dist/chromium/interfaces/common.types.js +3 -0
- package/dist/chromium/interfaces/common.types.js.map +1 -0
- package/dist/chromium/interfaces/converter.types.d.ts +4 -10
- package/dist/chromium/utils/converter.utils.d.ts +2 -12
- package/dist/chromium/utils/converter.utils.js +36 -50
- package/dist/chromium/utils/converter.utils.js.map +1 -1
- package/dist/common/gotenberg.utils.d.ts +11 -1
- package/dist/common/gotenberg.utils.js +25 -2
- package/dist/common/gotenberg.utils.js.map +1 -1
- package/dist/common/index.d.ts +3 -3
- package/dist/common/index.js.map +1 -1
- package/dist/common/types.d.ts +1 -1
- package/dist/gotenberg.js +4 -3
- package/dist/gotenberg.js.map +1 -1
- package/dist/libre-office/index.d.ts +2 -2
- package/dist/libre-office/index.js.map +1 -1
- package/dist/libre-office/utils/constants.js +80 -76
- package/dist/libre-office/utils/constants.js.map +1 -1
- package/dist/libre-office/utils/libre-office.utils.d.ts +3 -3
- package/dist/libre-office/utils/libre-office.utils.js +5 -5
- package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
- package/dist/main.config.d.ts +1 -1
- package/dist/main.config.js +6 -6
- package/dist/main.config.js.map +1 -1
- package/dist/main.d.ts +3 -3
- package/dist/main.js.map +1 -1
- package/dist/pdf-engines/index.d.ts +1 -1
- package/dist/pdf-engines/index.js.map +1 -1
- package/dist/pdf-engines/pdf.engine.d.ts +3 -3
- package/dist/pdf-engines/pdf.engine.js +5 -5
- package/dist/pdf-engines/pdf.engine.js.map +1 -1
- package/dist/pdf-engines/utils/engine.utils.d.ts +2 -2
- package/dist/pdf-engines/utils/engine.utils.js +3 -3
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
- package/package.json +25 -17
- package/src/.prettierrc.yml +4 -0
- package/src/chromium/converters/converter.ts +2 -2
- package/src/chromium/converters/html.converter.ts +40 -24
- package/src/chromium/converters/markdown.converter.ts +32 -26
- package/src/chromium/converters/tests/html.converter.test.ts +111 -68
- package/src/chromium/converters/tests/markdown.converter.test.ts +102 -77
- package/src/chromium/converters/tests/url.converter.test.ts +90 -66
- package/src/chromium/converters/url.converter.ts +31 -25
- package/src/chromium/index.ts +3 -3
- package/src/chromium/interfaces/common.types.ts +15 -0
- package/src/chromium/interfaces/converter.types.ts +4 -12
- package/src/chromium/utils/converter.utils.ts +67 -60
- package/src/chromium/utils/tests/converter.utils.test.ts +237 -167
- package/src/common/constants.ts +3 -3
- package/src/common/gotenberg.utils.ts +39 -8
- package/src/common/index.ts +3 -3
- package/src/common/tests/gotenberg.utils.test.ts +38 -31
- package/src/common/types.ts +2 -2
- package/src/gotenberg.ts +9 -9
- package/src/libre-office/index.ts +2 -2
- package/src/libre-office/utils/constants.ts +80 -76
- package/src/libre-office/utils/libre-office.utils.ts +21 -18
- package/src/libre-office/utils/tests/libre-office.utils.test.ts +58 -49
- package/src/main.config.ts +13 -13
- package/src/main.ts +3 -3
- package/src/pdf-engines/index.ts +1 -1
- package/src/pdf-engines/pdf.engine.ts +23 -19
- package/src/pdf-engines/tests/pdf.engine.test.ts +52 -49
- package/src/pdf-engines/utils/engine.utils.ts +12 -9
- package/src/pdf-engines/utils/tests/engine.utils.test.ts +23 -23
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ so.
|
|
|
33
33
|
After that, you can start a default Docker container of [Gotenberg](https://gotenberg.dev/) as follows:
|
|
34
34
|
|
|
35
35
|
```bash
|
|
36
|
-
docker run --rm -p 3000:3000 gotenberg/gotenberg:
|
|
36
|
+
docker run --rm -p 3000:3000 gotenberg/gotenberg:8
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
## Get Started
|
|
@@ -75,11 +75,11 @@ a `url` to a `buffer` which contains the converted PDF file content.
|
|
|
75
75
|
#### URL
|
|
76
76
|
|
|
77
77
|
```typescript
|
|
78
|
-
import {UrlConverter} from "chromiumly";
|
|
78
|
+
import { UrlConverter } from "chromiumly";
|
|
79
79
|
|
|
80
80
|
const urlConverter = new UrlConverter();
|
|
81
81
|
const buffer = await urlConverter.convert({
|
|
82
|
-
|
|
82
|
+
url: "https://www.example.com/",
|
|
83
83
|
});
|
|
84
84
|
```
|
|
85
85
|
|
|
@@ -88,13 +88,12 @@ const buffer = await urlConverter.convert({
|
|
|
88
88
|
The only requirement is that the file name should be `index.html`.
|
|
89
89
|
|
|
90
90
|
```typescript
|
|
91
|
-
import {HtmlConverter} from "chromiumly";
|
|
91
|
+
import { HtmlConverter } from "chromiumly";
|
|
92
92
|
|
|
93
93
|
const htmlConverter = new HtmlConverter();
|
|
94
94
|
const buffer = await htmlConverter.convert({
|
|
95
|
-
|
|
95
|
+
html: "path/to/index.html",
|
|
96
96
|
});
|
|
97
|
-
|
|
98
97
|
```
|
|
99
98
|
|
|
100
99
|
#### Markdown
|
|
@@ -102,12 +101,12 @@ const buffer = await htmlConverter.convert({
|
|
|
102
101
|
This route accepts an `index.html` file plus a markdown file.
|
|
103
102
|
|
|
104
103
|
```typescript
|
|
105
|
-
import {MarkdownConverter} from "chromiumly";
|
|
104
|
+
import { MarkdownConverter } from "chromiumly";
|
|
106
105
|
|
|
107
106
|
const markdownConverter = new MarkdownConverter();
|
|
108
107
|
const buffer = await markdownConverter.convert({
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
html: "path/to/index.html",
|
|
109
|
+
markdown: "path/to/file.md",
|
|
111
110
|
});
|
|
112
111
|
```
|
|
113
112
|
|
|
@@ -118,22 +117,43 @@ file will look like.
|
|
|
118
117
|
|
|
119
118
|
```typescript
|
|
120
119
|
type PageProperties = {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
120
|
+
singlePage?: boolean; // Print the entire content in one single page (default false)
|
|
121
|
+
size?: {
|
|
122
|
+
width: number; // Paper width, in inches (default 8.5)
|
|
123
|
+
height: number; //Paper height, in inches (default 11)
|
|
124
|
+
};
|
|
125
|
+
margins?: {
|
|
126
|
+
top: number; // Top margin, in inches (default 0.39)
|
|
127
|
+
bottom: number; // Bottom margin, in inches (default 0.39)
|
|
128
|
+
left: number; // Left margin, in inches (default 0.39)
|
|
129
|
+
right: number; // Right margin, in inches (default 0.39)
|
|
130
|
+
};
|
|
131
|
+
preferCssPageSize?: boolean; // Define whether to prefer page size as defined by CSS (default false)
|
|
132
|
+
printBackground?: boolean; // Print the background graphics (default false)
|
|
133
|
+
omitBackground?: boolean; // Hide the default white background and allow generating PDFs with transparency (default false)
|
|
134
|
+
landscape?: boolean; // Set the paper orientation to landscape (default false)
|
|
135
|
+
scale?: number; // The scale of the page rendering (default 1.0)
|
|
136
|
+
nativePageRanges?: { from: number; to: number }; // Page ranges to print
|
|
137
|
+
};
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
In addition to the `PageProperties` customization options, the `convert()` method also accepts a set of parameters to further enhance the versatility of the conversion process. Here's an overview of the full list of parameters:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
type ConversionOptions = {
|
|
144
|
+
properties?: PageProperties; // Customize the appearance of the generated PDF
|
|
145
|
+
pdfFormat?: PdfFormat; // Define the PDF format for the conversion
|
|
146
|
+
pdfUA?: boolean; // Enable PDF for Universal Access for optimal accessibility (default false)
|
|
147
|
+
userAgent?: string; // Customize the user agent string sent during conversion
|
|
148
|
+
header?: PathLikeOrReadStream; // Specify a custom header for the PDF
|
|
149
|
+
footer?: PathLikeOrReadStream; // Specify a custom footer for the PDF
|
|
150
|
+
emulatedMediaType?: EmulatedMediaType; // Specify the emulated media type for conversion
|
|
151
|
+
waitDelay?: string; // Duration (e.g., '5s') to wait when loading an HTML document before conversion
|
|
152
|
+
waitForExpression?: string; // JavaScript expression to wait before converting an HTML document into PDF
|
|
153
|
+
extraHttpHeaders?: Record<string, string>; // Include additional HTTP headers in the request
|
|
154
|
+
failOnHttpStatusCodes?: number[]; // List of HTTP status codes triggering a 409 Conflict response (default [499, 599])
|
|
155
|
+
failOnConsoleExceptions?: boolean; // Return a 409 Conflict response if there are exceptions in the Chromium console (default false)
|
|
156
|
+
skipNetworkIdleEvent?: boolean; // Do not wait for Chromium network to be idle (default false)
|
|
137
157
|
};
|
|
138
158
|
```
|
|
139
159
|
|
|
@@ -150,10 +170,10 @@ documents to PDF files. You can find the file extensions
|
|
|
150
170
|
accepted [here](https://gotenberg.dev/docs/modules/libreoffice#route).
|
|
151
171
|
|
|
152
172
|
```typescript
|
|
153
|
-
import {PDFEngine} from "chromiumly";
|
|
173
|
+
import { PDFEngine } from "chromiumly";
|
|
154
174
|
|
|
155
175
|
const buffer = await PDFEngine.convert({
|
|
156
|
-
|
|
176
|
+
files: ["path/to/file.docx", "path/to/file.png"],
|
|
157
177
|
});
|
|
158
178
|
```
|
|
159
179
|
|
|
@@ -171,10 +191,10 @@ as: [PDFtk](https://gitlab.com/pdftk-java/pdftk), [PDFcpu](https://github.com/pd
|
|
|
171
191
|
and [UNO](https://github.com/unoconv/unoconv).
|
|
172
192
|
|
|
173
193
|
```typescript
|
|
174
|
-
import {PDFEngine} from "chromiumly";
|
|
194
|
+
import { PDFEngine } from "chromiumly";
|
|
175
195
|
|
|
176
196
|
const buffer = await PDFEngine.merge({
|
|
177
|
-
|
|
197
|
+
files: ["path/to/file.docx", "path/to/file.png"],
|
|
178
198
|
});
|
|
179
199
|
```
|
|
180
200
|
|
|
@@ -190,15 +210,15 @@ Please note that all the PDF files can be found `__generated__` folder in the ro
|
|
|
190
210
|
The following is a short snippet of how to use the library.
|
|
191
211
|
|
|
192
212
|
```typescript
|
|
193
|
-
import {PDFEngine, UrlConverter} from "chromiumly";
|
|
213
|
+
import { PDFEngine, UrlConverter } from "chromiumly";
|
|
194
214
|
|
|
195
215
|
async function run() {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
216
|
+
const urlConverter = new UrlConverter();
|
|
217
|
+
const buffer = await urlConverter.convert({
|
|
218
|
+
url: "https://gotenberg.dev/",
|
|
219
|
+
});
|
|
200
220
|
|
|
201
|
-
|
|
221
|
+
await PDFEngine.generate("gotenberg.pdf", buffer);
|
|
202
222
|
}
|
|
203
223
|
|
|
204
224
|
run();
|
|
@@ -14,7 +14,7 @@ class Converter {
|
|
|
14
14
|
* @param {ChromiumRoute} route - The ChromiumRoute enum value representing the conversion route.
|
|
15
15
|
*/
|
|
16
16
|
constructor(route) {
|
|
17
|
-
this.endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.
|
|
17
|
+
this.endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.CHROMIUM_CONVERT_PATH}/${main_config_1.Chromiumly.CHROMIUM_ROUTES[route]}`;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.Converter = Converter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/converter.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/converter.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAE9D;;;GAGG;AACH,MAAsB,SAAS;IAM3B;;;;;OAKG;IACH,YAAY,KAAoB;QAC5B,IAAI,CAAC,QAAQ,GAAG,GAAG,wBAAU,CAAC,kBAAkB,IAAI,wBAAU,CAAC,qBAAqB,IAAI,wBAAU,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;IAChI,CAAC;CACJ;AAfD,8BAeC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { PathLikeOrReadStream, PdfFormat } from
|
|
3
|
-
import {
|
|
4
|
-
import { Converter } from
|
|
2
|
+
import { PathLikeOrReadStream, PdfFormat } from '../../common';
|
|
3
|
+
import { PageProperties } from '../interfaces/converter.types';
|
|
4
|
+
import { Converter } from './converter';
|
|
5
|
+
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
5
6
|
/**
|
|
6
7
|
* Class representing an HTML converter that extends the base Converter class.
|
|
7
8
|
* This class is used to convert HTML content to PDF using Gotenberg service.
|
|
@@ -29,11 +30,17 @@ export declare class HtmlConverter extends Converter {
|
|
|
29
30
|
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
|
|
30
31
|
* @param {string} [options.userAgent] - User agent string to use during the conversion.
|
|
31
32
|
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
|
|
33
|
+
* @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
32
34
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
35
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
33
36
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
34
37
|
*/
|
|
35
|
-
convert({ html, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnConsoleExceptions, }: {
|
|
38
|
+
convert({ html, assets, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent }: {
|
|
36
39
|
html: PathLikeOrReadStream;
|
|
40
|
+
assets?: {
|
|
41
|
+
file: PathLikeOrReadStream;
|
|
42
|
+
name: string;
|
|
43
|
+
}[];
|
|
37
44
|
header?: PathLikeOrReadStream;
|
|
38
45
|
footer?: PathLikeOrReadStream;
|
|
39
46
|
properties?: PageProperties;
|
|
@@ -44,6 +51,8 @@ export declare class HtmlConverter extends Converter {
|
|
|
44
51
|
waitForExpression?: string;
|
|
45
52
|
userAgent?: string;
|
|
46
53
|
extraHttpHeaders?: Record<string, string>;
|
|
54
|
+
failOnHttpStatusCodes?: number[];
|
|
47
55
|
failOnConsoleExceptions?: boolean;
|
|
56
|
+
skipNetworkIdleEvent?: boolean;
|
|
48
57
|
}): Promise<Buffer>;
|
|
49
58
|
}
|
|
@@ -36,13 +36,18 @@ class HtmlConverter extends converter_1.Converter {
|
|
|
36
36
|
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
|
|
37
37
|
* @param {string} [options.userAgent] - User agent string to use during the conversion.
|
|
38
38
|
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
|
|
39
|
+
* @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
39
40
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
41
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
40
42
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
41
43
|
*/
|
|
42
|
-
convert({ html, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnConsoleExceptions, }) {
|
|
44
|
+
convert({ html, assets, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent }) {
|
|
43
45
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
44
46
|
const data = new form_data_1.default();
|
|
45
|
-
yield
|
|
47
|
+
yield common_1.GotenbergUtils.addFile(data, html, 'index.html');
|
|
48
|
+
if (assets === null || assets === void 0 ? void 0 : assets.length) {
|
|
49
|
+
yield Promise.all(assets.map(({ file, name }) => common_1.GotenbergUtils.addFile(data, file, name)));
|
|
50
|
+
}
|
|
46
51
|
yield converter_utils_1.ConverterUtils.customize(data, {
|
|
47
52
|
header,
|
|
48
53
|
footer,
|
|
@@ -54,7 +59,9 @@ class HtmlConverter extends converter_1.Converter {
|
|
|
54
59
|
waitForExpression,
|
|
55
60
|
userAgent,
|
|
56
61
|
extraHttpHeaders,
|
|
62
|
+
failOnHttpStatusCodes,
|
|
57
63
|
failOnConsoleExceptions,
|
|
64
|
+
skipNetworkIdleEvent
|
|
58
65
|
});
|
|
59
66
|
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
60
67
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"html.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/html.converter.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,
|
|
1
|
+
{"version":3,"file":"html.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/html.converter.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,yCAA+E;AAE/E,8DAA0D;AAC1D,2CAAwC;AACxC,mDAAkD;AAGlD;;;;;GAKG;AACH,MAAa,aAAc,SAAQ,qBAAS;IACxC;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACG,OAAO,CAAC,EACV,IAAI,EACJ,MAAM,EACN,MAAM,EACN,MAAM,EACN,UAAU,EACV,SAAS,EACT,KAAK,EACL,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EAiBvB;;YACG,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,MAAM,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;YAEvD,IAAI,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE,CAAC;gBACjB,MAAM,OAAO,CAAC,GAAG,CACb,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAC1B,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAC3C,CACJ,CAAC;YACN,CAAC;YAED,MAAM,gCAAc,CAAC,SAAS,CAAC,IAAI,EAAE;gBACjC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,SAAS;gBACT,KAAK;gBACL,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,SAAS;gBACT,gBAAgB;gBAChB,qBAAqB;gBACrB,uBAAuB;gBACvB,oBAAoB;aACvB,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AA5FD,sCA4FC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { PdfFormat, PathLikeOrReadStream } from
|
|
3
|
-
import {
|
|
4
|
-
import { Converter } from
|
|
2
|
+
import { PdfFormat, PathLikeOrReadStream } from '../../common';
|
|
3
|
+
import { PageProperties } from '../interfaces/converter.types';
|
|
4
|
+
import { Converter } from './converter';
|
|
5
|
+
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
5
6
|
/**
|
|
6
7
|
* Class representing a Markdown converter that extends the base Converter class.
|
|
7
8
|
* This class is used to convert HTML with markdown content to PDF using Gotenberg service.
|
|
@@ -30,10 +31,12 @@ export declare class MarkdownConverter extends Converter {
|
|
|
30
31
|
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
|
|
31
32
|
* @param {string} [options.userAgent] - User agent string to use during the conversion.
|
|
32
33
|
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
|
|
34
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
33
35
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
36
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
34
37
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
35
38
|
*/
|
|
36
|
-
convert({ html, markdown, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnConsoleExceptions, }: {
|
|
39
|
+
convert({ html, markdown, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent }: {
|
|
37
40
|
html: PathLikeOrReadStream;
|
|
38
41
|
markdown: PathLikeOrReadStream;
|
|
39
42
|
header?: PathLikeOrReadStream;
|
|
@@ -46,6 +49,8 @@ export declare class MarkdownConverter extends Converter {
|
|
|
46
49
|
waitForExpression?: string;
|
|
47
50
|
userAgent?: string;
|
|
48
51
|
extraHttpHeaders?: Record<string, string>;
|
|
52
|
+
failOnHttpStatusCodes?: number[];
|
|
49
53
|
failOnConsoleExceptions?: boolean;
|
|
54
|
+
skipNetworkIdleEvent?: boolean;
|
|
50
55
|
}): Promise<Buffer>;
|
|
51
56
|
}
|
|
@@ -37,14 +37,16 @@ class MarkdownConverter extends converter_1.Converter {
|
|
|
37
37
|
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
|
|
38
38
|
* @param {string} [options.userAgent] - User agent string to use during the conversion.
|
|
39
39
|
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
|
|
40
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
40
41
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
42
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
41
43
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
42
44
|
*/
|
|
43
|
-
convert({ html, markdown, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnConsoleExceptions, }) {
|
|
45
|
+
convert({ html, markdown, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent }) {
|
|
44
46
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
47
|
const data = new form_data_1.default();
|
|
46
|
-
yield
|
|
47
|
-
yield
|
|
48
|
+
yield common_1.GotenbergUtils.addFile(data, html, 'index.html');
|
|
49
|
+
yield common_1.GotenbergUtils.addFile(data, markdown, 'file.md');
|
|
48
50
|
yield converter_utils_1.ConverterUtils.customize(data, {
|
|
49
51
|
header,
|
|
50
52
|
footer,
|
|
@@ -56,7 +58,9 @@ class MarkdownConverter extends converter_1.Converter {
|
|
|
56
58
|
waitForExpression,
|
|
57
59
|
userAgent,
|
|
58
60
|
extraHttpHeaders,
|
|
61
|
+
failOnHttpStatusCodes,
|
|
59
62
|
failOnConsoleExceptions,
|
|
63
|
+
skipNetworkIdleEvent
|
|
60
64
|
});
|
|
61
65
|
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
62
66
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/markdown.converter.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,
|
|
1
|
+
{"version":3,"file":"markdown.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/markdown.converter.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,yCAA+E;AAE/E,8DAA0D;AAC1D,2CAAwC;AACxC,mDAAkD;AAGlD;;;;;GAKG;AACH,MAAa,iBAAkB,SAAQ,qBAAS;IAC5C;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,OAAO,CAAC,EACV,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,MAAM,EACN,UAAU,EACV,SAAS,EACT,KAAK,EACL,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EAiBvB;;YACG,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,MAAM,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;YAEvD,MAAM,uBAAc,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;YAExD,MAAM,gCAAc,CAAC,SAAS,CAAC,IAAI,EAAE;gBACjC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,SAAS;gBACT,KAAK;gBACL,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,SAAS;gBACT,gBAAgB;gBAChB,qBAAqB;gBACrB,uBAAuB;gBACvB,oBAAoB;aACvB,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AAvFD,8CAuFC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { PdfFormat, PathLikeOrReadStream } from
|
|
3
|
-
import {
|
|
4
|
-
import { Converter } from
|
|
2
|
+
import { PdfFormat, PathLikeOrReadStream } from '../../common';
|
|
3
|
+
import { PageProperties } from '../interfaces/converter.types';
|
|
4
|
+
import { Converter } from './converter';
|
|
5
|
+
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
5
6
|
/**
|
|
6
7
|
* Class representing a URL converter that extends the base Converter class.
|
|
7
8
|
* This class is used to convert content from a URL to PDF using Gotenberg service.
|
|
@@ -29,10 +30,12 @@ export declare class UrlConverter extends Converter {
|
|
|
29
30
|
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
|
|
30
31
|
* @param {string} [options.userAgent] - User agent string to use during the conversion.
|
|
31
32
|
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
|
|
33
|
+
* @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
32
34
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
35
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
33
36
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
34
37
|
*/
|
|
35
|
-
convert({ url, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnConsoleExceptions, }: {
|
|
38
|
+
convert({ url, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent }: {
|
|
36
39
|
url: string;
|
|
37
40
|
header?: PathLikeOrReadStream;
|
|
38
41
|
footer?: PathLikeOrReadStream;
|
|
@@ -44,6 +47,8 @@ export declare class UrlConverter extends Converter {
|
|
|
44
47
|
waitForExpression?: string;
|
|
45
48
|
userAgent?: string;
|
|
46
49
|
extraHttpHeaders?: Record<string, string>;
|
|
50
|
+
failOnHttpStatusCodes?: number[];
|
|
47
51
|
failOnConsoleExceptions?: boolean;
|
|
52
|
+
skipNetworkIdleEvent?: boolean;
|
|
48
53
|
}): Promise<Buffer>;
|
|
49
54
|
}
|
|
@@ -37,14 +37,16 @@ class UrlConverter extends converter_1.Converter {
|
|
|
37
37
|
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
|
|
38
38
|
* @param {string} [options.userAgent] - User agent string to use during the conversion.
|
|
39
39
|
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
|
|
40
|
+
* @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
40
41
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
42
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
41
43
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
42
44
|
*/
|
|
43
|
-
convert({ url, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnConsoleExceptions, }) {
|
|
45
|
+
convert({ url, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent }) {
|
|
44
46
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
47
|
const _url = new url_1.URL(url);
|
|
46
48
|
const data = new form_data_1.default();
|
|
47
|
-
data.append(
|
|
49
|
+
data.append('url', _url.href);
|
|
48
50
|
yield converter_utils_1.ConverterUtils.customize(data, {
|
|
49
51
|
header,
|
|
50
52
|
footer,
|
|
@@ -56,7 +58,9 @@ class UrlConverter extends converter_1.Converter {
|
|
|
56
58
|
waitForExpression,
|
|
57
59
|
userAgent,
|
|
58
60
|
extraHttpHeaders,
|
|
61
|
+
failOnHttpStatusCodes,
|
|
59
62
|
failOnConsoleExceptions,
|
|
63
|
+
skipNetworkIdleEvent
|
|
60
64
|
});
|
|
61
65
|
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
62
66
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/url.converter.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"url.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/url.converter.ts"],"names":[],"mappings":";;;;AAAA,6BAA0B;AAC1B,kEAAiC;AACjC,yCAA+E;AAE/E,8DAA0D;AAC1D,2CAAwC;AACxC,mDAAkD;AAGlD;;;;;GAKG;AACH,MAAa,YAAa,SAAQ,qBAAS;IACvC;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACG,OAAO,CAAC,EACV,GAAG,EACH,MAAM,EACN,MAAM,EACN,UAAU,EACV,SAAS,EACT,KAAK,EACL,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EAgBvB;;YACG,MAAM,IAAI,GAAG,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;YAC1B,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;YAE9B,MAAM,gCAAc,CAAC,SAAS,CAAC,IAAI,EAAE;gBACjC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,SAAS;gBACT,KAAK;gBACL,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,SAAS;gBACT,gBAAgB;gBAChB,qBAAqB;gBACrB,uBAAuB;gBACvB,oBAAoB;aACvB,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AAnFD,oCAmFC"}
|
package/dist/chromium/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { HtmlConverter } from
|
|
2
|
-
export { MarkdownConverter } from
|
|
3
|
-
export { UrlConverter } from
|
|
1
|
+
export { HtmlConverter } from './converters/html.converter';
|
|
2
|
+
export { MarkdownConverter } from './converters/markdown.converter';
|
|
3
|
+
export { UrlConverter } from './converters/url.converter';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chromium/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chromium/index.ts"],"names":[],"mappings":";;;AAAA,8DAA4D;AAAnD,+GAAA,aAAa,OAAA;AACtB,sEAAoE;AAA3D,uHAAA,iBAAiB,OAAA;AAC1B,4DAA0D;AAAjD,6GAAA,YAAY,OAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PathLikeOrReadStream } from '../../common';
|
|
2
|
+
export type EmulatedMediaType = 'screen' | 'print';
|
|
3
|
+
export type ChromiumOptions = {
|
|
4
|
+
header?: PathLikeOrReadStream;
|
|
5
|
+
footer?: PathLikeOrReadStream;
|
|
6
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
7
|
+
waitDelay?: string;
|
|
8
|
+
waitForExpression?: string;
|
|
9
|
+
extraHttpHeaders?: Record<string, string>;
|
|
10
|
+
failOnHttpStatusCodes?: number[];
|
|
11
|
+
failOnConsoleExceptions?: boolean;
|
|
12
|
+
skipNetworkIdleEvent?: boolean;
|
|
13
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.types.js","sourceRoot":"","sources":["../../../src/chromium/interfaces/common.types.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PdfFormat } from '../../common';
|
|
2
|
+
import { ChromiumOptions } from './common.types';
|
|
2
3
|
type PageSize = {
|
|
3
4
|
width: number;
|
|
4
5
|
height: number;
|
|
@@ -10,6 +11,7 @@ type PageMargins = {
|
|
|
10
11
|
right: number;
|
|
11
12
|
};
|
|
12
13
|
export type PageProperties = {
|
|
14
|
+
singlePage?: boolean;
|
|
13
15
|
size?: PageSize;
|
|
14
16
|
margins?: PageMargins;
|
|
15
17
|
preferCssPageSize?: boolean;
|
|
@@ -22,18 +24,10 @@ export type PageProperties = {
|
|
|
22
24
|
to: number;
|
|
23
25
|
};
|
|
24
26
|
};
|
|
25
|
-
export type
|
|
26
|
-
export type ConversionOptions = {
|
|
27
|
-
header?: PathLikeOrReadStream;
|
|
28
|
-
footer?: PathLikeOrReadStream;
|
|
27
|
+
export type ConversionOptions = ChromiumOptions & {
|
|
29
28
|
properties?: PageProperties;
|
|
30
29
|
pdfFormat?: PdfFormat;
|
|
31
30
|
pdfUA?: boolean;
|
|
32
|
-
emulatedMediaType?: EmulatedMediaType;
|
|
33
|
-
waitDelay?: string;
|
|
34
|
-
waitForExpression?: string;
|
|
35
31
|
userAgent?: string;
|
|
36
|
-
extraHttpHeaders?: Record<string, string>;
|
|
37
|
-
failOnConsoleExceptions?: boolean;
|
|
38
32
|
};
|
|
39
33
|
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import FormData from
|
|
2
|
-
import { ConversionOptions, PageProperties } from
|
|
3
|
-
import { PathLikeOrReadStream } from "../../common";
|
|
1
|
+
import FormData from 'form-data';
|
|
2
|
+
import { ConversionOptions, PageProperties } from '../interfaces/converter.types';
|
|
4
3
|
/**
|
|
5
4
|
* Utility class for handling common tasks related to conversion.
|
|
6
5
|
*/
|
|
@@ -12,15 +11,6 @@ export declare class ConverterUtils {
|
|
|
12
11
|
* @param {PageProperties} pageProperties - The page properties to be added to the FormData.
|
|
13
12
|
*/
|
|
14
13
|
static addPageProperties(data: FormData, pageProperties: PageProperties): void;
|
|
15
|
-
/**
|
|
16
|
-
* Adds a file to the FormData object.
|
|
17
|
-
*
|
|
18
|
-
* @param {FormData} data - The FormData object to which the file will be added.
|
|
19
|
-
* @param {PathLikeOrReadStream} file - The file to be added (either a PathLike or a ReadStream).
|
|
20
|
-
* @param {string} name - The name to be used for the file in the FormData.
|
|
21
|
-
* @returns {Promise<void>} A Promise that resolves once the file has been added.
|
|
22
|
-
*/
|
|
23
|
-
static addFile(data: FormData, file: PathLikeOrReadStream, name: string): Promise<void>;
|
|
24
14
|
/**
|
|
25
15
|
* Customizes the FormData object based on the provided conversion options.
|
|
26
16
|
*
|