chromiumly 2.9.0 → 3.0.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 (46) hide show
  1. package/README.md +46 -26
  2. package/dist/libre-office/index.d.ts +1 -2
  3. package/dist/libre-office/index.js +3 -3
  4. package/dist/libre-office/index.js.map +1 -1
  5. package/dist/libre-office/interfaces/libre-office.types.d.ts +9 -0
  6. package/dist/libre-office/libre-office.d.ts +27 -0
  7. package/dist/libre-office/libre-office.js +41 -0
  8. package/dist/libre-office/libre-office.js.map +1 -0
  9. package/dist/libre-office/utils/constants.js +102 -53
  10. package/dist/libre-office/utils/constants.js.map +1 -1
  11. package/dist/libre-office/utils/libre-office.utils.d.ts +9 -1
  12. package/dist/libre-office/utils/libre-office.utils.js +29 -0
  13. package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
  14. package/dist/main.d.ts +2 -1
  15. package/dist/main.js +4 -2
  16. package/dist/main.js.map +1 -1
  17. package/dist/pdf-engines/index.d.ts +1 -1
  18. package/dist/pdf-engines/index.js +3 -3
  19. package/dist/pdf-engines/index.js.map +1 -1
  20. package/dist/pdf-engines/interfaces/pdf-engines.types.d.ts +8 -0
  21. package/dist/pdf-engines/interfaces/pdf-engines.types.js +3 -0
  22. package/dist/pdf-engines/interfaces/pdf-engines.types.js.map +1 -0
  23. package/dist/pdf-engines/{pdf.engine.d.ts → pdf-engines.d.ts} +9 -15
  24. package/dist/pdf-engines/{pdf.engine.js → pdf-engines.js} +22 -28
  25. package/dist/pdf-engines/pdf-engines.js.map +1 -0
  26. package/dist/pdf-engines/utils/{engine.utils.d.ts → pdf-engines.utils.d.ts} +10 -1
  27. package/dist/pdf-engines/utils/{engine.utils.js → pdf-engines.utils.js} +24 -4
  28. package/dist/pdf-engines/utils/pdf-engines.utils.js.map +1 -0
  29. package/package.json +5 -5
  30. package/src/chromium/interfaces/common.types.ts +1 -1
  31. package/src/libre-office/index.ts +1 -2
  32. package/src/libre-office/interfaces/libre-office.types.ts +11 -0
  33. package/src/libre-office/libre-office.ts +58 -0
  34. package/src/libre-office/tests/libre-office.test.ts +56 -0
  35. package/src/libre-office/utils/constants.ts +102 -53
  36. package/src/libre-office/utils/libre-office.utils.ts +43 -1
  37. package/src/libre-office/utils/tests/libre-office.utils.test.ts +15 -0
  38. package/src/main.ts +2 -1
  39. package/src/pdf-engines/index.ts +1 -1
  40. package/src/pdf-engines/interfaces/pdf-engines.types.ts +10 -0
  41. package/src/pdf-engines/{pdf.engine.ts → pdf-engines.ts} +27 -39
  42. package/src/pdf-engines/tests/pdf.engine.test.ts +20 -19
  43. package/src/pdf-engines/utils/{engine.utils.ts → pdf-engines.utils.ts} +29 -1
  44. package/src/pdf-engines/utils/tests/{engine.utils.test.ts → pdf-engines.utils.test.ts} +6 -7
  45. package/dist/pdf-engines/pdf.engine.js.map +0 -1
  46. package/dist/pdf-engines/utils/engine.utils.js.map +0 -1
@@ -1,18 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PDFEngine = void 0;
3
+ exports.PDFEngines = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = tslib_1.__importDefault(require("path"));
7
7
  const form_data_1 = tslib_1.__importDefault(require("form-data"));
8
8
  const main_config_1 = require("../main.config");
9
9
  const common_1 = require("../common");
10
- const libre_office_1 = require("../libre-office");
11
- const engine_utils_1 = require("./utils/engine.utils");
10
+ const pdf_engines_utils_1 = require("./utils/pdf-engines.utils");
12
11
  /**
13
- * Class representing a PDF engine for various operations such as merging and conversion.
12
+ * Class uses PDF engines for various operations such as merging and conversion.
14
13
  */
