chromiumly 2.7.0 → 2.9.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 +129 -8
- package/dist/chromium/converters/html.converter.d.ts +12 -2
- package/dist/chromium/converters/html.converter.js +5 -3
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/dist/chromium/converters/markdown.converter.d.ts +12 -2
- package/dist/chromium/converters/markdown.converter.js +5 -3
- package/dist/chromium/converters/markdown.converter.js.map +1 -1
- package/dist/chromium/converters/url.converter.d.ts +12 -2
- package/dist/chromium/converters/url.converter.js +5 -3
- package/dist/chromium/converters/url.converter.js.map +1 -1
- package/dist/chromium/index.d.ts +3 -0
- package/dist/chromium/index.js +7 -1
- package/dist/chromium/index.js.map +1 -1
- package/dist/chromium/interfaces/converter.types.d.ts +2 -1
- package/dist/chromium/interfaces/screenshot.types.d.ts +10 -0
- package/dist/chromium/interfaces/screenshot.types.js +3 -0
- package/dist/chromium/interfaces/screenshot.types.js.map +1 -0
- package/dist/chromium/screenshots/html.screenshot.d.ts +54 -0
- package/dist/chromium/screenshots/html.screenshot.js +67 -0
- package/dist/chromium/screenshots/html.screenshot.js.map +1 -0
- package/dist/chromium/screenshots/markdown.screenshot.d.ts +52 -0
- package/dist/chromium/screenshots/markdown.screenshot.js +66 -0
- package/dist/chromium/screenshots/markdown.screenshot.js.map +1 -0
- package/dist/chromium/screenshots/screenshot.d.ts +18 -0
- package/dist/chromium/screenshots/screenshot.js +21 -0
- package/dist/chromium/screenshots/screenshot.js.map +1 -0
- package/dist/chromium/screenshots/url.screenshot.d.ts +50 -0
- package/dist/chromium/screenshots/url.screenshot.js +66 -0
- package/dist/chromium/screenshots/url.screenshot.js.map +1 -0
- package/dist/chromium/utils/converter.utils.js +3 -0
- package/dist/chromium/utils/converter.utils.js.map +1 -1
- package/dist/chromium/utils/screenshot.utils.d.ts +22 -0
- package/dist/chromium/utils/screenshot.utils.js +75 -0
- package/dist/chromium/utils/screenshot.utils.js.map +1 -0
- package/dist/common/constants.d.ts +4 -0
- package/dist/common/constants.js +4 -0
- package/dist/common/constants.js.map +1 -1
- package/dist/common/index.d.ts +1 -1
- package/dist/common/types.d.ts +3 -0
- package/dist/libre-office/utils/constants.js +2 -1
- package/dist/libre-office/utils/constants.js.map +1 -1
- package/dist/main.config.d.ts +10 -1
- package/dist/main.config.js +10 -1
- package/dist/main.config.js.map +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.js +4 -1
- package/dist/main.js.map +1 -1
- package/dist/pdf-engines/pdf.engine.d.ts +23 -1
- package/dist/pdf-engines/pdf.engine.js +34 -4
- package/dist/pdf-engines/pdf.engine.js.map +1 -1
- package/package.json +7 -7
- package/src/chromium/converters/html.converter.ts +20 -3
- package/src/chromium/converters/markdown.converter.ts +20 -3
- package/src/chromium/converters/url.converter.ts +20 -3
- package/src/chromium/index.ts +3 -0
- package/src/chromium/interfaces/converter.types.ts +2 -1
- package/src/chromium/interfaces/screenshot.types.ts +12 -0
- package/src/chromium/screenshots/html.screenshot.ts +100 -0
- package/src/chromium/screenshots/markdown.screenshot.ts +95 -0
- package/src/chromium/screenshots/screenshot.ts +22 -0
- package/src/chromium/screenshots/tests/html.screenshot.test.ts +192 -0
- package/src/chromium/screenshots/tests/markdown.screenshot.test.ts +176 -0
- package/src/chromium/screenshots/tests/url.screenshot.test.ts +166 -0
- package/src/chromium/screenshots/url.screenshot.ts +91 -0
- package/src/chromium/utils/converter.utils.ts +3 -0
- package/src/chromium/utils/screenshot.utils.ts +115 -0
- package/src/chromium/utils/tests/converter.utils.test.ts +33 -2
- package/src/chromium/utils/tests/screenshot.utils.test.ts +284 -0
- package/src/common/constants.ts +4 -0
- package/src/common/index.ts +1 -1
- package/src/common/tests/gotenberg.utils.test.ts +46 -0
- package/src/common/types.ts +4 -0
- package/src/libre-office/utils/constants.ts +2 -1
- package/src/main.config.ts +12 -2
- package/src/main.ts +8 -1
- package/src/pdf-engines/pdf.engine.ts +52 -1
- package/src/pdf-engines/tests/pdf.engine.test.ts +36 -0
package/README.md
CHANGED
|
@@ -11,6 +11,29 @@
|
|
|
11
11
|
A lightweight Typescript library that interacts with [Gotenberg](https://gotenberg.dev/)'s different modules to convert
|
|
12
12
|
a variety of document formats to PDF files.
|
|
13
13
|
|
|
14
|
+
# Table of Contents
|
|
15
|
+
|
|
16
|
+
1. [Introduction](#introduction)
|
|
17
|
+
- [Install](#install)
|
|
18
|
+
- [Prerequisites](#prerequisites)
|
|
19
|
+
- [Get Started](#get-started)
|
|
20
|
+
2. [Configuration](#configuration)
|
|
21
|
+
- [dotenv](#dotenv)
|
|
22
|
+
- [config](#config)
|
|
23
|
+
3. [Modules](#modules)
|
|
24
|
+
- [Chromium](#chromium)
|
|
25
|
+
- [URL](#url)
|
|
26
|
+
- [HTML](#html)
|
|
27
|
+
- [Markdown](#markdown)
|
|
28
|
+
- [Customization](#customization)
|
|
29
|
+
- [Conversion](#conversion)
|
|
30
|
+
- [Screenshot](#screenshot)
|
|
31
|
+
- [PDF Engine](#pdf-engine)
|
|
32
|
+
- [convert](#convert)
|
|
33
|
+
- [merge](#merge)
|
|
34
|
+
- [generate](#generate)
|
|
35
|
+
4. [Snippet](#snippet)
|
|
36
|
+
|
|
14
37
|
## Install
|
|
15
38
|
|
|
16
39
|
Using npm:
|
|
@@ -62,16 +85,18 @@ GOTENBERG_ENDPOINT=http://localhost:3000
|
|
|
62
85
|
## Modules
|
|
63
86
|
|
|
64
87
|
Chromiumly introduces different classes that serve as wrappers to
|
|
65
|
-
Gotenberg's [
|
|
88
|
+
Gotenberg's [routes](https://gotenberg.dev/docs/routes). These classes encompass methods featuring an
|
|
66
89
|
input file parameter, such as `html`, `header`, `footer`, and `markdown`, capable of accepting inputs in the form of a
|
|
67
90
|
`string` (i.e. file path), `Buffer`, or `ReadStream`.
|
|
68
91
|
|
|
69
92
|
### Chormium
|
|
70
93
|
|
|
71
94
|
There are three different classes that come with a single method (i.e.`convert`) which calls one of
|
|
72
|
-
Chromium's [routes](https://gotenberg.dev/docs/
|
|
95
|
+
Chromium's [Conversion routes](https://gotenberg.dev/docs/routes#convert-with-chromium) to convert `html` and `markdown` files, or
|
|
73
96
|
a `url` to a `buffer` which contains the converted PDF file content.
|
|
74
97
|
|
|
98
|
+
Similarly, a new set of classes have been added to harness the recently introduced Gotenberg [Screenshot routes](https://gotenberg.dev/docs/routes#screenshots-route). These classes include a single method called `capture`, which allows capturing full-page screenshots of `html`, `markdown`, and `url`.
|
|
99
|
+
|
|
75
100
|
#### URL
|
|
76
101
|
|
|
77
102
|
```typescript
|
|
@@ -83,6 +108,15 @@ const buffer = await urlConverter.convert({
|
|
|
83
108
|
});
|
|
84
109
|
```
|
|
85
110
|
|
|
111
|
+
```typescript
|
|
112
|
+
import { UrlScreenshot } from "chromiumly";
|
|
113
|
+
|
|
114
|
+
const screenshot = new UrlScreenshot();
|
|
115
|
+
const buffer = await screenshot.capture({
|
|
116
|
+
url: "https://www.example.com/",
|
|
117
|
+
});
|
|
118
|
+
```
|
|
119
|
+
|
|
86
120
|
#### HTML
|
|
87
121
|
|
|
88
122
|
The only requirement is that the file name should be `index.html`.
|
|
@@ -96,6 +130,15 @@ const buffer = await htmlConverter.convert({
|
|
|
96
130
|
});
|
|
97
131
|
```
|
|
98
132
|
|
|
133
|
+
```typescript
|
|
134
|
+
import { HtmlScreenshot } from "chromiumly";
|
|
135
|
+
|
|
136
|
+
const screenshot = new HtmlScreenshot();
|
|
137
|
+
const buffer = await screenshot.capture({
|
|
138
|
+
html: "path/to/index.html",
|
|
139
|
+
});
|
|
140
|
+
```
|
|
141
|
+
|
|
99
142
|
#### Markdown
|
|
100
143
|
|
|
101
144
|
This route accepts an `index.html` file plus a markdown file.
|
|
@@ -110,8 +153,20 @@ const buffer = await markdownConverter.convert({
|
|
|
110
153
|
});
|
|
111
154
|
```
|
|
112
155
|
|
|
156
|
+
```typescript
|
|
157
|
+
import { MarkdownScreenshot } from "chromiumly";
|
|
158
|
+
|
|
159
|
+
const screenshot = new MarkdownScreenshot();
|
|
160
|
+
const buffer = await screenshot.capture({
|
|
161
|
+
html: "path/to/index.html",
|
|
162
|
+
markdown: "path/to/file.md",
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
113
166
|
### Customization
|
|
114
167
|
|
|
168
|
+
#### Conversion
|
|
169
|
+
|
|
115
170
|
`convert()` method takes an optional `properties` parameter of the following type which dictates how the PDF generated
|
|
116
171
|
file will look like.
|
|
117
172
|
|
|
@@ -154,20 +209,51 @@ type ConversionOptions = {
|
|
|
154
209
|
failOnHttpStatusCodes?: number[]; // List of HTTP status codes triggering a 409 Conflict response (default [499, 599])
|
|
155
210
|
failOnConsoleExceptions?: boolean; // Return a 409 Conflict response if there are exceptions in the Chromium console (default false)
|
|
156
211
|
skipNetworkIdleEvent?: boolean; // Do not wait for Chromium network to be idle (default false)
|
|
212
|
+
metadata?: Metadata; // Metadata to be written.
|
|
213
|
+
};
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
#### Screenshot
|
|
217
|
+
|
|
218
|
+
Similarly, the `capture()` method takes an optional `properties` parameter of the specified type, influencing the appearance of the captured screenshot file.
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
type ImageProperties = {
|
|
222
|
+
format: "png" | "jpeg" | "webp"; //The image compression format, either "png", "jpeg" or "webp".
|
|
223
|
+
quality?: number; // The compression quality from range 0 to 100 (jpeg only).
|
|
224
|
+
omitBackground?: boolean; // Hide the default white background and allow generating screenshots with transparency.
|
|
225
|
+
};
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Furthermore, alongside the customization options offered by `ImageProperties`, the `capture()` method accommodates a variety of parameters to expand the versatility of the screenshot process. Below is a comprehensive overview of all parameters available:
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
type ScreenshotOptions = {
|
|
232
|
+
properties?: ImageProperties;
|
|
233
|
+
header?: PathLikeOrReadStream;
|
|
234
|
+
footer?: PathLikeOrReadStream;
|
|
235
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
236
|
+
waitDelay?: string; // Duration (e.g, '5s') to wait when loading an HTML document before convertion.
|
|
237
|
+
waitForExpression?: string; // JavaScript's expression to wait before converting an HTML document into PDF until it returns true.
|
|
238
|
+
extraHttpHeaders?: Record<string, string>;
|
|
239
|
+
failOnHttpStatusCodes?: number[]; // Return a 409 Conflict response if the HTTP status code is in the list (default [499,599])
|
|
240
|
+
failOnConsoleExceptions?: boolean; // Return a 409 Conflict response if there are exceptions in the Chromium console (default false)
|
|
241
|
+
skipNetworkIdleEvent?: boolean; // Do not wait for Chromium network to be idle (default false)
|
|
242
|
+
optimizeForSpeed?: boolean; // Define whether to optimize image encoding for speed, not for resulting size.
|
|
157
243
|
};
|
|
158
244
|
```
|
|
159
245
|
|
|
160
246
|
### PDF Engine
|
|
161
247
|
|
|
162
|
-
The `PDFEngine` combines the functionality of
|
|
163
|
-
Gotenberg's [PDF Engines](https://gotenberg.dev/docs/
|
|
164
|
-
and [LibreOffice](https://gotenberg.dev/docs/
|
|
248
|
+
The `PDFEngine` combines the functionality of
|
|
249
|
+
Gotenberg's [PDF Engines](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route)
|
|
250
|
+
and [LibreOffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) modules to manipulate different file formats.
|
|
165
251
|
|
|
166
252
|
#### convert
|
|
167
253
|
|
|
168
|
-
This method interacts with [LibreOffice](https://gotenberg.dev/docs/
|
|
254
|
+
This method interacts with [LibreOffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) module to convert different
|
|
169
255
|
documents to PDF files. You can find the file extensions
|
|
170
|
-
accepted [here](https://gotenberg.dev/docs/
|
|
256
|
+
accepted [here](https://gotenberg.dev/docs/routes#convert-with-libreoffice#route).
|
|
171
257
|
|
|
172
258
|
```typescript
|
|
173
259
|
import { PDFEngine } from "chromiumly";
|
|
@@ -185,7 +271,7 @@ Similarly to Chromium's module `convert` method, this method takes the following
|
|
|
185
271
|
|
|
186
272
|
#### merge
|
|
187
273
|
|
|
188
|
-
This method interacts with [PDF Engines](https://gotenberg.dev/docs/
|
|
274
|
+
This method interacts with [PDF Engines](https://gotenberg.dev/docs/routes#merge-pdfs-route) module which gathers different
|
|
189
275
|
engines that can manipulate and merge PDF files such
|
|
190
276
|
as: [PDFtk](https://gitlab.com/pdftk-java/pdftk), [PDFcpu](https://github.com/pdfcpu/pdfcpu), [QPDF](https://github.com/qpdf/qpdf),
|
|
191
277
|
and [UNO](https://github.com/unoconv/unoconv).
|
|
@@ -198,6 +284,41 @@ const buffer = await PDFEngine.merge({
|
|
|
198
284
|
});
|
|
199
285
|
```
|
|
200
286
|
|
|
287
|
+
#### readMetadata
|
|
288
|
+
|
|
289
|
+
This method reads metadata from the provided PDF files.
|
|
290
|
+
|
|
291
|
+
```typescript
|
|
292
|
+
import { PDFEngine } from "chromiumly";
|
|
293
|
+
|
|
294
|
+
const metadataBuffer = await PDFEngine.readMetadata([
|
|
295
|
+
"path/to/file_1.pdf",
|
|
296
|
+
"path/to/file_2.pdf",
|
|
297
|
+
]);
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
#### writeMetadata
|
|
301
|
+
|
|
302
|
+
This method writes metadata to the provided PDF files.
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
import { PDFEngine } from "chromiumly";
|
|
306
|
+
|
|
307
|
+
const buffer = await PDFEngine.writeMetadata({
|
|
308
|
+
files: [
|
|
309
|
+
"path/to/file_1.pdf",
|
|
310
|
+
"path/to/file_2.pdf",
|
|
311
|
+
],
|
|
312
|
+
metadata: {
|
|
313
|
+
Author: 'Taha Cherfia',
|
|
314
|
+
Tite: 'Chromiumly'
|
|
315
|
+
Keywords: ['pdf', 'html', 'gotenberg'],
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
Please consider referring to [ExifTool](https://exiftool.org/TagNames/XMP.html#pdf) for a comprehensive list of accessible metadata options.
|
|
321
|
+
|
|
201
322
|
#### generate
|
|
202
323
|
|
|
203
324
|
It is just a generic complementary method that takes the `buffer` returned by the `convert` method, and a
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { PathLikeOrReadStream, PdfFormat } from '../../common';
|
|
2
|
+
import { Metadata, PathLikeOrReadStream, PdfFormat } from '../../common';
|
|
3
3
|
import { PageProperties } from '../interfaces/converter.types';
|
|
4
4
|
import { Converter } from './converter';
|
|
5
5
|
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
@@ -33,9 +33,10 @@ export declare class HtmlConverter extends Converter {
|
|
|
33
33
|
* @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
34
34
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
35
35
|
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
36
|
+
* @param {Metadata} options.metadata - Metadata to be written.
|
|
36
37
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
37
38
|
*/
|
|
38
|
-
convert({ html, assets, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent }: {
|
|
39
|
+
convert({ html, assets, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, metadata }: {
|
|
39
40
|
html: PathLikeOrReadStream;
|
|
40
41
|
assets?: {
|
|
41
42
|
file: PathLikeOrReadStream;
|
|
@@ -44,15 +45,24 @@ export declare class HtmlConverter extends Converter {
|
|
|
44
45
|
header?: PathLikeOrReadStream;
|
|
45
46
|
footer?: PathLikeOrReadStream;
|
|
46
47
|
properties?: PageProperties;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for pdfFormat.
|
|
50
|
+
* @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
|
|
51
|
+
*/
|
|
47
52
|
pdfFormat?: PdfFormat;
|
|
48
53
|
pdfUA?: boolean;
|
|
49
54
|
emulatedMediaType?: EmulatedMediaType;
|
|
50
55
|
waitDelay?: string;
|
|
51
56
|
waitForExpression?: string;
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for userAgent.
|
|
59
|
+
* @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
|
|
60
|
+
*/
|
|
52
61
|
userAgent?: string;
|
|
53
62
|
extraHttpHeaders?: Record<string, string>;
|
|
54
63
|
failOnHttpStatusCodes?: number[];
|
|
55
64
|
failOnConsoleExceptions?: boolean;
|
|
56
65
|
skipNetworkIdleEvent?: boolean;
|
|
66
|
+
metadata?: Metadata;
|
|
57
67
|
}): Promise<Buffer>;
|
|
58
68
|
}
|
|
@@ -39,10 +39,11 @@ class HtmlConverter extends converter_1.Converter {
|
|
|
39
39
|
* @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
40
40
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
41
41
|
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
42
|
+
* @param {Metadata} options.metadata - Metadata to be written.
|
|
42
43
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
43
44
|
*/
|
|
44
|
-
convert(
|
|
45
|
-
return tslib_1.__awaiter(this,
|
|
45
|
+
convert(_a) {
|
|
46
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ html, assets, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, metadata }) {
|
|
46
47
|
const data = new form_data_1.default();
|
|
47
48
|
yield common_1.GotenbergUtils.addFile(data, html, 'index.html');
|
|
48
49
|
if (assets === null || assets === void 0 ? void 0 : assets.length) {
|
|
@@ -61,7 +62,8 @@ class HtmlConverter extends converter_1.Converter {
|
|
|
61
62
|
extraHttpHeaders,
|
|
62
63
|
failOnHttpStatusCodes,
|
|
63
64
|
failOnConsoleExceptions,
|
|
64
|
-
skipNetworkIdleEvent
|
|
65
|
+
skipNetworkIdleEvent,
|
|
66
|
+
metadata
|
|
65
67
|
});
|
|
66
68
|
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
67
69
|
});
|
|
@@ -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,yCAKsB;AAEtB,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;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,OAAO;qEAAC,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,EACpB,QAAQ,EA0BX;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;gBACpB,QAAQ;aACX,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AAxGD,sCAwGC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { PdfFormat, PathLikeOrReadStream } from '../../common';
|
|
2
|
+
import { PdfFormat, PathLikeOrReadStream, Metadata } from '../../common';
|
|
3
3
|
import { PageProperties } from '../interfaces/converter.types';
|
|
4
4
|
import { Converter } from './converter';
|
|
5
5
|
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
@@ -34,23 +34,33 @@ export declare class MarkdownConverter extends Converter {
|
|
|
34
34
|
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
35
35
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
36
36
|
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
37
|
+
* @param {Metadata} options.metadata - Metadata to be written.
|
|
37
38
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
38
39
|
*/
|
|
39
|
-
convert({ html, markdown, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent }: {
|
|
40
|
+
convert({ html, markdown, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, metadata }: {
|
|
40
41
|
html: PathLikeOrReadStream;
|
|
41
42
|
markdown: PathLikeOrReadStream;
|
|
42
43
|
header?: PathLikeOrReadStream;
|
|
43
44
|
footer?: PathLikeOrReadStream;
|
|
44
45
|
properties?: PageProperties;
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for pdfFormat.
|
|
48
|
+
* @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
|
|
49
|
+
*/
|
|
45
50
|
pdfFormat?: PdfFormat;
|
|
46
51
|
pdfUA?: boolean;
|
|
47
52
|
emulatedMediaType?: EmulatedMediaType;
|
|
48
53
|
waitDelay?: string;
|
|
49
54
|
waitForExpression?: string;
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for userAgent.
|
|
57
|
+
* @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
|
|
58
|
+
*/
|
|
50
59
|
userAgent?: string;
|
|
51
60
|
extraHttpHeaders?: Record<string, string>;
|
|
52
61
|
failOnHttpStatusCodes?: number[];
|
|
53
62
|
failOnConsoleExceptions?: boolean;
|
|
54
63
|
skipNetworkIdleEvent?: boolean;
|
|
64
|
+
metadata?: Metadata;
|
|
55
65
|
}): Promise<Buffer>;
|
|
56
66
|
}
|
|
@@ -40,10 +40,11 @@ class MarkdownConverter extends converter_1.Converter {
|
|
|
40
40
|
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
41
41
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
42
42
|
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
43
|
+
* @param {Metadata} options.metadata - Metadata to be written.
|
|
43
44
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
44
45
|
*/
|
|
45
|
-
convert(
|
|
46
|
-
return tslib_1.__awaiter(this,
|
|
46
|
+
convert(_a) {
|
|
47
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ html, markdown, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, metadata }) {
|
|
47
48
|
const data = new form_data_1.default();
|
|
48
49
|
yield common_1.GotenbergUtils.addFile(data, html, 'index.html');
|
|
49
50
|
yield common_1.GotenbergUtils.addFile(data, markdown, 'file.md');
|
|
@@ -60,7 +61,8 @@ class MarkdownConverter extends converter_1.Converter {
|
|
|
60
61
|
extraHttpHeaders,
|
|
61
62
|
failOnHttpStatusCodes,
|
|
62
63
|
failOnConsoleExceptions,
|
|
63
|
-
skipNetworkIdleEvent
|
|
64
|
+
skipNetworkIdleEvent,
|
|
65
|
+
metadata
|
|
64
66
|
});
|
|
65
67
|
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
66
68
|
});
|
|
@@ -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,yCAKsB;AAEtB,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;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,OAAO;qEAAC,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,EACpB,QAAQ,EA0BX;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;gBACpB,QAAQ;aACX,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AAnGD,8CAmGC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { PdfFormat, PathLikeOrReadStream } from '../../common';
|
|
2
|
+
import { PdfFormat, PathLikeOrReadStream, Metadata } from '../../common';
|
|
3
3
|
import { PageProperties } from '../interfaces/converter.types';
|
|
4
4
|
import { Converter } from './converter';
|
|
5
5
|
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
@@ -33,22 +33,32 @@ export declare class UrlConverter extends Converter {
|
|
|
33
33
|
* @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
34
34
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
35
35
|
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
36
|
+
* @param {Metadata} options.metadata - Metadata to be written.
|
|
36
37
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
37
38
|
*/
|
|
38
|
-
convert({ url, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent }: {
|
|
39
|
+
convert({ url, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, metadata }: {
|
|
39
40
|
url: string;
|
|
40
41
|
header?: PathLikeOrReadStream;
|
|
41
42
|
footer?: PathLikeOrReadStream;
|
|
42
43
|
properties?: PageProperties;
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for pdfFormat.
|
|
46
|
+
* @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
|
|
47
|
+
*/
|
|
43
48
|
pdfFormat?: PdfFormat;
|
|
44
49
|
pdfUA?: boolean;
|
|
45
50
|
emulatedMediaType?: EmulatedMediaType;
|
|
46
51
|
waitDelay?: string;
|
|
47
52
|
waitForExpression?: string;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for userAgent.
|
|
55
|
+
* @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
|
|
56
|
+
*/
|
|
48
57
|
userAgent?: string;
|
|
49
58
|
extraHttpHeaders?: Record<string, string>;
|
|
50
59
|
failOnHttpStatusCodes?: number[];
|
|
51
60
|
failOnConsoleExceptions?: boolean;
|
|
52
61
|
skipNetworkIdleEvent?: boolean;
|
|
62
|
+
metadata?: Metadata;
|
|
53
63
|
}): Promise<Buffer>;
|
|
54
64
|
}
|
|
@@ -40,10 +40,11 @@ class UrlConverter extends converter_1.Converter {
|
|
|
40
40
|
* @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
41
41
|
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
42
42
|
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
43
|
+
* @param {Metadata} options.metadata - Metadata to be written.
|
|
43
44
|
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
44
45
|
*/
|
|
45
|
-
convert(
|
|
46
|
-
return tslib_1.__awaiter(this,
|
|
46
|
+
convert(_a) {
|
|
47
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ url, header, footer, properties, pdfFormat, pdfUA, emulatedMediaType, waitDelay, waitForExpression, userAgent, extraHttpHeaders, failOnHttpStatusCodes, failOnConsoleExceptions, skipNetworkIdleEvent, metadata }) {
|
|
47
48
|
const _url = new url_1.URL(url);
|
|
48
49
|
const data = new form_data_1.default();
|
|
49
50
|
data.append('url', _url.href);
|
|
@@ -60,7 +61,8 @@ class UrlConverter extends converter_1.Converter {
|
|
|
60
61
|
extraHttpHeaders,
|
|
61
62
|
failOnHttpStatusCodes,
|
|
62
63
|
failOnConsoleExceptions,
|
|
63
|
-
skipNetworkIdleEvent
|
|
64
|
+
skipNetworkIdleEvent,
|
|
65
|
+
metadata
|
|
64
66
|
});
|
|
65
67
|
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
66
68
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"url.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/url.converter.ts"],"names":[],"mappings":";;;;AAAA,6BAA0B;AAC1B,kEAAiC;AACjC,
|
|
1
|
+
{"version":3,"file":"url.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/url.converter.ts"],"names":[],"mappings":";;;;AAAA,6BAA0B;AAC1B,kEAAiC;AACjC,yCAKsB;AAEtB,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;;;;;;;;;;;;;;;;;;;;OAoBG;IACG,OAAO;qEAAC,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,EACpB,QAAQ,EAyBX;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;gBACpB,QAAQ;aACX,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AA/FD,oCA+FC"}
|
package/dist/chromium/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export { UrlScreenshot } from './screenshots/url.screenshot';
|
|
2
|
+
export { MarkdownScreenshot } from './screenshots/markdown.screenshot';
|
|
3
|
+
export { HtmlScreenshot } from './screenshots/html.screenshot';
|
|
1
4
|
export { HtmlConverter } from './converters/html.converter';
|
|
2
5
|
export { MarkdownConverter } from './converters/markdown.converter';
|
|
3
6
|
export { UrlConverter } from './converters/url.converter';
|
package/dist/chromium/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UrlConverter = exports.MarkdownConverter = exports.HtmlConverter = void 0;
|
|
3
|
+
exports.UrlConverter = exports.MarkdownConverter = exports.HtmlConverter = exports.HtmlScreenshot = exports.MarkdownScreenshot = exports.UrlScreenshot = void 0;
|
|
4
|
+
var url_screenshot_1 = require("./screenshots/url.screenshot");
|
|
5
|
+
Object.defineProperty(exports, "UrlScreenshot", { enumerable: true, get: function () { return url_screenshot_1.UrlScreenshot; } });
|
|
6
|
+
var markdown_screenshot_1 = require("./screenshots/markdown.screenshot");
|
|
7
|
+
Object.defineProperty(exports, "MarkdownScreenshot", { enumerable: true, get: function () { return markdown_screenshot_1.MarkdownScreenshot; } });
|
|
8
|
+
var html_screenshot_1 = require("./screenshots/html.screenshot");
|
|
9
|
+
Object.defineProperty(exports, "HtmlScreenshot", { enumerable: true, get: function () { return html_screenshot_1.HtmlScreenshot; } });
|
|
4
10
|
var html_converter_1 = require("./converters/html.converter");
|
|
5
11
|
Object.defineProperty(exports, "HtmlConverter", { enumerable: true, get: function () { return html_converter_1.HtmlConverter; } });
|
|
6
12
|
var markdown_converter_1 = require("./converters/markdown.converter");
|
|
@@ -1 +1 @@
|
|
|
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"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chromium/index.ts"],"names":[],"mappings":";;;AAAA,+DAA6D;AAApD,+GAAA,aAAa,OAAA;AACtB,yEAAuE;AAA9D,yHAAA,kBAAkB,OAAA;AAC3B,iEAA+D;AAAtD,iHAAA,cAAc,OAAA;AACvB,8DAA4D;AAAnD,+GAAA,aAAa,OAAA;AACtB,sEAAoE;AAA3D,uHAAA,iBAAiB,OAAA;AAC1B,4DAA0D;AAAjD,6GAAA,YAAY,OAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PdfFormat } from '../../common';
|
|
1
|
+
import { Metadata, PdfFormat } from '../../common';
|
|
2
2
|
import { ChromiumOptions } from './common.types';
|
|
3
3
|
type PageSize = {
|
|
4
4
|
width: number;
|
|
@@ -29,5 +29,6 @@ export type ConversionOptions = ChromiumOptions & {
|
|
|
29
29
|
pdfFormat?: PdfFormat;
|
|
30
30
|
pdfUA?: boolean;
|
|
31
31
|
userAgent?: string;
|
|
32
|
+
metadata?: Metadata;
|
|
32
33
|
};
|
|
33
34
|
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChromiumOptions } from './common.types';
|
|
2
|
+
export type ImageProperties = {
|
|
3
|
+
format: 'png' | 'jpeg' | 'webp';
|
|
4
|
+
quality?: number;
|
|
5
|
+
omitBackground?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type ScreenshotOptions = ChromiumOptions & {
|
|
8
|
+
properties?: ImageProperties;
|
|
9
|
+
optimizeForSpeed?: boolean;
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"screenshot.types.js","sourceRoot":"","sources":["../../../src/chromium/interfaces/screenshot.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PathLikeOrReadStream } from '../../common';
|
|
3
|
+
import { EmulatedMediaType } from '../interfaces/common.types';
|
|
4
|
+
import { Screenshot } from './screenshot';
|
|
5
|
+
import { ImageProperties } from '../interfaces/screenshot.types';
|
|
6
|
+
/**
|
|
7
|
+
* Class representing an HTML Screenshot that extends the base Screenshot class.
|
|
8
|
+
* This class is used to screenshot HTML content using Gotenberg service.
|
|
9
|
+
*
|
|
10
|
+
* @extends Screenshot
|
|
11
|
+
*/
|
|
12
|
+
export declare class HtmlScreenshot extends Screenshot {
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of HtmlScreenshot.
|
|
15
|
+
* Initializes the Screenshot with the HTML screenshot route.
|
|
16
|
+
*/
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* Screenshots HTML content.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} options - Screenshot options.
|
|
22
|
+
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
|
|
23
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
24
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
25
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
26
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
27
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
28
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
29
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
30
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
31
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
32
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
33
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
34
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
35
|
+
*/
|
|
36
|
+
capture({ html, assets, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnConsoleExceptions, failOnHttpStatusCodes, skipNetworkIdleEvent, optimizeForSpeed }: {
|
|
37
|
+
html: PathLikeOrReadStream;
|
|
38
|
+
assets?: {
|
|
39
|
+
file: PathLikeOrReadStream;
|
|
40
|
+
name: string;
|
|
41
|
+
}[];
|
|
42
|
+
header?: PathLikeOrReadStream;
|
|
43
|
+
footer?: PathLikeOrReadStream;
|
|
44
|
+
properties?: ImageProperties;
|
|
45
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
46
|
+
waitDelay?: string;
|
|
47
|
+
waitForExpression?: string;
|
|
48
|
+
extraHttpHeaders?: Record<string, string>;
|
|
49
|
+
failOnConsoleExceptions?: boolean;
|
|
50
|
+
failOnHttpStatusCodes?: number[];
|
|
51
|
+
skipNetworkIdleEvent?: boolean;
|
|
52
|
+
optimizeForSpeed?: boolean;
|
|
53
|
+
}): Promise<Buffer>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HtmlScreenshot = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const form_data_1 = tslib_1.__importDefault(require("form-data"));
|
|
6
|
+
const common_1 = require("../../common");
|
|
7
|
+
const main_config_1 = require("../../main.config");
|
|
8
|
+
const screenshot_utils_1 = require("../utils/screenshot.utils");
|
|
9
|
+
const screenshot_1 = require("./screenshot");
|
|
10
|
+
/**
|
|
11
|
+
* Class representing an HTML Screenshot that extends the base Screenshot class.
|
|
12
|
+
* This class is used to screenshot HTML content using Gotenberg service.
|
|
13
|
+
*
|
|
14
|
+
* @extends Screenshot
|
|
15
|
+
*/
|
|
16
|
+
class HtmlScreenshot extends screenshot_1.Screenshot {
|
|
17
|
+
/**
|
|
18
|
+
* Creates an instance of HtmlScreenshot.
|
|
19
|
+
* Initializes the Screenshot with the HTML screenshot route.
|
|
20
|
+
*/
|
|
21
|
+
constructor() {
|
|
22
|
+
super(main_config_1.ChromiumRoute.HTML);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Screenshots HTML content.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} options - Screenshot options.
|
|
28
|
+
* @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
|
|
29
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
30
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
31
|
+
* @param {ImageProperties} [options.properties] - Image properties for the screenshot.
|
|
32
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
|
|
33
|
+
* @param {string} [options.waitDelay] - Delay before the screenshot process starts.
|
|
34
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
|
|
35
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
|
|
36
|
+
* @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
|
|
37
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
|
|
38
|
+
* @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
|
|
39
|
+
* @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
|
|
40
|
+
* @returns {Promise<Buffer>} A Promise resolving to the image buffer.
|
|
41
|
+
*/
|
|
42
|
+
capture(_a) {
|
|
43
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* ({ html, assets, header, footer, properties, emulatedMediaType, waitDelay, waitForExpression, extraHttpHeaders, failOnConsoleExceptions, failOnHttpStatusCodes, skipNetworkIdleEvent, optimizeForSpeed }) {
|
|
44
|
+
const data = new form_data_1.default();
|
|
45
|
+
yield common_1.GotenbergUtils.addFile(data, html, 'index.html');
|
|
46
|
+
if (assets === null || assets === void 0 ? void 0 : assets.length) {
|
|
47
|
+
yield Promise.all(assets.map(({ file, name }) => common_1.GotenbergUtils.addFile(data, file, name)));
|
|
48
|
+
}
|
|
49
|
+
yield screenshot_utils_1.ScreenshotUtils.customize(data, {
|
|
50
|
+
header,
|
|
51
|
+
footer,
|
|
52
|
+
properties,
|
|
53
|
+
emulatedMediaType,
|
|
54
|
+
waitDelay,
|
|
55
|
+
waitForExpression,
|
|
56
|
+
extraHttpHeaders,
|
|
57
|
+
failOnHttpStatusCodes,
|
|
58
|
+
failOnConsoleExceptions,
|
|
59
|
+
skipNetworkIdleEvent,
|
|
60
|
+
optimizeForSpeed
|
|
61
|
+
});
|
|
62
|
+
return common_1.GotenbergUtils.fetch(this.endpoint, data);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.HtmlScreenshot = HtmlScreenshot;
|
|
67
|
+
//# sourceMappingURL=html.screenshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html.screenshot.js","sourceRoot":"","sources":["../../../src/chromium/screenshots/html.screenshot.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,yCAAoE;AACpE,mDAAkD;AAElD,gEAA4D;AAC5D,6CAA0C;AAG1C;;;;;GAKG;AACH,MAAa,cAAe,SAAQ,uBAAU;IAC1C;;;OAGG;IACH;QACI,KAAK,CAAC,2BAAa,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACG,OAAO;qEAAC,EACV,IAAI,EACJ,MAAM,EACN,MAAM,EACN,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAenB;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,kCAAe,CAAC,SAAS,CAAC,IAAI,EAAE;gBAClC,MAAM;gBACN,MAAM;gBACN,UAAU;gBACV,iBAAiB;gBACjB,SAAS;gBACT,iBAAiB;gBACjB,gBAAgB;gBAChB,qBAAqB;gBACrB,uBAAuB;gBACvB,oBAAoB;gBACpB,gBAAgB;aACnB,CAAC,CAAC;YAEH,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACrD,CAAC;KAAA;CACJ;AApFD,wCAoFC"}
|