chromiumly 2.2.0 → 2.4.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 +1 -0
- package/dist/chromium/converters/html.converter.d.ts +8 -3
- package/dist/chromium/converters/html.converter.js +19 -18
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/dist/chromium/converters/markdown.converter.d.ts +8 -3
- package/dist/chromium/converters/markdown.converter.js +24 -18
- package/dist/chromium/converters/markdown.converter.js.map +1 -1
- package/dist/chromium/converters/url.converter.d.ts +8 -3
- package/dist/chromium/converters/url.converter.js +14 -19
- package/dist/chromium/converters/url.converter.js.map +1 -1
- package/dist/chromium/interfaces/converter.types.d.ts +18 -0
- package/dist/chromium/utils/converter.utils.d.ts +2 -1
- package/dist/chromium/utils/converter.utils.js +56 -0
- package/dist/chromium/utils/converter.utils.js.map +1 -1
- package/dist/common/gotenberg.utils.js.map +1 -1
- package/dist/gotenberg.js.map +1 -1
- package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
- package/dist/pdf-engines/pdf.engine.d.ts +2 -1
- package/dist/pdf-engines/pdf.engine.js +5 -2
- package/dist/pdf-engines/pdf.engine.js.map +1 -1
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
- package/package.json +27 -12
- package/src/chromium/converters/html.converter.ts +31 -24
- package/src/chromium/converters/markdown.converter.ts +36 -22
- package/src/chromium/converters/tests/html.converter.test.ts +11 -0
- package/src/chromium/converters/tests/markdown.converter.test.ts +13 -1
- package/src/chromium/converters/url.converter.ts +27 -22
- package/src/chromium/interfaces/converter.types.ts +18 -0
- package/src/chromium/utils/converter.utils.ts +73 -1
- package/src/chromium/utils/tests/converter.utils.test.ts +267 -7
- package/src/pdf-engines/pdf.engine.ts +13 -1
- package/src/pdf-engines/tests/pdf.engine.test.ts +2 -1
- package/dist/chromium/interfaces/converter.interface.d.ts +0 -10
- package/dist/chromium/interfaces/converter.interface.js +0 -3
- package/dist/chromium/interfaces/converter.interface.js.map +0 -1
- package/src/chromium/interfaces/converter.interface.ts +0 -12
|
@@ -3,7 +3,6 @@ import { constants, createReadStream, PathLike, promises } from "fs";
|
|
|
3
3
|
import FormData from "form-data";
|
|
4
4
|
|
|
5
5
|
import { GotenbergUtils, PdfFormat } from "../../common";
|
|
6
|
-
import { IConverter } from "../interfaces/converter.interface";
|
|
7
6
|
import {
|
|
8
7
|
EmulatedMediaType,
|
|
9
8
|
PageProperties,
|
|
@@ -12,7 +11,7 @@ import { ConverterUtils } from "../utils/converter.utils";
|
|
|
12
11
|
import { Converter } from "./converter";
|
|
13
12
|
import { ChromiumRoute } from "../../main.config";
|
|
14
13
|
|
|
15
|
-
export class HtmlConverter extends Converter
|
|
14
|
+
export class HtmlConverter extends Converter {
|
|
16
15
|
constructor() {
|
|
17
16
|
super(ChromiumRoute.HTML);
|
|
18
17
|
}
|
|
@@ -23,41 +22,49 @@ export class HtmlConverter extends Converter implements IConverter {
|
|
|
23
22
|
footer,
|
|
24
23
|
properties,
|
|
25
24
|
pdfFormat,
|
|
25
|
+
pdfUA,
|
|
26
26
|
emulatedMediaType,
|
|
27
|
+
waitDelay,
|
|
28
|
+
waitForExpression,
|
|
29
|
+
userAgent,
|
|
30
|
+
extraHttpHeaders,
|
|
31
|
+
failOnConsoleExceptions,
|
|
27
32
|
}: {
|
|
28
33
|
html: PathLike;
|
|
29
34
|
header?: PathLike;
|
|
30
35
|
footer?: PathLike;
|
|
31
36
|
properties?: PageProperties;
|
|
32
37
|
pdfFormat?: PdfFormat;
|
|
38
|
+
pdfUA?: boolean;
|
|
33
39
|
emulatedMediaType?: EmulatedMediaType;
|
|
40
|
+
waitDelay?: string;
|
|
41
|
+
waitForExpression?: string;
|
|
42
|
+
userAgent?: string;
|
|
43
|
+
extraHttpHeaders?: Record<string, string>;
|
|
44
|
+
failOnConsoleExceptions?: boolean;
|
|
34
45
|
}): Promise<Buffer> {
|
|
35
|
-
await promises.access(html, constants.R_OK);
|
|
36
46
|
const data = new FormData();
|
|
37
47
|
|
|
38
|
-
if (
|
|
39
|
-
data.append("
|
|
48
|
+
if (Buffer.isBuffer(html)) {
|
|
49
|
+
data.append("files", html, "index.html");
|
|
50
|
+
} else {
|
|
51
|
+
await promises.access(html, constants.R_OK);
|
|
52
|
+
data.append("files", createReadStream(html), "index.html");
|
|
40
53
|
}
|
|
41
54
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
data.append("emulatedMediaType", emulatedMediaType);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
if (properties) {
|
|
59
|
-
ConverterUtils.injectPageProperties(data, properties);
|
|
60
|
-
}
|
|
55
|
+
ConverterUtils.customize(data, {
|
|
56
|
+
header,
|
|
57
|
+
footer,
|
|
58
|
+
properties,
|
|
59
|
+
pdfFormat,
|
|
60
|
+
pdfUA,
|
|
61
|
+
emulatedMediaType,
|
|
62
|
+
waitDelay,
|
|
63
|
+
waitForExpression,
|
|
64
|
+
userAgent,
|
|
65
|
+
extraHttpHeaders,
|
|
66
|
+
failOnConsoleExceptions,
|
|
67
|
+
});
|
|
61
68
|
|
|
62
69
|
return GotenbergUtils.fetch(this.endpoint, data);
|
|
63
70
|
}
|
|
@@ -3,7 +3,6 @@ import { constants, createReadStream, PathLike, promises } from "fs";
|
|
|
3
3
|
import FormData from "form-data";
|
|
4
4
|
|
|
5
5
|
import { GotenbergUtils, PdfFormat } from "../../common";
|
|
6
|
-
import { IConverter } from "../interfaces/converter.interface";
|
|
7
6
|
import {
|
|
8
7
|
EmulatedMediaType,
|
|
9
8
|
PageProperties,
|
|
@@ -12,7 +11,7 @@ import { ConverterUtils } from "../utils/converter.utils";
|
|
|
12
11
|
import { Converter } from "./converter";
|
|
13
12
|
import { ChromiumRoute } from "../../main.config";
|
|
14
13
|
|
|
15
|
-
export class MarkdownConverter extends Converter
|
|
14
|
+
export class MarkdownConverter extends Converter {
|
|
16
15
|
constructor() {
|
|
17
16
|
super(ChromiumRoute.MARKDOWN);
|
|
18
17
|
}
|
|
@@ -24,7 +23,13 @@ export class MarkdownConverter extends Converter implements IConverter {
|
|
|
24
23
|
footer,
|
|
25
24
|
properties,
|
|
26
25
|
pdfFormat,
|
|
26
|
+
pdfUA,
|
|
27
27
|
emulatedMediaType,
|
|
28
|
+
waitDelay,
|
|
29
|
+
waitForExpression,
|
|
30
|
+
userAgent,
|
|
31
|
+
extraHttpHeaders,
|
|
32
|
+
failOnConsoleExceptions,
|
|
28
33
|
}: {
|
|
29
34
|
html: PathLike;
|
|
30
35
|
markdown: PathLike;
|
|
@@ -32,34 +37,43 @@ export class MarkdownConverter extends Converter implements IConverter {
|
|
|
32
37
|
footer?: PathLike;
|
|
33
38
|
properties?: PageProperties;
|
|
34
39
|
pdfFormat?: PdfFormat;
|
|
40
|
+
pdfUA?: boolean;
|
|
35
41
|
emulatedMediaType?: EmulatedMediaType;
|
|
42
|
+
waitDelay?: string;
|
|
43
|
+
waitForExpression?: string;
|
|
44
|
+
userAgent?: string;
|
|
45
|
+
extraHttpHeaders?: Record<string, string>;
|
|
46
|
+
failOnConsoleExceptions?: boolean;
|
|
36
47
|
}): Promise<Buffer> {
|
|
37
|
-
await promises.access(html, constants.R_OK);
|
|
38
|
-
await promises.access(markdown, constants.R_OK);
|
|
39
48
|
const data = new FormData();
|
|
40
|
-
if (pdfFormat) {
|
|
41
|
-
data.append("pdfFormat", pdfFormat);
|
|
42
|
-
}
|
|
43
|
-
data.append("index.html", createReadStream(html));
|
|
44
|
-
data.append("file.md", createReadStream(markdown));
|
|
45
|
-
|
|
46
|
-
if (header) {
|
|
47
|
-
await promises.access(header, constants.R_OK);
|
|
48
|
-
data.append("header.html", createReadStream(header));
|
|
49
|
-
}
|
|
50
49
|
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
if (Buffer.isBuffer(html)) {
|
|
51
|
+
data.append("files", html, "index.html");
|
|
52
|
+
} else {
|
|
53
|
+
await promises.access(html, constants.R_OK);
|
|
54
|
+
data.append("files", createReadStream(html), "index.html");
|
|
54
55
|
}
|
|
55
56
|
|
|
56
|
-
if (
|
|
57
|
-
data.append("
|
|
57
|
+
if (Buffer.isBuffer(markdown)) {
|
|
58
|
+
data.append("files", createReadStream(markdown), "file.md");
|
|
59
|
+
} else {
|
|
60
|
+
await promises.access(markdown, constants.R_OK);
|
|
61
|
+
data.append("file.md", createReadStream(markdown));
|
|
58
62
|
}
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
ConverterUtils.customize(data, {
|
|
65
|
+
header,
|
|
66
|
+
footer,
|
|
67
|
+
properties,
|
|
68
|
+
pdfFormat,
|
|
69
|
+
pdfUA,
|
|
70
|
+
emulatedMediaType,
|
|
71
|
+
waitDelay,
|
|
72
|
+
waitForExpression,
|
|
73
|
+
userAgent,
|
|
74
|
+
extraHttpHeaders,
|
|
75
|
+
failOnConsoleExceptions,
|
|
76
|
+
});
|
|
63
77
|
|
|
64
78
|
return GotenbergUtils.fetch(this.endpoint, data);
|
|
65
79
|
}
|
|
@@ -44,6 +44,17 @@ describe("HtmlConverter", () => {
|
|
|
44
44
|
});
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
+
describe("when buffer is passed", () => {
|
|
48
|
+
it("should return a buffer", async () => {
|
|
49
|
+
mockPromisesAccess.mockResolvedValue();
|
|
50
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
51
|
+
const buffer = await converter.convert({
|
|
52
|
+
html: Buffer.from("html"),
|
|
53
|
+
});
|
|
54
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
47
58
|
describe("when pdf format parameter is passed", () => {
|
|
48
59
|
it("should return a buffer", async () => {
|
|
49
60
|
mockPromisesAccess.mockResolvedValue();
|
|
@@ -35,7 +35,7 @@ describe("MarkdownConverter", () => {
|
|
|
35
35
|
.mockImplementation((file) => file);
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
describe("when
|
|
38
|
+
describe("when files exist", () => {
|
|
39
39
|
it("should return a buffer", async () => {
|
|
40
40
|
mockPromisesAccess.mockResolvedValue();
|
|
41
41
|
mockFetch.mockResolvedValue(new Response("content"));
|
|
@@ -47,6 +47,18 @@ describe("MarkdownConverter", () => {
|
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
describe("when buffers passed", () => {
|
|
51
|
+
it("should return a buffer", async () => {
|
|
52
|
+
mockPromisesAccess.mockResolvedValue();
|
|
53
|
+
mockFetch.mockResolvedValue(new Response("content"));
|
|
54
|
+
const buffer = await converter.convert({
|
|
55
|
+
html: Buffer.from("html"),
|
|
56
|
+
markdown: Buffer.from("markdown"),
|
|
57
|
+
});
|
|
58
|
+
expect(buffer).toEqual(Buffer.from("content"));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
50
62
|
describe("when pdf format parameter is passed", () => {
|
|
51
63
|
it("should return a buffer", async () => {
|
|
52
64
|
mockPromisesAccess.mockResolvedValue();
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { PathLike
|
|
1
|
+
import { PathLike } from "fs";
|
|
2
2
|
|
|
3
3
|
import { URL } from "url";
|
|
4
4
|
|
|
5
5
|
import FormData from "form-data";
|
|
6
6
|
|
|
7
7
|
import { GotenbergUtils, PdfFormat } from "../../common";
|
|
8
|
-
import { IConverter } from "../interfaces/converter.interface";
|
|
9
8
|
import {
|
|
10
9
|
EmulatedMediaType,
|
|
11
10
|
PageProperties,
|
|
@@ -14,7 +13,7 @@ import { ConverterUtils } from "../utils/converter.utils";
|
|
|
14
13
|
import { Converter } from "./converter";
|
|
15
14
|
import { ChromiumRoute } from "../../main.config";
|
|
16
15
|
|
|
17
|
-
export class UrlConverter extends Converter
|
|
16
|
+
export class UrlConverter extends Converter {
|
|
18
17
|
constructor() {
|
|
19
18
|
super(ChromiumRoute.URL);
|
|
20
19
|
}
|
|
@@ -25,40 +24,46 @@ export class UrlConverter extends Converter implements IConverter {
|
|
|
25
24
|
footer,
|
|
26
25
|
properties,
|
|
27
26
|
pdfFormat,
|
|
27
|
+
pdfUA,
|
|
28
28
|
emulatedMediaType,
|
|
29
|
+
waitDelay,
|
|
30
|
+
waitForExpression,
|
|
31
|
+
userAgent,
|
|
32
|
+
extraHttpHeaders,
|
|
33
|
+
failOnConsoleExceptions,
|
|
29
34
|
}: {
|
|
30
35
|
url: string;
|
|
31
36
|
header?: PathLike;
|
|
32
37
|
footer?: PathLike;
|
|
33
38
|
properties?: PageProperties;
|
|
34
39
|
pdfFormat?: PdfFormat;
|
|
40
|
+
pdfUA?: boolean;
|
|
35
41
|
emulatedMediaType?: EmulatedMediaType;
|
|
42
|
+
waitDelay?: string;
|
|
43
|
+
waitForExpression?: string;
|
|
44
|
+
userAgent?: string;
|
|
45
|
+
extraHttpHeaders?: Record<string, string>;
|
|
46
|
+
failOnConsoleExceptions?: boolean;
|
|
36
47
|
}): Promise<Buffer> {
|
|
37
48
|
const _url = new URL(url);
|
|
38
49
|
const data = new FormData();
|
|
39
|
-
if (pdfFormat) {
|
|
40
|
-
data.append("pdfFormat", pdfFormat);
|
|
41
|
-
}
|
|
42
50
|
|
|
43
51
|
data.append("url", _url.href);
|
|
44
52
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
53
|
+
ConverterUtils.customize(data, {
|
|
54
|
+
header,
|
|
55
|
+
footer,
|
|
56
|
+
properties,
|
|
57
|
+
pdfFormat,
|
|
58
|
+
pdfUA,
|
|
59
|
+
emulatedMediaType,
|
|
60
|
+
waitDelay,
|
|
61
|
+
waitForExpression,
|
|
62
|
+
userAgent,
|
|
63
|
+
extraHttpHeaders,
|
|
64
|
+
failOnConsoleExceptions,
|
|
65
|
+
});
|
|
49
66
|
|
|
50
|
-
if (footer) {
|
|
51
|
-
await promises.access(footer, constants.R_OK);
|
|
52
|
-
data.append("footer.html", createReadStream(footer));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (emulatedMediaType) {
|
|
56
|
-
data.append("emulatedMediaType", emulatedMediaType);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (properties) {
|
|
60
|
-
ConverterUtils.injectPageProperties(data, properties);
|
|
61
|
-
}
|
|
62
67
|
return GotenbergUtils.fetch(this.endpoint, data);
|
|
63
68
|
}
|
|
64
69
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { PathLike } from "fs";
|
|
2
|
+
import { PdfFormat } from "../../common";
|
|
3
|
+
|
|
1
4
|
type PageSize = {
|
|
2
5
|
width: number; // Paper width, in inches (default 8.5)
|
|
3
6
|
height: number; //Paper height, in inches (default 11)
|
|
@@ -15,9 +18,24 @@ export type PageProperties = {
|
|
|
15
18
|
margins?: PageMargins;
|
|
16
19
|
preferCssPageSize?: boolean; // Define whether to prefer page size as defined by CSS (default false)
|
|
17
20
|
printBackground?: boolean; // Print the background graphics (default false)
|
|
21
|
+
omitBackground?: boolean; // Hide the default white background and allow generating PDFs with transparency (default false)
|
|
18
22
|
landscape?: boolean; // Set the paper orientation to landscape (default false)
|
|
19
23
|
scale?: number; // The scale of the page rendering (default 1.0)
|
|
20
24
|
nativePageRanges?: { from: number; to: number }; // Page ranges to print
|
|
21
25
|
};
|
|
22
26
|
|
|
23
27
|
export type EmulatedMediaType = "screen" | "print";
|
|
28
|
+
|
|
29
|
+
export type ConversionOptions = {
|
|
30
|
+
header?: PathLike | Buffer;
|
|
31
|
+
footer?: PathLike | Buffer;
|
|
32
|
+
properties?: PageProperties;
|
|
33
|
+
pdfFormat?: PdfFormat;
|
|
34
|
+
pdfUA?: boolean; // Enable PDF for Universal Access for optimal accessibility (default false)
|
|
35
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
36
|
+
waitDelay?: string; // Duration (e.g, '5s') to wait when loading an HTML document before converting it into PDF
|
|
37
|
+
waitForExpression?: string; // JavaScript expression to wait before converting an HTML document into PDF until it returns true.
|
|
38
|
+
userAgent?: string;
|
|
39
|
+
extraHttpHeaders?: Record<string, string>;
|
|
40
|
+
failOnConsoleExceptions?: boolean; // Return a 409 Conflict response if there are exceptions in the Chromium console (default false)
|
|
41
|
+
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { constants, createReadStream, promises } from "fs";
|
|
1
2
|
import FormData from "form-data";
|
|
2
3
|
|
|
3
4
|
import { GotenbergUtils } from "../../common/gotenberg.utils";
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ConversionOptions,
|
|
7
|
+
PageProperties,
|
|
8
|
+
} from "../interfaces/converter.types";
|
|
5
9
|
|
|
6
10
|
export class ConverterUtils {
|
|
7
11
|
public static injectPageProperties(
|
|
@@ -44,6 +48,10 @@ export class ConverterUtils {
|
|
|
44
48
|
data.append("printBackground", String(pageProperties.printBackground));
|
|
45
49
|
}
|
|
46
50
|
|
|
51
|
+
if (pageProperties.omitBackground) {
|
|
52
|
+
data.append("omitBackground", String(pageProperties.omitBackground));
|
|
53
|
+
}
|
|
54
|
+
|
|
47
55
|
if (pageProperties.landscape) {
|
|
48
56
|
data.append("landscape", String(pageProperties.landscape));
|
|
49
57
|
}
|
|
@@ -72,4 +80,68 @@ export class ConverterUtils {
|
|
|
72
80
|
);
|
|
73
81
|
}
|
|
74
82
|
}
|
|
83
|
+
|
|
84
|
+
public static async customize(
|
|
85
|
+
data: FormData,
|
|
86
|
+
options: ConversionOptions
|
|
87
|
+
): Promise<void> {
|
|
88
|
+
if (options.pdfFormat) {
|
|
89
|
+
data.append("pdfa", options.pdfFormat);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (options.pdfUA) {
|
|
93
|
+
data.append("pdfua", String(options.pdfUA));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (options.header) {
|
|
97
|
+
const { header } = options;
|
|
98
|
+
if (Buffer.isBuffer(header)) {
|
|
99
|
+
data.append("files", header, "header.html");
|
|
100
|
+
} else {
|
|
101
|
+
await promises.access(options.header, constants.R_OK);
|
|
102
|
+
data.append("files", createReadStream(options.header), "header.html");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (options.footer) {
|
|
107
|
+
const { footer } = options;
|
|
108
|
+
if (Buffer.isBuffer(footer)) {
|
|
109
|
+
data.append("files", footer, "footer.html");
|
|
110
|
+
} else {
|
|
111
|
+
await promises.access(options.footer, constants.R_OK);
|
|
112
|
+
data.append("files", createReadStream(options.footer), "footer.html");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (options.emulatedMediaType) {
|
|
117
|
+
data.append("emulatedMediaType", options.emulatedMediaType);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (options.properties) {
|
|
121
|
+
ConverterUtils.injectPageProperties(data, options.properties);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (options.waitDelay) {
|
|
125
|
+
data.append("waitDelay", options.waitDelay);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (options.waitForExpression) {
|
|
129
|
+
data.append("waitForExpression", options.waitForExpression);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (options.userAgent) {
|
|
133
|
+
data.append("userAgent", options.userAgent);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (options.extraHttpHeaders) {
|
|
137
|
+
data.append("extraHttpHeaders", JSON.stringify(options.extraHttpHeaders));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (options.failOnConsoleExceptions) {
|
|
141
|
+
data.append(
|
|
142
|
+
"failOnConsoleExceptions",
|
|
143
|
+
String(options.failOnConsoleExceptions)
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
75
147
|
}
|