15
- class PDFEngine {
14
+ class PDFEngines {
16
15
  /**
17
16
  * Merges multiple PDF files into a single PDF document.
18
17
  *
@@ -21,9 +20,14 @@ class PDFEngine {
21
20
  * @returns {Promise<Buffer>} A Promise resolving to the merged PDF content as a Buffer.
22
21
  */
23
22
  static merge(_a) {
24
- return tslib_1.__awaiter(this, arguments, void 0, function* ({ files }) {
23
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ files, pdfa, pdfUA, metadata }) {
25
24
  const data = new form_data_1.default();
26
- yield engine_utils_1.PDFEngineUtils.addFiles(files, data);
25
+ yield pdf_engines_utils_1.PDFEnginesUtils.addFiles(files, data);
26
+ yield pdf_engines_utils_1.PDFEnginesUtils.customize(data, {
27
+ pdfa,
28
+ pdfUA,
29
+ metadata
30
+ });
27
31
  const endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.PDF_ENGINES_PATH}/${main_config_1.Chromiumly.PDF_ENGINE_ROUTES.merge}`;
28
32
  return common_1.GotenbergUtils.fetch(endpoint, data);
29
33
  });
@@ -33,28 +37,18 @@ class PDFEngine {
33
37
  *
34
38
  * @param {Object} options - Options for the conversion operation.
35
39
  * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the files to be converted to PDF.
36
- * @param {PageProperties} [options.properties] - Page properties for the conversion.
37
- * @param {PdfFormat} [options.pdfFormat] - PDF format options.
40
+ * @param {pdfa} [options.pdfa] - PDF format options.
38
41
  * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
39
- * @param {boolean} [options.merge] - Indicates whether to merge the resulting PDFs.
40
42
  * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
41
43
  */
42
44
  static convert(_a) {
43
- return tslib_1.__awaiter(this, arguments, void 0, function* ({ files, properties, pdfFormat, pdfUA, merge }) {
45
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ files, pdfa, pdfUA }) {
44
46
  const data = new form_data_1.default();
45
- if (pdfFormat) {
46
- data.append('pdfa', pdfFormat);
47
- }
48
- if (pdfUA) {
49
- data.append('pdfUA', String(pdfUA));
50
- }
51
- if (merge) {
52
- data.append('merge', String(merge));
53
- }
54
- if (properties) {
55
- libre_office_1.LibreOfficeUtils.addPageProperties(data, properties);
56
- }
57
- yield libre_office_1.LibreOfficeUtils.addFiles(files, data);
47
+ yield pdf_engines_utils_1.PDFEnginesUtils.addFiles(files, data);
48
+ yield pdf_engines_utils_1.PDFEnginesUtils.customize(data, {
49
+ pdfa,
50
+ pdfUA
51
+ });
58
52
  const endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.LIBRE_OFFICE_PATH}/${main_config_1.Chromiumly.LIBRE_OFFICE_ROUTES.convert}`;
59
53
  return common_1.GotenbergUtils.fetch(endpoint, data);
60
54
  });
@@ -68,7 +62,7 @@ class PDFEngine {
68
62
  static readMetadata(files) {
69
63
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
70
64
  const data = new form_data_1.default();
71
- yield engine_utils_1.PDFEngineUtils.addFiles(files, data);
65
+ yield pdf_engines_utils_1.PDFEnginesUtils.addFiles(files, data);
72
66
  const endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.PDF_ENGINES_PATH}/${main_config_1.Chromiumly.PDF_ENGINE_ROUTES.readMetadata}`;
73
67
  return common_1.GotenbergUtils.fetch(endpoint, data);
74
68
  });
@@ -84,7 +78,7 @@ class PDFEngine {
84
78
  return tslib_1.__awaiter(this, arguments, void 0, function* ({ files, metadata }) {
85
79
  const data = new form_data_1.default();
86
80
  data.append('metadata', JSON.stringify(metadata));
87
- yield engine_utils_1.PDFEngineUtils.addFiles(files, data);
81
+ yield pdf_engines_utils_1.PDFEnginesUtils.addFiles(files, data);
88
82
  const endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.PDF_ENGINES_PATH}/${main_config_1.Chromiumly.PDF_ENGINE_ROUTES.writeMetadata}`;
89
83
  return common_1.GotenbergUtils.fetch(endpoint, data);
90
84
  });
