chromiumly 2.3.1 → 2.5.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.
Files changed (66) hide show
  1. package/dist/chromium/converters/converter.js.map +1 -1
  2. package/dist/chromium/converters/html.converter.d.ts +4 -6
  3. package/dist/chromium/converters/html.converter.js +3 -4
  4. package/dist/chromium/converters/html.converter.js.map +1 -1
  5. package/dist/chromium/converters/markdown.converter.d.ts +5 -7
  6. package/dist/chromium/converters/markdown.converter.js +3 -6
  7. package/dist/chromium/converters/markdown.converter.js.map +1 -1
  8. package/dist/chromium/converters/url.converter.d.ts +3 -5
  9. package/dist/chromium/converters/url.converter.js +1 -1
  10. package/dist/chromium/converters/url.converter.js.map +1 -1
  11. package/dist/chromium/index.js.map +1 -1
  12. package/dist/chromium/interfaces/converter.types.d.ts +3 -5
  13. package/dist/chromium/utils/converter.utils.d.ts +3 -1
  14. package/dist/chromium/utils/converter.utils.js +26 -11
  15. package/dist/chromium/utils/converter.utils.js.map +1 -1
  16. package/dist/common/constants.js.map +1 -1
  17. package/dist/common/gotenberg.utils.js.map +1 -1
  18. package/dist/common/index.d.ts +1 -0
  19. package/dist/common/index.js.map +1 -1
  20. package/dist/common/types.d.ts +3 -0
  21. package/dist/common/types.js +3 -0
  22. package/dist/common/types.js.map +1 -0
  23. package/dist/gotenberg.js.map +1 -1
  24. package/dist/libre-office/index.js.map +1 -1
  25. package/dist/libre-office/utils/constants.js.map +1 -1
  26. package/dist/libre-office/utils/libre-office.utils.d.ts +3 -4
  27. package/dist/libre-office/utils/libre-office.utils.js +18 -9
  28. package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
  29. package/dist/main.config.js.map +1 -1
  30. package/dist/main.js.map +1 -1
  31. package/dist/pdf-engines/index.js.map +1 -1
  32. package/dist/pdf-engines/pdf.engine.js +3 -3
  33. package/dist/pdf-engines/pdf.engine.js.map +1 -1
  34. package/dist/pdf-engines/utils/engine.utils.d.ts +2 -3
  35. package/dist/pdf-engines/utils/engine.utils.js +17 -8
  36. package/dist/pdf-engines/utils/engine.utils.js.map +1 -1
  37. package/package.json +7 -7
  38. package/src/chromium/converters/converter.ts +5 -5
  39. package/src/chromium/converters/html.converter.ts +54 -56
  40. package/src/chromium/converters/markdown.converter.ts +57 -60
  41. package/src/chromium/converters/tests/html.converter.test.ts +121 -126
  42. package/src/chromium/converters/tests/markdown.converter.test.ts +132 -139
  43. package/src/chromium/converters/tests/url.converter.test.ts +114 -123
  44. package/src/chromium/converters/url.converter.ts +55 -57
  45. package/src/chromium/index.ts +3 -3
  46. package/src/chromium/interfaces/converter.types.ts +27 -27
  47. package/src/chromium/utils/converter.utils.ts +141 -129
  48. package/src/chromium/utils/tests/converter.utils.test.ts +315 -280
  49. package/src/common/constants.ts +3 -3
  50. package/src/common/gotenberg.utils.ts +16 -16
  51. package/src/common/index.ts +3 -2
  52. package/src/common/tests/gotenberg.utils.test.ts +54 -54
  53. package/src/common/types.ts +3 -0
  54. package/src/gotenberg.ts +4 -4
  55. package/src/libre-office/index.ts +2 -2
  56. package/src/libre-office/interfaces/libre-office.types.ts +2 -2
  57. package/src/libre-office/utils/constants.ts +76 -76
  58. package/src/libre-office/utils/libre-office.utils.ts +42 -35
  59. package/src/libre-office/utils/tests/libre-office.utils.test.ts +81 -69
  60. package/src/main.config.ts +22 -21
  61. package/src/main.ts +3 -3
  62. package/src/pdf-engines/index.ts +1 -1
  63. package/src/pdf-engines/pdf.engine.ts +49 -49
  64. package/src/pdf-engines/tests/pdf.engine.test.ts +94 -94
  65. package/src/pdf-engines/utils/engine.utils.ts +20 -12
  66. package/src/pdf-engines/utils/tests/engine.utils.test.ts +60 -48
