chromiumly 3.3.0 → 3.3.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.
Files changed (48) hide show
  1. package/README.md +1 -0
  2. package/dist/pdf-engines/utils/pdf-engines.utils.js +5 -5
  3. package/dist/pdf-engines/utils/pdf-engines.utils.js.map +1 -1
  4. package/package.json +11 -8
  5. package/src/.prettierrc.yml +0 -4
  6. package/src/chromium/converters/converter.ts +0 -22
  7. package/src/chromium/converters/html.converter.ts +0 -134
  8. package/src/chromium/converters/markdown.converter.ts +0 -129
  9. package/src/chromium/converters/tests/html.converter.test.ts +0 -190
  10. package/src/chromium/converters/tests/markdown.converter.test.ts +0 -187
  11. package/src/chromium/converters/tests/url.converter.test.ts +0 -164
  12. package/src/chromium/converters/url.converter.ts +0 -125
  13. package/src/chromium/index.ts +0 -6
  14. package/src/chromium/interfaces/common.types.ts +0 -15
  15. package/src/chromium/interfaces/converter.types.ts +0 -45
  16. package/src/chromium/interfaces/screenshot.types.ts +0 -15
  17. package/src/chromium/screenshots/html.screenshot.ts +0 -105
  18. package/src/chromium/screenshots/markdown.screenshot.ts +0 -100
  19. package/src/chromium/screenshots/screenshot.ts +0 -22
  20. package/src/chromium/screenshots/tests/html.screenshot.test.ts +0 -192
  21. package/src/chromium/screenshots/tests/markdown.screenshot.test.ts +0 -176
  22. package/src/chromium/screenshots/tests/url.screenshot.test.ts +0 -166
  23. package/src/chromium/screenshots/url.screenshot.ts +0 -96
  24. package/src/chromium/utils/converter.utils.ts +0 -187
  25. package/src/chromium/utils/screenshot.utils.ts +0 -127
  26. package/src/chromium/utils/tests/converter.utils.test.ts +0 -496
  27. package/src/chromium/utils/tests/screenshot.utils.test.ts +0 -338
  28. package/src/common/constants.ts +0 -9
  29. package/src/common/gotenberg.utils.ts +0 -86
  30. package/src/common/index.ts +0 -3
  31. package/src/common/tests/gotenberg.utils.test.ts +0 -141
  32. package/src/common/types.ts +0 -7
  33. package/src/gotenberg.ts +0 -54
  34. package/src/libre-office/index.ts +0 -1
  35. package/src/libre-office/interfaces/libre-office.types.ts +0 -156
  36. package/src/libre-office/libre-office.ts +0 -61
  37. package/src/libre-office/tests/libre-office.test.ts +0 -56
  38. package/src/libre-office/utils/constants.ts +0 -132
  39. package/src/libre-office/utils/libre-office.utils.ts +0 -128
  40. package/src/libre-office/utils/tests/libre-office.utils.test.ts +0 -156
  41. package/src/main.config.ts +0 -157
  42. package/src/main.ts +0 -13
  43. package/src/pdf-engines/index.ts +0 -1
  44. package/src/pdf-engines/interfaces/pdf-engines.types.ts +0 -10
  45. package/src/pdf-engines/pdf-engines.ts +0 -156
  46. package/src/pdf-engines/tests/pdf.engine.test.ts +0 -163
  47. package/src/pdf-engines/utils/pdf-engines.utils.ts +0 -68
  48. package/src/pdf-engines/utils/tests/pdf-engines.utils.test.ts +0 -71