@@ -104,5 +98,5 @@ class PDFEngine {
104
98
  });
105
99
  }
106
100
  }
107
- exports.PDFEngine = PDFEngine;
108
- //# sourceMappingURL=pdf.engine.js.map
101
+ exports.PDFEngines = PDFEngines;
102
+ //# sourceMappingURL=pdf-engines.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-engines.js","sourceRoot":"","sources":["../../src/pdf-engines/pdf-engines.ts"],"names":[],"mappings":"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"}
@@ -1,9 +1,10 @@
1
1
  import FormData from 'form-data';
2
2
  import { PathLikeOrReadStream } from '../../common';
3
+ import { ConversionOptions, MergeOptions } from '../interfaces/pdf-engines.types';
3
4
  /**
4
5
  * Utility class for handling common tasks related to PDF engine operations.
5
6
  */
6
- export declare class PDFEngineUtils {
7
+ export declare class PDFEnginesUtils {
7
8
  /**
8
9
  * Adds PDF files to the FormData object.
9
10
  *
@@ -12,4 +13,12 @@ export declare class PDFEngineUtils {
12
13
  * @throws {Error} Throws an error if the file extension is not supported.
13
14
  */
14
15
  static addFiles(files: PathLikeOrReadStream[], data: FormData): Promise<void>;
16
+ /**
17
+ * Customizes the FormData object based on the provided conversion options.
18
+ *
19
+ * @param {FormData} data - The FormData object to be customized.
20
+ * @param {ConversionOptions | MergeOptions} options - The options to apply to the FormData.
21
+ * @returns {Promise<void>} A Promise that resolves once the customization is complete.
22
+ */
23
+ static customize(data: FormData, options: ConversionOptions | MergeOptions): Promise<void>;
15
24
  }
@@ -1,13 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PDFEngineUtils = void 0;
3
+ exports.PDFEnginesUtils = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs_1 = require("fs");
6
6
  const path_1 = tslib_1.__importDefault(require("path"));
7
7
  /**
8
8
  * Utility class for handling common tasks related to PDF engine operations.
9
9
  */
10
- class PDFEngineUtils {
10
+ class PDFEnginesUtils {
11
11
  /**
12
12
  * Adds PDF files to the FormData object.
13
13
  *
@@ -39,6 +39,26 @@ class PDFEngineUtils {
39
39
  }
40
40
  });
41
41
  }
42
+ /**
43
+ * Customizes the FormData object based on the provided conversion options.
44
+ *
45
+ * @param {FormData} data - The FormData object to be customized.
46
+ * @param {ConversionOptions | MergeOptions} options - The options to apply to the FormData.
47
+ * @returns {Promise<void>} A Promise that resolves once the customization is complete.
48
+ */
49
+ static customize(data, options) {
50
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
51
+ if (options.pdfa) {
52
+ data.append('pdfa', options.pdfa);
53
+ }
54
+ if (options.pdfUA) {
55
+ data.append('pdfUA', String(options.pdfUA));
56
+ }
57
+ if ('metadata' in options && options.metadata) {
58
+ data.append('metadata', JSON.stringify(options.metadata));
59
+ }
60
+ });
61
+ }
42
62
  }