@@ -1,69 +1,67 @@
1
- import { PathLike } from "fs";
2
-
3
- import { URL } from "url";
1
+ import {URL} from "url";
4
2
 
5
3
  import FormData from "form-data";
6
4
 
7
- import { GotenbergUtils, PdfFormat } from "../../common";
5
+ import {GotenbergUtils, PdfFormat, PathLikeOrReadStream} from "../../common";
8
6
  import {
9
- EmulatedMediaType,
10
- PageProperties,
7
+ EmulatedMediaType,
8
+ PageProperties,
11
9
  } from "../interfaces/converter.types";
12
- import { ConverterUtils } from "../utils/converter.utils";
13
- import { Converter } from "./converter";
14
- import { ChromiumRoute } from "../../main.config";
10
+ import {ConverterUtils} from "../utils/converter.utils";
11
+ import {Converter} from "./converter";
12
+ import {ChromiumRoute} from "../../main.config";
15
13
 
16
14
  export class UrlConverter extends Converter {
17
- constructor() {
18
- super(ChromiumRoute.URL);
19
- }
15
+ constructor() {
16
+ super(ChromiumRoute.URL);
17
+ }
20
18
 
21
- async convert({
22
- url,
23
- header,
24
- footer,
25
- properties,
26
- pdfFormat,
27
- pdfUA,
28
- emulatedMediaType,
29
- waitDelay,
30
- waitForExpression,
31
- userAgent,
32
- extraHttpHeaders,
33
- failOnConsoleExceptions,
34
- }: {
35
- url: string;
36
- header?: PathLike;
37
- footer?: PathLike;
38
- properties?: PageProperties;
39
- pdfFormat?: PdfFormat;
40
- pdfUA?: boolean;
41
- emulatedMediaType?: EmulatedMediaType;
42
- waitDelay?: string;
43
- waitForExpression?: string;
44
- userAgent?: string;
45
- extraHttpHeaders?: Record<string, string>;
46
- failOnConsoleExceptions?: boolean;
47
- }): Promise<Buffer> {
48
- const _url = new URL(url);
49
- const data = new FormData();
19
+ async convert({
20
+ url,
21
+ header,
22
+ footer,
23
+ properties,
24
+ pdfFormat,
25
+ pdfUA,
26
+ emulatedMediaType,
27
+ waitDelay,
28
+ waitForExpression,
29
+ userAgent,
30
+ extraHttpHeaders,
31
+ failOnConsoleExceptions,
32
+ }: {
33
+ url: string;
34
+ header?: PathLikeOrReadStream;
35
+ footer?: PathLikeOrReadStream;
36
+ properties?: PageProperties;
37
+ pdfFormat?: PdfFormat;
38
+ pdfUA?: boolean;
39
+ emulatedMediaType?: EmulatedMediaType;
40
+ waitDelay?: string;
41
+ waitForExpression?: string;
42
+ userAgent?: string;
43
+ extraHttpHeaders?: Record<string, string>;
44
+ failOnConsoleExceptions?: boolean;
45
+ }): Promise<Buffer> {
46
+ const _url = new URL(url);
47
+ const data = new FormData();
50
48
 
51
- data.append("url", _url.href);
49
+ data.append("url", _url.href);
52
50
 
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
- });
51
+ await ConverterUtils.customize(data, {
52
+ header,
53
+ footer,
54
+ properties,
55
+ pdfFormat,
56
+ pdfUA,
57
+ emulatedMediaType,
58
+ waitDelay,
59
+ waitForExpression,
60
+ userAgent,
61
+ extraHttpHeaders,
62
+ failOnConsoleExceptions,
63
+ });
66
64
 
67
- return GotenbergUtils.fetch(this.endpoint, data);
68
- }
65
+ return GotenbergUtils.fetch(this.endpoint, data);
66
+ }
69
67
  }
