chromiumly 2.4.0 → 2.5.1
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 +57 -40
- package/dist/chromium/converters/converter.d.ts +13 -0
- package/dist/chromium/converters/converter.js +10 -0
- package/dist/chromium/converters/converter.js.map +1 -1
- package/dist/chromium/converters/html.converter.d.ts +32 -6
- package/dist/chromium/converters/html.converter.js +30 -9
- package/dist/chromium/converters/html.converter.js.map +1 -1
- package/dist/chromium/converters/markdown.converter.d.ts +34 -7
- package/dist/chromium/converters/markdown.converter.js +32 -16
- package/dist/chromium/converters/markdown.converter.js.map +1 -1
- package/dist/chromium/converters/url.converter.d.ts +31 -5
- package/dist/chromium/converters/url.converter.js +29 -1
- package/dist/chromium/converters/url.converter.js.map +1 -1
- package/dist/chromium/index.js.map +1 -1
- package/dist/chromium/interfaces/converter.types.d.ts +3 -6
- package/dist/chromium/utils/converter.utils.d.ts +27 -1
- package/dist/chromium/utils/converter.utils.js +48 -21
- package/dist/chromium/utils/converter.utils.js.map +1 -1
- package/dist/common/constants.js.map +1 -1
- package/dist/common/gotenberg.utils.d.ts +18 -0
- package/dist/common/gotenberg.utils.js +18 -0
- package/dist/common/gotenberg.utils.js.map +1 -1
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js.map +1 -1
- package/dist/common/types.d.ts +3 -0
- package/dist/common/types.js +3 -0
- package/dist/common/types.js.map +1 -0
- package/dist/gotenberg.d.ts +8 -0
- package/dist/gotenberg.js +8 -0
- package/dist/gotenberg.js.map +1 -1
- package/dist/libre-office/index.js.map +1 -1
- package/dist/libre-office/utils/constants.js +76 -76
- package/dist/libre-office/utils/constants.js.map +1 -1
- package/dist/libre-office/utils/libre-office.utils.d.ts +19 -4
- package/dist/libre-office/utils/libre-office.utils.js +39 -7
- package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
- package/dist/main.config.d.ts +43 -0
- package/dist/main.config.js +43 -0
- package/dist/main.config.js.map +1 -1
- package/dist/main.js.map +1 -1
- package/dist/pdf-engines/index.js.map +1 -1
- package/dist/pdf-engines/pdf.engine.d.ts +31 -5
- package/dist/pdf-engines/pdf.engine.js +31 -3
- package/dist/pdf-engines/pdf.engine.js.map +1 -1
- package/dist/pdf-engines/utils/engine.utils.d.ts +12 -3
- package/dist/pdf-engines/utils/engine.utils.js +27 -8
- package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
- package/package.json +8 -7
- package/src/chromium/converters/converter.ts +18 -5
- package/src/chromium/converters/html.converter.ts +82 -61
- package/src/chromium/converters/markdown.converter.ts +86 -69
- package/src/chromium/converters/tests/html.converter.test.ts +119 -135
- package/src/chromium/converters/tests/markdown.converter.test.ts +131 -150
- package/src/chromium/converters/tests/url.converter.test.ts +114 -123
- package/src/chromium/converters/url.converter.ts +84 -60
- package/src/chromium/index.ts +3 -3
- package/src/chromium/interfaces/converter.types.ts +27 -27
- package/src/chromium/utils/converter.utils.ts +165 -139
- package/src/chromium/utils/tests/converter.utils.test.ts +312 -311
- package/src/common/constants.ts +3 -3
- package/src/common/gotenberg.utils.ts +36 -17
- package/src/common/index.ts +3 -2
- package/src/common/tests/gotenberg.utils.test.ts +54 -54
- package/src/common/types.ts +3 -0
- package/src/gotenberg.ts +13 -4
- package/src/libre-office/index.ts +2 -2
- package/src/libre-office/interfaces/libre-office.types.ts +2 -2
- package/src/libre-office/utils/constants.ts +76 -76
- package/src/libre-office/utils/libre-office.utils.ts +72 -37
- package/src/libre-office/utils/tests/libre-office.utils.test.ts +100 -68
- package/src/main.config.ts +68 -22
- package/src/main.ts +3 -3
- package/src/pdf-engines/index.ts +1 -1
- package/src/pdf-engines/pdf.engine.ts +77 -49
- package/src/pdf-engines/tests/pdf.engine.test.ts +94 -94
- package/src/pdf-engines/utils/engine.utils.ts +30 -12
- package/src/pdf-engines/utils/tests/engine.utils.test.ts +60 -48
|
@@ -1,69 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { URL } from "url";
|
|
4
|
-
|
|
1
|
+
import {URL} from "url";
|
|
5
2
|
import FormData from "form-data";
|
|
6
|
-
|
|
7
|
-
import { GotenbergUtils, PdfFormat } from "../../common";
|
|
3
|
+
import {GotenbergUtils, PdfFormat, PathLikeOrReadStream} from "../../common";
|
|
8
4
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
EmulatedMediaType,
|
|
6
|
+
PageProperties,
|
|
11
7
|
} from "../interfaces/converter.types";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
8
|
+
import {ConverterUtils} from "../utils/converter.utils";
|
|
9
|
+
import {Converter} from "./converter";
|
|
10
|
+
import {ChromiumRoute} from "../../main.config";
|
|
15
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Class representing a URL converter that extends the base Converter class.
|
|
14
|
+
* This class is used to convert content from a URL to PDF using Gotenberg service.
|
|
15
|
+
*
|
|
16
|
+
* @extends Converter
|
|
17
|
+
*/
|
|
16
18
|
export class UrlConverter extends Converter {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Creates an instance of UrlConverter.
|
|
21
|
+
* Initializes the converter with the URL conversion route.
|
|
22
|
+
*/
|
|
23
|
+
constructor() {
|
|
24
|
+
super(ChromiumRoute.URL);
|
|
25
|
+
}
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Converts content from a URL to PDF.
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} options - Conversion options.
|
|
31
|
+
* @param {string} options.url - The URL of the content to be converted to PDF.
|
|
32
|
+
* @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
|
|
33
|
+
* @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
|
|
34
|
+
* @param {PageProperties} [options.properties] - Page properties for the conversion.
|
|
35
|
+
* @param {PdfFormat} [options.pdfFormat] - PDF format options.
|
|
36
|
+
* @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
|
|
37
|
+
* @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the conversion.
|
|
38
|
+
* @param {string} [options.waitDelay] - Delay before the conversion process starts.
|
|
39
|
+
* @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
|
|
40
|
+
* @param {string} [options.userAgent] - User agent string to use during the conversion.
|
|
41
|
+
* @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
|
|
42
|
+
* @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
|
|
43
|
+
* @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
|
|
44
|
+
*/
|
|
45
|
+
async convert({
|
|
46
|
+
url,
|
|
47
|
+
header,
|
|
48
|
+
footer,
|
|
49
|
+
properties,
|
|
50
|
+
pdfFormat,
|
|
51
|
+
pdfUA,
|
|
52
|
+
emulatedMediaType,
|
|
53
|
+
waitDelay,
|
|
54
|
+
waitForExpression,
|
|
55
|
+
userAgent,
|
|
56
|
+
extraHttpHeaders,
|
|
57
|
+
failOnConsoleExceptions,
|
|
58
|
+
}: {
|
|
59
|
+
url: string;
|
|
60
|
+
header?: PathLikeOrReadStream;
|
|
61
|
+
footer?: PathLikeOrReadStream;
|
|
62
|
+
properties?: PageProperties;
|
|
63
|
+
pdfFormat?: PdfFormat;
|
|
64
|
+
pdfUA?: boolean;
|
|
65
|
+
emulatedMediaType?: EmulatedMediaType;
|
|
66
|
+
waitDelay?: string;
|
|
67
|
+
waitForExpression?: string;
|
|
68
|
+
userAgent?: string;
|
|
69
|
+
extraHttpHeaders?: Record<string, string>;
|
|
70
|
+
failOnConsoleExceptions?: boolean;
|
|
71
|
+
}): Promise<Buffer> {
|
|
72
|
+
const _url = new URL(url);
|
|
73
|
+
const data = new FormData();
|
|
50
74
|
|
|
51
|
-
|
|
75
|
+
data.append("url", _url.href);
|
|
52
76
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
77
|
+
await ConverterUtils.customize(data, {
|
|
78
|
+
header,
|
|
79
|
+
footer,
|
|
80
|
+
properties,
|
|
81
|
+
pdfFormat,
|
|
82
|
+
pdfUA,
|
|
83
|
+
emulatedMediaType,
|
|
84
|
+
waitDelay,
|
|
85
|
+
waitForExpression,
|
|
86
|
+
userAgent,
|
|
87
|
+
extraHttpHeaders,
|
|
88
|
+
failOnConsoleExceptions,
|
|
89
|
+
});
|
|
66
90
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
91
|
+
return GotenbergUtils.fetch(this.endpoint, data);
|
|
92
|
+
}
|
|
93
|
+
}
|
package/src/chromium/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
1
|
+
export {HtmlConverter} from "./converters/html.converter";
|
|
2
|
+
export {MarkdownConverter} from "./converters/markdown.converter";
|
|
3
|
+
export {UrlConverter} from "./converters/url.converter";
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { PdfFormat } from "../../common";
|
|
1
|
+
import {PathLikeOrReadStream, PdfFormat} from "../../common";
|
|
3
2
|
|
|
4
3
|
type PageSize = {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
width: number; // Paper width, in inches (default 8.5)
|
|
5
|
+
height: number; //Paper height, in inches (default 11)
|
|
7
6
|
};
|
|
8
7
|
|
|
9
8
|
type PageMargins = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
top: number; // Top margin, in inches (default 0.39)
|
|
10
|
+
bottom: number; // Bottom margin, in inches (default 0.39)
|
|
11
|
+
left: number; // Left margin, in inches (default 0.39)
|
|
12
|
+
right: number; // Right margin, in inches (default 0.39)
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
export type PageProperties = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
size?: PageSize;
|
|
17
|
+
margins?: PageMargins;
|
|
18
|
+
preferCssPageSize?: boolean; // Define whether to prefer page size as defined by CSS (default false)
|
|
19
|
+
printBackground?: boolean; // Print the background graphics (default false)
|
|
20
|
+
omitBackground?: boolean; // Hide the default white background and allow generating PDFs with transparency (default false)
|
|
21
|
+
landscape?: boolean; // Set the paper orientation to landscape (default false)
|
|
22
|
+
scale?: number; // The scale of the page rendering (default 1.0)
|
|
23
|
+
nativePageRanges?: { from: number; to: number }; // Page ranges to print
|
|
25
24
|
};
|
|
26
25
|
|
|
27
26
|
export type EmulatedMediaType = "screen" | "print";
|
|
28
27
|
|
|
28
|
+
|
|
29
29
|
export type ConversionOptions = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
header?: PathLikeOrReadStream;
|
|
31
|
+
footer?: PathLikeOrReadStream;
|
|
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's 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
41
|
};
|
|
@@ -1,147 +1,173 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {constants, createReadStream, promises} from "fs";
|
|
2
2
|
import FormData from "form-data";
|
|
3
3
|
|
|
4
|
-
import { GotenbergUtils } from "../../common/gotenberg.utils";
|
|
5
4
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
ConversionOptions,
|
|
6
|
+
PageProperties,
|
|
8
7
|
} from "../interfaces/converter.types";
|
|
8
|
+
import {GotenbergUtils, PathLikeOrReadStream} from "../../common";
|
|
9
|
+
import {ReadStream} from "fs";
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Utility class for handling common tasks related to conversion.
|
|
13
|
+
*/
|
|
10
14
|
export class ConverterUtils {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Adds page properties to the FormData object based on the provided PageProperties.
|
|
17
|
+
*
|
|
18
|
+
* @param {FormData} data - The FormData object to which page properties will be added.
|
|
19
|
+
* @param {PageProperties} pageProperties - The page properties to be added to the FormData.
|
|
20
|
+
*/
|
|
21
|
+
public static addPageProperties(
|
|
22
|
+
data: FormData,
|
|
23
|
+
pageProperties: PageProperties
|
|
24
|
+
): void {
|
|
25
|
+
if (pageProperties.size) {
|
|
26
|
+
GotenbergUtils.assert(
|
|
27
|
+
pageProperties.size.width >= 1.0 && pageProperties.size.height >= 1.5,
|
|
28
|
+
"size is smaller than the minimum printing requirements (i.e. 1.0 x 1.5 in)"
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
data.append("paperWidth", pageProperties.size.width);
|
|
32
|
+
data.append("paperHeight", pageProperties.size.height);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (pageProperties.margins) {
|
|
36
|
+
GotenbergUtils.assert(
|
|
37
|
+
pageProperties.margins.top >= 0 &&
|
|
38
|
+
pageProperties.margins.bottom >= 0 &&
|
|
39
|
+
pageProperties.margins.left >= 0 &&
|
|
40
|
+
pageProperties.margins.left >= 0,
|
|
41
|
+
"negative margins are not allowed"
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
data.append("marginTop", pageProperties.margins.top);
|
|
45
|
+
data.append("marginBottom", pageProperties.margins.bottom);
|
|
46
|
+
data.append("marginLeft", pageProperties.margins.left);
|
|
47
|
+
data.append("marginRight", pageProperties.margins.right);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (pageProperties.preferCssPageSize) {
|
|
51
|
+
data.append(
|
|
52
|
+
"preferCssPageSize",
|
|
53
|
+
String(pageProperties.preferCssPageSize)
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (pageProperties.printBackground) {
|
|
58
|
+
data.append("printBackground", String(pageProperties.printBackground));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (pageProperties.omitBackground) {
|
|
62
|
+
data.append("omitBackground", String(pageProperties.omitBackground));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (pageProperties.landscape) {
|
|
66
|
+
data.append("landscape", String(pageProperties.landscape));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (pageProperties.scale) {
|
|
70
|
+
GotenbergUtils.assert(
|
|
71
|
+
pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0,
|
|
72
|
+
"scale is outside of [0.1 - 2] range"
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
data.append("scale", pageProperties.scale);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (pageProperties.nativePageRanges) {
|
|
79
|
+
GotenbergUtils.assert(
|
|
80
|
+
pageProperties.nativePageRanges.from > 0 &&
|
|
81
|
+
pageProperties.nativePageRanges.to > 0 &&
|
|
82
|
+
pageProperties.nativePageRanges.to >=
|
|
83
|
+
pageProperties.nativePageRanges.from,
|
|
84
|
+
"page ranges syntax error"
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
data.append(
|
|
88
|
+
"nativePageRanges",
|
|
89
|
+
`${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Adds a file to the FormData object.
|
|
96
|
+
*
|
|
97
|
+
* @param {FormData} data - The FormData object to which the file will be added.
|
|
98
|
+
* @param {PathLikeOrReadStream} file - The file to be added (either a PathLike or a ReadStream).
|
|
99
|
+
* @param {string} name - The name to be used for the file in the FormData.
|
|
100
|
+
* @returns {Promise<void>} A Promise that resolves once the file has been added.
|
|
101
|
+
*/
|
|
102
|
+
public static async addFile(data: FormData, file: PathLikeOrReadStream, name: string) {
|
|
103
|
+
if (Buffer.isBuffer(file)) {
|
|
104
|
+
data.append("files", file, name);
|
|
105
|
+
} else if (file instanceof ReadStream) {
|
|
106
|
+
data.append("files", file, name);
|
|
107
|
+
} else {
|
|
108
|
+
await promises.access(file, constants.R_OK);
|
|
109
|
+
data.append("files", createReadStream(file), name);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Customizes the FormData object based on the provided conversion options.
|
|
115
|
+
*
|
|
116
|
+
* @param {FormData} data - The FormData object to be customized.
|
|
117
|
+
* @param {ConversionOptions} options - The conversion options to apply to the FormData.
|
|
118
|
+
* @returns {Promise<void>} A Promise that resolves once the customization is complete.
|
|
119
|
+
*/
|
|
120
|
+
public static async customize(
|
|
121
|
+
data: FormData,
|
|
122
|
+
options: ConversionOptions
|
|
123
|
+
): Promise<void> {
|
|
124
|
+
if (options.pdfFormat) {
|
|
125
|
+
data.append("pdfa", options.pdfFormat);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (options.pdfUA) {
|
|
129
|
+
data.append("pdfua", String(options.pdfUA));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (options.header) {
|
|
133
|
+
const {header} = options;
|
|
134
|
+
await ConverterUtils.addFile(data, header, "header.html")
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (options.footer) {
|
|
138
|
+
const {footer} = options;
|
|
139
|
+
await ConverterUtils.addFile(data, footer, "footer.html")
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (options.emulatedMediaType) {
|
|
143
|
+
data.append("emulatedMediaType", options.emulatedMediaType);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (options.properties) {
|
|
147
|
+
ConverterUtils.addPageProperties(data, options.properties);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (options.waitDelay) {
|
|
151
|
+
data.append("waitDelay", options.waitDelay);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (options.waitForExpression) {
|
|
155
|
+
data.append("waitForExpression", options.waitForExpression);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (options.userAgent) {
|
|
159
|
+
data.append("userAgent", options.userAgent);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (options.extraHttpHeaders) {
|
|
163
|
+
data.append("extraHttpHeaders", JSON.stringify(options.extraHttpHeaders));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (options.failOnConsoleExceptions) {
|
|
167
|
+
data.append(
|
|
168
|
+
"failOnConsoleExceptions",
|
|
169
|
+
String(options.failOnConsoleExceptions)
|
|
170
|
+
);
|
|
171
|
+
}
|
|
23
172
|
}
|
|
24
|
-
|
|
25
|
-
if (pageProperties.margins) {
|
|
26
|
-
GotenbergUtils.assert(
|
|
27
|
-
pageProperties.margins.top >= 0 &&
|
|
28
|
-
pageProperties.margins.bottom >= 0 &&
|
|
29
|
-
pageProperties.margins.left >= 0 &&
|
|
30
|
-
pageProperties.margins.left >= 0,
|
|
31
|
-
"negative margins are not allowed"
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
data.append("marginTop", pageProperties.margins.top);
|
|
35
|
-
data.append("marginBottom", pageProperties.margins.bottom);
|
|
36
|
-
data.append("marginLeft", pageProperties.margins.left);
|
|
37
|
-
data.append("marginRight", pageProperties.margins.right);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (pageProperties.preferCssPageSize) {
|
|
41
|
-
data.append(
|
|
42
|
-
"preferCssPageSize",
|
|
43
|
-
String(pageProperties.preferCssPageSize)
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (pageProperties.printBackground) {
|
|
48
|
-
data.append("printBackground", String(pageProperties.printBackground));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (pageProperties.omitBackground) {
|
|
52
|
-
data.append("omitBackground", String(pageProperties.omitBackground));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (pageProperties.landscape) {
|
|
56
|
-
data.append("landscape", String(pageProperties.landscape));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (pageProperties.scale) {
|
|
60
|
-
GotenbergUtils.assert(
|
|
61
|
-
pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0,
|
|
62
|
-
"scale is outside of [0.1 - 2] range"
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
data.append("scale", pageProperties.scale);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (pageProperties.nativePageRanges) {
|
|
69
|
-
GotenbergUtils.assert(
|
|
70
|
-
pageProperties.nativePageRanges.from > 0 &&
|
|
71
|
-
pageProperties.nativePageRanges.to > 0 &&
|
|
72
|
-
pageProperties.nativePageRanges.to >=
|
|
73
|
-
pageProperties.nativePageRanges.from,
|
|
74
|
-
"page ranges syntax error"
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
data.append(
|
|
78
|
-
"nativePageRanges",
|
|
79
|
-
`${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
|
|
80
|
-
);
|
|
81
|
-
}
|
|
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
|
-
}
|
|
147
173
|
}
|