43
- exports.PDFEngineUtils = PDFEngineUtils;
44
- //# sourceMappingURL=engine.utils.js.map
63
+ exports.PDFEnginesUtils = PDFEnginesUtils;
64
+ //# sourceMappingURL=pdf-engines.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-engines.utils.js","sourceRoot":"","sources":["../../../src/pdf-engines/utils/pdf-engines.utils.ts"],"names":[],"mappings":";;;;AAAA,2BAAuE;AACvE,wDAAwB;AASxB;;GAEG;AACH,MAAa,eAAe;IACxB;;;;;;OAMG;IACI,MAAM,CAAO,QAAQ,CACxB,KAA6B,EAC7B,IAAc;;YAEd,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;gBACxC,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;gBAClC,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;oBACxB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACzC,CAAC;qBAAM,IAAI,IAAI,YAAY,eAAU,EAAE,CAAC;oBACpC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACzC,CAAC;qBAAM,CAAC;oBACJ,MAAM,aAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;oBAC5C,MAAM,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;oBAChD,MAAM,SAAS,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;oBACzC,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;wBACvB,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC,CAAC;oBAClD,CAAC;yBAAM,CAAC;wBACJ,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,mBAAmB,CAAC,CAAC;oBACrD,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;KAAA;IAED;;;;;;OAMG;IACI,MAAM,CAAO,SAAS,CACzB,IAAc,EACd,OAAyC;;YAEzC,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;YACtC,CAAC;YAED,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YAChD,CAAC;YAED,IAAI,UAAU,IAAI,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBAC5C,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC9D,CAAC;QACL,CAAC;KAAA;CACJ;AAtDD,0CAsDC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chromiumly",
3
- "version": "2.9.0",
3
+ "version": "3.0.0",
4
4
  "description": "A lightweight Typescript library that interacts with Gotenberg's different modules to convert a variety of document formats to PDF files.",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -50,10 +50,10 @@
50
50
  "@types/dotenv": "8.2.0",
51
51
  "@types/form-data": "2.5.0",
52
52
  "@types/jest": "29.5.12",
53
- "@types/node": "20.11.30",
53
+ "@types/node": "20.12.5",
54
54
  "@types/node-fetch": "2.6.11",
55
- "@typescript-eslint/eslint-plugin": "7.3.1",
56
- "@typescript-eslint/parser": "7.3.1",
55
+ "@typescript-eslint/eslint-plugin": "7.5.0",
56
+ "@typescript-eslint/parser": "7.5.0",
57
57
  "commitizen": "4.3.0",
58
58
  "eslint": "8.57.0",
59
59
  "eslint-config-prettier": "^9.1.0",
@@ -67,7 +67,7 @@
67
67
  "ts-jest": "29.1.2",
68
68
  "ts-node": "10.9.2",
69
69
  "tslib": "2.6.2",
70
- "typescript": "5.4.3"
70
+ "typescript": "5.4.4"
71
71
  },