@@ -1,3 +1,3 @@
1
- export { HtmlConverter } from "./converters/html.converter";
2
- export { MarkdownConverter } from "./converters/markdown.converter";
3
- export { UrlConverter } from "./converters/url.converter";
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 { PathLike } from "fs";
2
- import { PdfFormat } from "../../common";
1
+ import {PathLikeOrReadStream, PdfFormat} from "../../common";
3
2
 
4
3
  type PageSize = {
5
- width: number; // Paper width, in inches (default 8.5)
6
- height: number; //Paper height, in inches (default 11)
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
- top: number; // Top margin, in inches (default 0.39)
11
- bottom: number; // Bottom margin, in inches (default 0.39)
12
- left: number; // Left margin, in inches (default 0.39)
13
- right: number; // Right margin, in inches (default 0.39)
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
- size?: PageSize;
18
- margins?: PageMargins;
19
- preferCssPageSize?: boolean; // Define whether to prefer page size as defined by CSS (default false)
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)
22
- landscape?: boolean; // Set the paper orientation to landscape (default false)
23
- scale?: number; // The scale of the page rendering (default 1.0)
24
- nativePageRanges?: { from: number; to: number }; // Page ranges to print
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
- header?: PathLike;
31
- footer?: PathLike;
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)
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,137 +1,149 @@
1
- import { constants, createReadStream, promises } from "fs";
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
- ConversionOptions,
7
- PageProperties,
5
+ ConversionOptions,
6
+ PageProperties,
8
7
  } from "../interfaces/converter.types";
8
+ import {GotenbergUtils, PathLikeOrReadStream} from "../../common";
9
+ import {ReadStream} from "fs";
9
10
 