@@ -1,187 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { createReadStream, promises } from 'fs';
3
-
4
- import FormData from 'form-data';
5
- import fetch from 'node-fetch';
6
-
7
- import { PdfFormat } from '../../../common';
8
- import { MarkdownConverter } from '../markdown.converter';
9
-
10
- const { Response } = jest.requireActual('node-fetch');
11
- jest.mock('node-fetch', () => jest.fn());
12
-
13
- describe('MarkdownConverter', () => {
14
- const converter = new MarkdownConverter();
15
-
16
- describe('endpoint', () => {
17
- it('should route to Chromium Markdown route', () => {
18
- expect(converter.endpoint).toEqual(
19
- 'http://localhost:3000/forms/chromium/convert/markdown'
20
- );
21
- });
22
- });
23
-
24
- describe('convert', () => {
25
- const mockPromisesAccess = jest.spyOn(promises, 'access');
26
- const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
27
- const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
28
-
29
- beforeEach(() => {
30
- (createReadStream as jest.Mock) = jest.fn();
31
- });
32
-
33
- afterEach(() => {
34
- jest.resetAllMocks();
35
- });
36
-
37
- describe('when html and markdown parameters are passed', () => {
38
- it('should return a buffer', async () => {
39
- mockFetch.mockResolvedValue(new Response('content'));
40
- const buffer = await converter.convert({
41
- html: Buffer.from('data'),
42
- markdown: Buffer.from('markdown')
43
- });
44
- expect(buffer).toEqual(Buffer.from('content'));
45
- });
46
- });
47
-
48
- describe('when pdf format parameter is passed', () => {
49
- it('should return a buffer', async () => {
50
- mockFetch.mockResolvedValue(new Response('content'));
51
- const buffer = await converter.convert({
52
- html: Buffer.from('data'),
53
- markdown: Buffer.from('markdown'),
54
- pdfFormat: PdfFormat.A_2b
55
- });
56
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
57
- expect(buffer).toEqual(Buffer.from('content'));
58
- });
59
- });
60
-
61
- describe('when page properties parameter is passed', () => {
62
- it('should return a buffer', async () => {
63
- mockFetch.mockResolvedValue(new Response('content'));
64
- const buffer = await converter.convert({
65
- html: Buffer.from('data'),
66
- markdown: Buffer.from('markdown'),
67
- properties: { size: { width: 8.3, height: 11.7 } }
68
- });
69
- expect(mockFormDataAppend).toHaveBeenCalledTimes(4);
70
- expect(buffer).toEqual(Buffer.from('content'));
71
- });
72
- });
73
-
74
- describe('when header parameter is passed', () => {
75
- it('should return a buffer', async () => {
76
- mockFetch.mockResolvedValue(new Response('content'));
77
- const buffer = await converter.convert({
78
- html: Buffer.from('data'),
79
- markdown: Buffer.from('markdown'),
80
- header: Buffer.from('header')
81
- });
82
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
83
- expect(buffer).toEqual(Buffer.from('content'));
84
- });
85
- });
86
-
87
- describe('when footer parameter is passed', () => {
88
- it('should return a buffer', async () => {
89
- mockFetch.mockResolvedValue(new Response('content'));
90
- const buffer = await converter.convert({
91
- html: Buffer.from('data'),
92
- markdown: Buffer.from('markdown'),
93
- footer: Buffer.from('footer')
94
- });
95
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
96
- expect(buffer).toEqual(Buffer.from('content'));
97
- });
98
- });
99
-
100
- describe('when emulatedMediaType parameter is passed', () => {
101
- it('should return a buffer', async () => {
102
- mockFetch.mockResolvedValue(new Response('content'));
103
- const buffer = await converter.convert({
104
- html: Buffer.from('data'),
105
- markdown: Buffer.from('markdown'),
106
- emulatedMediaType: 'screen'
107
- });
108
-
109
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
110
- expect(buffer).toEqual(Buffer.from('content'));
111
- });
112
- });
113
-
114
- describe('when failOnHttpStatusCodes parameter is passed', () => {
115
- it('should return a buffer', async () => {
116
- mockFetch.mockResolvedValue(new Response('content'));
117
- const buffer = await converter.convert({
118
- html: Buffer.from('data'),
119
- markdown: Buffer.from('markdown'),
120
- failOnHttpStatusCodes: [499, 599]
121
- });
122
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
123
- expect(buffer).toEqual(Buffer.from('content'));
124
- });
125
- });
126
-
127
- describe('when skipNetworkIdleEvent parameter is passed', () => {
128
- it('should return a buffer', async () => {
129
- mockFetch.mockResolvedValue(new Response('content'));
130
- const buffer = await converter.convert({
131
- html: Buffer.from('data'),
132
- markdown: Buffer.from('markdown'),
133
- skipNetworkIdleEvent: true
134
- });
135
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
136
- expect(buffer).toEqual(Buffer.from('content'));
137
- });
138
- });
139
-
140
- describe('when all parameters are passed', () => {
141
- it('should return a buffer', async () => {
142
- mockFetch.mockResolvedValue(new Response('content'));
143
- const buffer = await converter.convert({
144
- html: Buffer.from('data'),
145
- markdown: Buffer.from('markdown'),
146
- header: Buffer.from('header'),
147
- footer: Buffer.from('footer'),
148
- pdfFormat: PdfFormat.A_1a,
149
- emulatedMediaType: 'screen',
150
- properties: { size: { width: 8.3, height: 11.7 } }
151
- });
152
- expect(mockFormDataAppend).toHaveBeenCalledTimes(8);
153
- expect(buffer).toEqual(Buffer.from('content'));
154
- });
155
- });
156
-
157
- describe('when file does not exist', () => {
158
- it('should throw an error', async () => {
159
- const errorMessage =
160
- "ENOENT: no such file or directory, access 'path/to/index.html'";
161
- mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
162
-
163
- await expect(() =>
164
- converter.convert({
165
- html: 'path/to/index.html',
166
- markdown: 'path/to/file.md'
167
- })
168
- ).rejects.toThrow(errorMessage);
169
- });
170
- });
171
-
172
- describe('when fetch request fails', () => {
173
- it('should throw an error', async () => {
174
- const errorMessage =
175
- 'FetchError: request to http://localhost:3000/forms/chromium/convert/html failed';
176
- mockPromisesAccess.mockResolvedValue();
177
- mockFetch.mockRejectedValue(new Error(errorMessage));
178
- await expect(() =>
179
- converter.convert({
180
- html: 'path/to/index.html',
181
- markdown: 'path/to/file.md'
182
- })
183
- ).rejects.toThrow(errorMessage);
184
- });
185
- });
186
- });
187
- });
@@ -1,164 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
- import { createReadStream } from 'fs';
3
- import FormData from 'form-data';
4
- import fetch from 'node-fetch';
5
-
6
- import { PdfFormat } from '../../../common';
7
- import { UrlConverter } from '../url.converter';
8
-
9
- const { Response } = jest.requireActual('node-fetch');
10
- jest.mock('node-fetch', () => jest.fn());
11
-
12
- describe('HtmlConverter', () => {
13
- const converter = new UrlConverter();
14
-
15
- describe('endpoint', () => {
16
- it('should route to Chromium HTML route', () => {
17
- expect(converter.endpoint).toEqual(
18
- 'http://localhost:3000/forms/chromium/convert/url'
19
- );
20
- });
21
- });
22
-
23
- describe('convert', () => {
24
- const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
25
- const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
26
-
27
- beforeEach(() => {
28
- (createReadStream as jest.Mock) = jest.fn();
29
- });
30
-
31
- afterEach(() => {
32
- jest.resetAllMocks();
33
- });
34
-
35
- describe('when URL is valid', () => {
36
- it('should return a buffer', async () => {
37
- mockFetch.mockResolvedValueOnce(new Response('content'));
38
- const buffer = await converter.convert({
39
- url: 'http://www.example.com/'
40
- });
41
- expect(buffer).toEqual(Buffer.from('content'));
42
- });
43
- });
44
-
45
- describe('when header parameter is passed', () => {
46
- it('should return a buffer', async () => {
47
- mockFetch.mockResolvedValueOnce(new Response('content'));
48
- const buffer = await converter.convert({
49
- url: 'http://www.example.com/',
50
- header: Buffer.from('header')
51
- });
52
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
53
- expect(buffer).toEqual(Buffer.from('content'));
54
- });
55
- });
56
-
57
- describe('when footer parameter is passed', () => {
58
- it('should return a buffer', async () => {
59
- mockFetch.mockResolvedValueOnce(new Response('content'));
60
- const buffer = await converter.convert({
61
- url: 'http://www.example.com/',
62
- footer: Buffer.from('footer')
63
- });
64
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
65
- expect(buffer).toEqual(Buffer.from('content'));
66
- });
67
- });
68
-
69
- describe('when pdf format parameter is passed', () => {
70
- it('should return a buffer', async () => {
71
- mockFetch.mockResolvedValueOnce(new Response('content'));
72
- const buffer = await converter.convert({
73
- url: 'http://www.example.com/',
74
- pdfFormat: PdfFormat.A_3b
75
- });
76
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
77
- expect(buffer).toEqual(Buffer.from('content'));
78
- });
79
- });
80
-
81
- describe('when page properties parameter is passed', () => {
82
- it('should return a buffer', async () => {
83
- mockFetch.mockResolvedValueOnce(new Response('content'));
84
- const buffer = await converter.convert({
85
- url: 'http://www.example.com/',
86
- properties: { size: { width: 8.3, height: 11.7 } }
87
- });
88
- expect(mockFormDataAppend).toHaveBeenCalledTimes(3);
89
- expect(buffer).toEqual(Buffer.from('content'));
90
- });
91
- });
92
-
93
- describe('when emulatedMediaType parameter is passed', () => {
94
- it('should return a buffer', async () => {
95
- mockFetch.mockResolvedValue(new Response('content'));
96
- const buffer = await converter.convert({
97
- url: 'http://www.example.com/',
98
- emulatedMediaType: 'screen'
99
- });
100
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
101
- expect(buffer).toEqual(Buffer.from('content'));
102
- });
103
- });
104
-
105
- describe('when failOnHttpStatusCodes parameter is passed', () => {
106
- it('should return a buffer', async () => {
107
- mockFetch.mockResolvedValue(new Response('content'));
108
- const buffer = await converter.convert({
109
- url: 'http://www.example.com/',
110
- failOnHttpStatusCodes: [499, 599]
111
- });
112
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
113
- expect(buffer).toEqual(Buffer.from('content'));
114
- });
115
- });
116
-
117
- describe('when skipNetworkIdleEvent parameter is passed', () => {
118
- it('should return a buffer', async () => {
119
- mockFetch.mockResolvedValue(new Response('content'));
120
- const buffer = await converter.convert({
121
- url: 'http://www.example.com/',
122
- skipNetworkIdleEvent: true
123
- });
124
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
125
- expect(buffer).toEqual(Buffer.from('content'));
126
- });
127
- });
128
-
129
- describe('when all parameters are passed', () => {
130
- it('should return a buffer', async () => {
131
- mockFetch.mockResolvedValue(new Response('content'));
132
- const buffer = await converter.convert({
133
- url: 'http://www.example.com/',
134
- header: Buffer.from('header'),
135
- footer: Buffer.from('footer'),
136
- pdfFormat: PdfFormat.A_1a,
137
- emulatedMediaType: 'screen',
138
- properties: { size: { width: 8.3, height: 11.7 } }
139
- });
140
- expect(mockFormDataAppend).toHaveBeenCalledTimes(7);
141
- expect(buffer).toEqual(Buffer.from('content'));
142
- });
143
- });
144
-
145
- describe('when URL is invalid', () => {
146
- it('should throw an error', async () => {
147
- await expect(() =>
148
- converter.convert({ url: 'invalid url' })
149
- ).rejects.toThrow('Invalid URL');
150
- });
151
- });
152
-
153
- describe('when fetch request fails', () => {
154
- it('should throw an error', async () => {
155
- const errorMessage =
156
- 'FetchError: request to http://localhost:3000/forms/chromium/convert/html failed';
157
- mockFetch.mockRejectedValueOnce(new Error(errorMessage));
158
- await expect(() =>
159
- converter.convert({ url: 'http://www.example.com/' })
160
- ).rejects.toThrow(errorMessage);
161
- });
162
- });
163
- });
164
- });
@@ -1,125 +0,0 @@
1
- import { URL } from 'url';
2
- import FormData from 'form-data';
3
- import {
4
- GotenbergUtils,
5
- PdfFormat,
6
- PathLikeOrReadStream,
7
- Metadata
8
- } from '../../common';
9
- import { Cookie, PageProperties } from '../interfaces/converter.types';
10
- import { ConverterUtils } from '../utils/converter.utils';
11
- import { Converter } from './converter';
12
- import { ChromiumRoute, Chromiumly } from '../../main.config';
13
- import { EmulatedMediaType } from '../interfaces/common.types';
14
-
15
- /**
16
- * Class representing a URL converter that extends the base Converter class.
17
- * This class is used to convert content from a URL to PDF using Gotenberg service.
18
- *
19
- * @extends Converter
20
- */
21
- export class UrlConverter extends Converter {
22
- /**
23
- * Creates an instance of UrlConverter.
24
- * Initializes the converter with the URL conversion route.
25
- */
26
- constructor() {
27
- super(ChromiumRoute.URL);
28
- }
29
-
30
- /**
31
- * Converts content from a URL to PDF.
32
- *
33
- * @param {Object} options - Conversion options.
34
- * @param {string} options.url - The URL of the content to be converted to PDF.
35
- * @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
36
- * @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
37
- * @param {PageProperties} [options.properties] - Page properties for the conversion.
38
- * @param {PdfFormat} [options.pdfFormat] - PDF format options.
39
- * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
40
- * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the conversion.
41
- * @param {string} [options.waitDelay] - Delay before the conversion process starts.
42
- * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the conversion.
43
- * @param {string} [options.userAgent] - User agent string to use during the conversion.
44
- * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the conversion.
45
- * @param {number[]} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
46
- * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during conversion.
47
- * @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
48
- * @param {Metadata} options.metadata - Metadata to be written.
49
- * @param {Cookie[]} options.cookies - Cookies to be written.
50
- * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
51
- */
52
- async convert({
53
- url,
54
- header,
55
- footer,
56
- properties,
57
- pdfFormat,
58
- pdfUA,
59
- emulatedMediaType,
60
- waitDelay,
61
- waitForExpression,
62
- userAgent,
63
- extraHttpHeaders,
64
- failOnHttpStatusCodes,
65
- failOnConsoleExceptions,
66
- skipNetworkIdleEvent,
67
- metadata,
68
- cookies
69
- }: {
70
- url: string;
71
- header?: PathLikeOrReadStream;
72
- footer?: PathLikeOrReadStream;
73
- properties?: PageProperties;
74
- /**
75
- * @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for pdfFormat.
76
- * @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
77
- */
78
- pdfFormat?: PdfFormat;
79
- pdfUA?: boolean;
80
- emulatedMediaType?: EmulatedMediaType;
81
- waitDelay?: string;
82
- waitForExpression?: string;
83
- /**
84
- * @deprecated Starting from Gotenberg version 8.0.0, Chromium no longer provides support for userAgent.
85
- * @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
86
- */
87
- userAgent?: string;
88
- extraHttpHeaders?: Record<string, string>;
89
- failOnHttpStatusCodes?: number[];
90
- failOnConsoleExceptions?: boolean;
91
- skipNetworkIdleEvent?: boolean;
92
- metadata?: Metadata;
93
- cookies?: Cookie[];
94
- }): Promise<Buffer> {
95
- const _url = new URL(url);
96
- const data = new FormData();
97
-
98
- data.append('url', _url.href);
99
-
100
- await ConverterUtils.customize(data, {
101
- header,
102
- footer,
103
- properties,
104
- pdfFormat,
105
- pdfUA,
106
- emulatedMediaType,
107
- waitDelay,
108
- waitForExpression,
109
- userAgent,
110
- extraHttpHeaders,
111
- failOnHttpStatusCodes,
112
- failOnConsoleExceptions,
113
- skipNetworkIdleEvent,
114
- metadata,
115
- cookies
116
- });
117
-
118
- return GotenbergUtils.fetch(
119
- this.endpoint,
120
- data,
121
- Chromiumly.getGotenbergApiBasicAuthUsername(),
122
- Chromiumly.getGotenbergApiBasicAuthPassword()
123
- );
124
- }
125
- }
@@ -1,6 +0,0 @@
1
- export { UrlScreenshot } from './screenshots/url.screenshot';
2
- export { MarkdownScreenshot } from './screenshots/markdown.screenshot';
3
- export { HtmlScreenshot } from './screenshots/html.screenshot';
4
- export { HtmlConverter } from './converters/html.converter';
5
- export { MarkdownConverter } from './converters/markdown.converter';
6
- export { UrlConverter } from './converters/url.converter';
@@ -1,15 +0,0 @@
1
- import { PathLikeOrReadStream } from '../../common';
2
-
3
- export type EmulatedMediaType = 'screen' | 'print';
4
-
5
- export type ChromiumOptions = {
6
- header?: PathLikeOrReadStream;
7
- footer?: PathLikeOrReadStream;
8
- emulatedMediaType?: EmulatedMediaType;
9
- waitDelay?: string; // Duration (e.g, '5s') to wait when loading an HTML document before conversion.
10
- waitForExpression?: string; // JavaScript's expression to wait before converting an HTML document into PDF until it returns true.
11
- extraHttpHeaders?: Record<string, string>;
12
- failOnHttpStatusCodes?: number[]; // Return a 409 Conflict response if the HTTP status code is in the list (default [499,599])
13
- failOnConsoleExceptions?: boolean; // Return a 409 Conflict response if there are exceptions in the Chromium console (default false)
14
- skipNetworkIdleEvent?: boolean; // Do not wait for Chromium network to be idle (default false)
15
- };
@@ -1,45 +0,0 @@
1
- import { Metadata, PdfFormat } from '../../common';
2
- import { ChromiumOptions } from './common.types';
3
-
4
- type PageSize = {
5
- width: number; // Paper width, in inches (default 8.5)
6
- height: number; //Paper height, in inches (default 11)
7
- };
8
-
9
- 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)
14
- };
15
-
16
- export type PageProperties = {
17
- singlePage?: boolean; // Print the entire content in one single page (default false)
18
- size?: PageSize;
19
- margins?: PageMargins;
20
- preferCssPageSize?: boolean; // Define whether to prefer page size as defined by CSS (default false)
21
- printBackground?: boolean; // Print the background graphics (default false)
22
- omitBackground?: boolean; // Hide the default white background and allow generating PDFs with transparency (default false)
23
- landscape?: boolean; // Set the paper orientation to landscape (default false)
24
- scale?: number; // The scale of the page rendering (default 1.0)
25
- nativePageRanges?: { from: number; to: number }; // Page ranges to print
26
- };
27
-
28
- export type Cookie = {
29
- name: string;
30
- value: string;
31
- domain: string;
32
- path?: string;
33
- secure?: boolean;
34
- httpOnly?: boolean;
35
- sameSite?: 'Strict' | 'Lax' | 'None';
36
- };
37
-
38
- export type ConversionOptions = ChromiumOptions & {
39
- properties?: PageProperties;
40
- pdfFormat?: PdfFormat;
41
- pdfUA?: boolean; // Enable PDF for Universal Access for optimal accessibility (default false)
42
- userAgent?: string;
43
- metadata?: Metadata;
44
- cookies?: Cookie[];
45
- };
@@ -1,15 +0,0 @@
1
- import { ChromiumOptions } from './common.types';
2
-
3
- export type ImageProperties = {
4
- format: 'png' | 'jpeg' | 'webp'; //The image compression format, either "png", "jpeg" or "webp".
5
- quality?: number; // The compression quality from range 0 to 100 (jpeg only).
6
- omitBackground?: boolean; // Hide the default white background and allow generating screenshots with transparency.
7
- width?: number; // The device screen width in pixels (default 800).
8
- height?: number; // The device screen height in pixels (default 600).
9
- clip?: boolean; // Define whether to clip the screenshot according to the device dimensions (default false).
10
- };
11
-
12
- export type ScreenshotOptions = ChromiumOptions & {
13
- properties?: ImageProperties;
14
- optimizeForSpeed?: boolean; // Define whether to optimize image encoding for speed, not for resulting size.
15
- };
@@ -1,105 +0,0 @@
1
- import FormData from 'form-data';
2
-
3
- import { GotenbergUtils, PathLikeOrReadStream } from '../../common';
4
- import { ChromiumRoute, Chromiumly } from '../../main.config';
5
- import { EmulatedMediaType } from '../interfaces/common.types';
6
- import { ScreenshotUtils } from '../utils/screenshot.utils';
7
- import { Screenshot } from './screenshot';
8
- import { ImageProperties } from '../interfaces/screenshot.types';
9
-
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
- export class HtmlScreenshot extends Screenshot {
17
- /**
18
- * Creates an instance of HtmlScreenshot.
19
- * Initializes the Screenshot with the HTML screenshot route.
20
- */
21
- constructor() {
22
- super(ChromiumRoute.HTML);
23
- }
24
-
25
- /**
26
- * Screenshots HTML content.
27
- *
28
- * @param {Object} options - Screenshot options.
29
- * @param {PathLikeOrReadStream} options.html - PathLike or ReadStream of the HTML content to be screenshoted.
30
- * @param {PathLikeOrReadStream} [options.header] - PathLike or ReadStream of the header HTML content.
31
- * @param {PathLikeOrReadStream} [options.footer] - PathLike or ReadStream of the footer HTML content.
32
- * @param {ImageProperties} [options.properties] - Image properties for the screenshot.
33
- * @param {EmulatedMediaType} [options.emulatedMediaType] - Emulated media type for the screenshot.
34
- * @param {string} [options.waitDelay] - Delay before the screenshot process starts.
35
- * @param {string} [options.waitForExpression] - JavaScript expression to wait for before completing the screenshot.
36
- * @param {Record<string, string>} [options.extraHttpHeaders] - Additional HTTP headers for the screenshot.
37
- * @param {number []} [options.failOnHttpStatusCodes] - Whether to fail on HTTP status code.
38
- * @param {boolean} [options.failOnConsoleExceptions] - Whether to fail on console exceptions during screenshot.
39
- * @param {boolean} [options.skipNetworkIdleEvent] - Whether to skip network idle event.
40
- * @param {boolean} [options.optimizeForSpeed] - Whether to optimize for speed.
41
- * @returns {Promise<Buffer>} A Promise resolving to the image buffer.
42
- */
43
- async capture({
44
- html,
45
- assets,
46
- header,
47
- footer,
48
- properties,
49
- emulatedMediaType,
50
- waitDelay,
51
- waitForExpression,
52
- extraHttpHeaders,
53
- failOnConsoleExceptions,
54
- failOnHttpStatusCodes,
55
- skipNetworkIdleEvent,
56
- optimizeForSpeed
57
- }: {
58
- html: PathLikeOrReadStream;
59
- assets?: { file: PathLikeOrReadStream; name: string }[];
60
- header?: PathLikeOrReadStream;
61
- footer?: PathLikeOrReadStream;
62
- properties?: ImageProperties;
63
- emulatedMediaType?: EmulatedMediaType;
64
- waitDelay?: string;
65
- waitForExpression?: string;
66
- extraHttpHeaders?: Record<string, string>;
67
- failOnConsoleExceptions?: boolean;
68
- failOnHttpStatusCodes?: number[];
69
- skipNetworkIdleEvent?: boolean;
70
- optimizeForSpeed?: boolean;
71
- }): Promise<Buffer> {
72
- const data = new FormData();
73
-
74
- await GotenbergUtils.addFile(data, html, 'index.html');
75
-
76
- if (assets?.length) {
77
- await Promise.all(
78
- assets.map(({ file, name }) =>
79
- GotenbergUtils.addFile(data, file, name)
80
- )
81
- );
82
- }
83
-
84
- await ScreenshotUtils.customize(data, {
85
- header,
86
- footer,
87
- properties,
88
- emulatedMediaType,
89
- waitDelay,
90
- waitForExpression,
91
- extraHttpHeaders,
92
- failOnHttpStatusCodes,
93
- failOnConsoleExceptions,
94
- skipNetworkIdleEvent,
95
- optimizeForSpeed
96
- });
97
-
98
- return GotenbergUtils.fetch(
99
- this.endpoint,
100
- data,
101
- Chromiumly.getGotenbergApiBasicAuthUsername(),
102
- Chromiumly.getGotenbergApiBasicAuthPassword()
103
- );
104
- }
105
- }