72
72
  "dependencies": {
73
73
  "config": "3.3.11",
@@ -6,7 +6,7 @@ export type ChromiumOptions = {
6
6
  header?: PathLikeOrReadStream;
7
7
  footer?: PathLikeOrReadStream;
8
8
  emulatedMediaType?: EmulatedMediaType;
9
- waitDelay?: string; // Duration (e.g, '5s') to wait when loading an HTML document before convertion.
9
+ waitDelay?: string; // Duration (e.g, '5s') to wait when loading an HTML document before conversion.
10
10
  waitForExpression?: string; // JavaScript's expression to wait before converting an HTML document into PDF until it returns true.
11
11
  extraHttpHeaders?: Record<string, string>;
12
12
  failOnHttpStatusCodes?: number[]; // Return a 409 Conflict response if the HTTP status code is in the list (default [499,599])
@@ -1,2 +1 @@
1
- export { PageProperties } from './interfaces/libre-office.types';
2
- export { LibreOfficeUtils } from './utils/libre-office.utils';
1
+ export { LibreOffice } from './libre-office';
@@ -1,4 +1,15 @@
1
+ import { Metadata, PdfFormat } from '../../common';
2
+
1
3
  export type PageProperties = {
2
4
  landscape?: boolean; // Set the paper orientation to landscape (default false)
3
5
  nativePageRanges?: { from: number; to: number }; // Page ranges to print
6
+ exportFormFields?: boolean; // Set whether to export the form fields or to use the inputted/selected content of the fields (default true)
7
+ };
8
+
9
+ export type ConversionOptions = {
10
+ properties?: PageProperties;
11
+ merge?: boolean;
12
+ pdfa?: PdfFormat;
13
+ pdfUA?: boolean;
14
+ metadata?: Metadata;
4
15
  };
@@ -0,0 +1,58 @@
1
+ import FormData from 'form-data';
2
+
3
+ import { Chromiumly } from '../main.config';
4
+ import {
5
+ GotenbergUtils,
6
+ PathLikeOrReadStream,
7
+ PdfFormat,
8
+ Metadata
9
+ } from '../common';
10
+ import { PageProperties } from './interfaces/libre-office.types';
11
+ import { LibreOfficeUtils } from './utils/libre-office.utils';
12
+
13
+ /**
14
+ * Class representing a LibreOffice for various operations such as merging and conversion.
15
+ */
16
+ export class LibreOffice {
17
+ /**
18
+ * Converts various document formats to PDF.
19
+ *
20
+ * @param {Object} options - Options for the conversion operation.
21
+ * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the files to be converted to PDF.
22
+ * @param {PageProperties} [options.properties] - Page properties for the conversion.
23
+ * @param {pdfa} [options.pdfFormat] - PDF format options.
24
+ * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
25
+ * @param {boolean} [options.merge] - Indicates whether to merge the resulting PDFs.
26
+ * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
27
+ */
28
+ public static async convert({
29
+ files,
30
+ properties,
31
+ pdfa,
32
+ pdfUA,
33
+ merge,
34
+ metadata
35
+ }: {
36
+ files: PathLikeOrReadStream[];
37
+ properties?: PageProperties;
38
+ pdfa?: PdfFormat;
39
+ pdfUA?: boolean;
40
+ merge?: boolean;
41
+ metadata?: Metadata;
42
+ }): Promise<Buffer> {
43
+ const data = new FormData();
44
+
45
+ await LibreOfficeUtils.addFiles(files, data);
46
+ await LibreOfficeUtils.customize(data, {
47
+ properties,
48
+ merge,
49
+ pdfa,
50
+ pdfUA,
51
+ metadata
52
+ });
53
+
54
+ const endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.LIBRE_OFFICE_PATH}/${Chromiumly.LIBRE_OFFICE_ROUTES.convert}`;
55
+
56
+ return GotenbergUtils.fetch(endpoint, data);
57
+ }
58
+ }
@@ -0,0 +1,56 @@
1
+ import { LibreOffice } from '../libre-office';
2
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3
+ import { createReadStream, promises } from 'fs';
4
+ import FormData from 'form-data';
5
+ import fetch from 'node-fetch';
6
+ import { PdfFormat } from '../../common';
7
+
8
+ const { Response } = jest.requireActual('node-fetch');
9
+ jest.mock('node-fetch', () => jest.fn());
10
+
11
+ describe('LibreOffice', () => {
12
+ const mockPromisesAccess = jest.spyOn(promises, 'access');
13
+ const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
14
+ const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
15
+
16
+ beforeEach(() => {
17
+ (createReadStream as jest.Mock) = jest
18
+ .fn()
19
+ .mockImplementation((file) => file);
20
+ });
21
+
22
+ afterEach(() => {
23
+ jest.resetAllMocks();
24
+ });
25
+
26
+ describe('convert', () => {
27
+ describe('when no properties are passed', () => {
28
+ it('should return a buffer', async () => {
29
+ mockPromisesAccess.mockResolvedValue();
30
+ mockFetch.mockResolvedValue(new Response('content'));
31
+ const buffer = await LibreOffice.convert({
32
+ files: ['path/to/file.docx', 'path/to/file.bib']
33
+ });
34
+ expect(buffer).toEqual(Buffer.from('content'));
35
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
36
+ });
37
+ });
38
+
39
+ describe('when properties are passed', () => {
40
+ it('should return a buffer', async () => {
41
+ mockPromisesAccess.mockResolvedValue();
42
+ mockFetch.mockResolvedValue(new Response('content'));
43
+ const buffer = await LibreOffice.convert({
44
+ files: ['path/to/file.docx', 'path/to/file.bib'],
45
+ properties: { landscape: true },
46
+ pdfa: PdfFormat.A_2b,
47
+ pdfUA: true,
48
+ metadata: { author: 'John Doe' },
49
+ merge: true
50
+ });
51
+ expect(buffer).toEqual(Buffer.from('content'));
52
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(7);
53
+ });
54
+ });
55
+ });
56
+ });
@@ -1,83 +1,132 @@
1
1
  export const LIBRE_OFFICE_EXTENSIONS = [
2
+ '123',
3
+ '602',
4
+ 'abw',
2
5
  'bib',
6
+ 'bmp',
7
+ 'cdr',
8
+ 'cgm',
9
+ 'cmx',
10
+ 'csv',
11
+ 'cwk',
12
+ 'dbf',
13
+ 'dif',
3
14
  'doc',
4
- 'xml',
15
+ 'docm',
5
16
  'docx',
6
- 'fodt',
7
- 'html',
8
- 'ltx',
9
- 'txt',
10
- 'odt',
11
- 'ott',
12
- 'pdb',
13
- 'pdf',
14
- 'psw',
15
- 'rtf',
16
- 'sdw',
17
- 'stw',
18
- 'sxw',
19
- 'uot',
20
- 'vor',
21
- 'wps',
22
- 'epub',
23
- 'png',
24
- 'bmp',
17
+ 'dot',
18
+ 'dotm',
19
+ 'dotx',
20
+ 'dxf',
25
21
  'emf',
26
22
  'eps',
23
+ 'epub',
27
24
  'fodg',
25
+ 'fodp',
26
+ 'fods',
27
+ 'fodt',
28
+ 'fopd',
28
29
  'gif',
30
+ 'htm',
31
+ 'html',
32
+ 'hwp',
33
+ 'jpeg',
29
34
  'jpg',
35
+ 'key',
36
+ 'ltx',
37
+ 'lwp',
38
+ 'mcw',
30
39
  'met',
40
+ 'mml',
41
+ 'mw',
42
+ 'numbers',
31
43
  'odd',
44
+ 'odg',
45
+ 'odm',
46
+ 'odp',
47
+ 'ods',
48
+ 'odt',
32
49
  'otg',
50
+ 'oth',
51
+ 'otp',
52
+ 'ots',
53
+ 'ott',
54
+ 'pages',
33
55
  'pbm',
56
+ 'pcd',
34
57
  'pct',
58
+ 'pcx',
59
+ 'pdb',
60
+ 'pdf',
35
61
  'pgm',
62
+ 'png',
63
+ 'pot',
64
+ 'potm',
65
+ 'potx',
36
66
  'ppm',
67
+ 'pps',
68
+ 'ppt',
69
+ 'pptm',
70
+ 'pptx',
71
+ 'psd',
72
+ 'psw',
73
+ 'pub',
74
+ 'pwp',
75
+ 'pxl',
37
76
  'ras',
77
+ 'rtf',
78
+ 'sda',
79
+ 'sdc',
80
+ 'sdd',
81
+ 'sdp',
82
+ 'sdw',
83
+ 'sgl',
84
+ 'slk',
85
+ 'smf',
86
+ 'stc',
38
87
  'std',
88
+ 'sti',
89
+ 'stw',
39
90
  'svg',
40
91
  'svm',
41
92
  'swf',
93
+ 'sxc',
42
94
  'sxd',
95
+ 'sxg',
96
+ 'sxi',
97
+ 'sxm',
43
98
  'sxw',
99
+ 'tga',
100
+ 'tif',
44
101
  'tiff',
45
- 'xhtml',
46
- 'xpm',
47
- 'fodp',
48
- 'pages',
49
- 'potm',
50
- 'pot',
51
- 'pptx',
52
- 'pps',
53
- 'ppt',
54
- 'pwp',
55
- 'sda',
56
- 'sdd',
57
- 'sti',
58
- 'sxi',
102
+ 'txt',
103
+ 'uof',
59
104
  'uop',
60
- 'wmf',
61
- 'csv',
62
- 'dbf',
63
- 'dif',
64
- 'fods',
65
- 'ods',
66
- 'ots',
67
- 'pxl',
68
- 'sdc',
69
- 'slk',
70
- 'stc',
71
- 'sxc',
72
105
  'uos',
106
+ 'uot',
107
+ 'vdx',
108
+ 'vor',
109
+ 'vsd',
110
+ 'vsdm',
111
+ 'vsdx',
112
+ 'wb2',
113
+ 'wk1',
114
+ 'wks',
115
+ 'wmf',
116
+ 'wpd',
117
+ 'wpg',
118
+ 'wps',
119
+ 'xbm',
120
+ 'xhtml',
73
121
  'xls',
74
- 'xlt',
122
+ 'xlsb',
123
+ 'xlsm',
75
124
  'xlsx',
76
- 'tif',
77
- 'jpeg',
78
- 'odp',
79
- 'odg',
80
- 'dotx',
125
+ 'xlt',
126
+ 'xltm',
81
127
  'xltx',
82
- 'key'
128
+ 'xlw',
129
+ 'xml',
130
+ 'xpm',
131
+ 'zabw'
83
132
  ];
@@ -7,7 +7,10 @@ import FormData from 'form-data';
7
7
 
8
8
  import { GotenbergUtils, PathLikeOrReadStream } from '../../common';
9
9
  import { LIBRE_OFFICE_EXTENSIONS } from './constants';
10
- import { PageProperties } from '../interfaces/libre-office.types';
10
+ import {
11
+ ConversionOptions,
12
+ PageProperties
13
+ } from '../interfaces/libre-office.types';
11
14
 
12
15
  /**
13
16
  * Utility class for handling common tasks related to LibreOffice conversions.
@@ -81,5 +84,44 @@ export class LibreOfficeUtils {
81
84
  `${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
82
85
  );
83
86
  }
87
+
88
+ if (pageProperties.exportFormFields === false) {
89
+ data.append(
90
+ 'exportFormFields',
91
+ String(pageProperties.exportFormFields)
92
+ );
93
+ }
94
+ }
95
+
96
+ /**
97
+ * Customizes the FormData object based on the provided conversion options.
98
+ *
99
+ * @param {FormData} data - The FormData object to be customized.
100
+ * @param {ConversionOptions} options - The conversion options to apply to the FormData.
101
+ * @returns {Promise<void>} A Promise that resolves once the customization is complete.
102
+ */
103
+ public static async customize(
104
+ data: FormData,
105
+ options: ConversionOptions
106
+ ): Promise<void> {
107
+ if (options.pdfa) {
108
+ data.append('pdfa', options.pdfa);
109
+ }
110
+
111
+ if (options.pdfUA) {
112
+ data.append('pdfUA', String(options.pdfUA));
113
+ }
114
+
115
+ if (options.merge) {
116
+ data.append('merge', String(options.merge));
117
+ }
118
+
119
+ if (options.metadata) {
120
+ data.append('metadata', JSON.stringify(options.metadata));
121
+ }
122
+
123
+ if (options.properties) {
124
+ LibreOfficeUtils.addPageProperties(data, options.properties);
125
+ }
84
126
  }
85
127
  }