10
11
  export class ConverterUtils {
11
- public static injectPageProperties(
12
- data: FormData,
13
- pageProperties: PageProperties
14
- ): void {
15
- if (pageProperties.size) {
16
- GotenbergUtils.assert(
17
- pageProperties.size.width >= 1.0 && pageProperties.size.height >= 1.5,
18
- "size is smaller than the minimum printing requirements (i.e. 1.0 x 1.5 in)"
19
- );
20
-
21
- data.append("paperWidth", pageProperties.size.width);
22
- data.append("paperHeight", pageProperties.size.height);
12
+ public static addPageProperties(
13
+ data: FormData,
14
+ pageProperties: PageProperties
15
+ ): void {
16
+ if (pageProperties.size) {
17
+ GotenbergUtils.assert(
18
+ pageProperties.size.width >= 1.0 && pageProperties.size.height >= 1.5,
19
+ "size is smaller than the minimum printing requirements (i.e. 1.0 x 1.5 in)"
20
+ );
21
+
22
+ data.append("paperWidth", pageProperties.size.width);
23
+ data.append("paperHeight", pageProperties.size.height);
24
+ }
25
+
26
+ if (pageProperties.margins) {
27
+ GotenbergUtils.assert(
28
+ pageProperties.margins.top >= 0 &&
29
+ pageProperties.margins.bottom >= 0 &&
30
+ pageProperties.margins.left >= 0 &&
31
+ pageProperties.margins.left >= 0,
32
+ "negative margins are not allowed"
33
+ );
34
+
35
+ data.append("marginTop", pageProperties.margins.top);
36
+ data.append("marginBottom", pageProperties.margins.bottom);
37
+ data.append("marginLeft", pageProperties.margins.left);
38
+ data.append("marginRight", pageProperties.margins.right);
39
+ }
40
+
41
+ if (pageProperties.preferCssPageSize) {
42
+ data.append(
43
+ "preferCssPageSize",
44
+ String(pageProperties.preferCssPageSize)
45
+ );
46
+ }
47
+
48
+ if (pageProperties.printBackground) {
49
+ data.append("printBackground", String(pageProperties.printBackground));
50
+ }
51
+
52
+ if (pageProperties.omitBackground) {
53
+ data.append("omitBackground", String(pageProperties.omitBackground));
54
+ }
55
+
56
+ if (pageProperties.landscape) {
57
+ data.append("landscape", String(pageProperties.landscape));
58
+ }
59
+
60
+ if (pageProperties.scale) {
61
+ GotenbergUtils.assert(
62
+ pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0,
63
+ "scale is outside of [0.1 - 2] range"
64
+ );
65
+
66
+ data.append("scale", pageProperties.scale);
67
+ }
68
+
69
+ if (pageProperties.nativePageRanges) {
70
+ GotenbergUtils.assert(
71
+ pageProperties.nativePageRanges.from > 0 &&
72
+ pageProperties.nativePageRanges.to > 0 &&
73
+ pageProperties.nativePageRanges.to >=
74
+ pageProperties.nativePageRanges.from,
75
+ "page ranges syntax error"
76
+ );
77
+
78
+ data.append(
79
+ "nativePageRanges",
80
+ `${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
81
+ );
82
+ }
83
+ }
84
+
85
+ public static async addFile(data: FormData, file: PathLikeOrReadStream, name: string) {
86
+ if (Buffer.isBuffer(file)) {
87
+ data.append("files", file, name);
88
+ } else if (file instanceof ReadStream) {
89
+ data.append("files", file, name);
90
+ } else {
91
+ await promises.access(file, constants.R_OK);
92
+ data.append("files", createReadStream(file), name);
93
+ }
94
+ }
95
+
96
+ public static async customize(
97
+ data: FormData,
98
+ options: ConversionOptions
99
+ ): Promise<void> {
100
+ if (options.pdfFormat) {
101
+ data.append("pdfa", options.pdfFormat);
102
+ }
103
+
104
+ if (options.pdfUA) {
105
+ data.append("pdfua", String(options.pdfUA));
106
+ }
107
+
108
+ if (options.header) {
109
+ const {header} = options;
110
+ await ConverterUtils.addFile(data, header, "header.html")
111
+ }
112
+
113
+ if (options.footer) {
114
+ const {footer} = options;
115
+ await ConverterUtils.addFile(data, footer, "footer.html")
116
+ }
117
+
118
+ if (options.emulatedMediaType) {
119
+ data.append("emulatedMediaType", options.emulatedMediaType);
120
+ }
121
+
122
+ if (options.properties) {
123
+ ConverterUtils.addPageProperties(data, options.properties);
124
+ }
125
+
126
+ if (options.waitDelay) {
127
+ data.append("waitDelay", options.waitDelay);
128
+ }
129
+
130
+ if (options.waitForExpression) {
131
+ data.append("waitForExpression", options.waitForExpression);
132
+ }
133
+
134
+ if (options.userAgent) {
135
+ data.append("userAgent", options.userAgent);
136
+ }
137
+
138
+ if (options.extraHttpHeaders) {
139
+ data.append("extraHttpHeaders", JSON.stringify(options.extraHttpHeaders));
140
+ }
141
+
142
+ if (options.failOnConsoleExceptions) {
143
+ data.append(
144
+ "failOnConsoleExceptions",
145
+ String(options.failOnConsoleExceptions)
146
+ );
147
+ }
23
148
  }
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
- await promises.access(options.header, constants.R_OK);
98
- data.append("header.html", createReadStream(options.header));
99
- }
100
-
101
- if (options.footer) {
102
- await promises.access(options.footer, constants.R_OK);
103
- data.append("footer.html", createReadStream(options.footer));
104
- }
105
-
106
- if (options.emulatedMediaType) {
107
- data.append("emulatedMediaType", options.emulatedMediaType);
108
- }
109
-
110
- if (options.properties) {
111
- ConverterUtils.injectPageProperties(data, options.properties);
112
- }
113
-
114
- if (options.waitDelay) {
115
- data.append("waitDelay", options.waitDelay);
116
- }
117
-
118
- if (options.waitForExpression) {
119
- data.append("waitForExpression", options.waitForExpression);
120
- }
121
-
122
- if (options.userAgent) {
123
- data.append("userAgent", options.userAgent);
124
- }
125
-
126
- if (options.extraHttpHeaders) {
127
- data.append("extraHttpHeaders", JSON.stringify(options.extraHttpHeaders));
128
- }
129
-
130
- if (options.failOnConsoleExceptions) {
131
- data.append(
132
- "failOnConsoleExceptions",
133
- String(options.failOnConsoleExceptions)
134
- );
135
- }
136
- }
137
149
  }