@@ -109,6 +109,21 @@ describe('LibreOfficeUtils', () => {
109
109
  });
110
110
  });
111
111
 
112
+ describe('Export form fields', () => {
113
+ describe('when exportFormFields parameter is set', () => {
114
+ it('should append exportFormFields to data', () => {
115
+ LibreOfficeUtils.addPageProperties(data, {
116
+ exportFormFields: false
117
+ });
118
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
119
+ expect(data.append).toHaveBeenCalledWith(
120
+ 'exportFormFields',
121
+ 'false'
122
+ );
123
+ });
124
+ });
125
+ });
126
+
112
127
  describe('Page ranges', () => {
113
128
  describe('when nativePageRanges is valid', () => {
114
129
  it('should append nativePageRanges to data', () => {
package/src/main.ts CHANGED
@@ -7,4 +7,5 @@ export {
7
7
  UrlConverter,
8
8
  UrlScreenshot
9
9
  } from './chromium';
10
- export { PDFEngine } from './pdf-engines';
10
+ export { PDFEngines } from './pdf-engines';
11
+ export { LibreOffice } from './libre-office';
@@ -1 +1 @@
1
- export { PDFEngine } from './pdf.engine';
1
+ export { PDFEngines } from './pdf-engines';
@@ -0,0 +1,10 @@
1
+ import { Metadata, PdfFormat } from '../../common';
2
+
3
+ export type ConversionOptions = {
4
+ pdfa?: PdfFormat;
5
+ pdfUA?: boolean;
6
+ };
7
+
8
+ export type MergeOptions = ConversionOptions & {
9
+ metadata?: Metadata;
10
+ };