chromiumly 2.10.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 (42) hide show
  1. package/README.md +45 -27
  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 +8 -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/libre-office.utils.d.ts +9 -1
  10. package/dist/libre-office/utils/libre-office.utils.js +26 -0
  11. package/dist/libre-office/utils/libre-office.utils.js.map +1 -1
  12. package/dist/main.d.ts +2 -1
  13. package/dist/main.js +4 -2
  14. package/dist/main.js.map +1 -1
  15. package/dist/pdf-engines/index.d.ts +1 -1
  16. package/dist/pdf-engines/index.js +3 -3
  17. package/dist/pdf-engines/index.js.map +1 -1
  18. package/dist/pdf-engines/interfaces/pdf-engines.types.d.ts +8 -0
  19. package/dist/pdf-engines/interfaces/pdf-engines.types.js +3 -0
  20. package/dist/pdf-engines/interfaces/pdf-engines.types.js.map +1 -0
  21. package/dist/pdf-engines/{pdf.engine.d.ts → pdf-engines.d.ts} +9 -15
  22. package/dist/pdf-engines/{pdf.engine.js → pdf-engines.js} +22 -28
  23. package/dist/pdf-engines/pdf-engines.js.map +1 -0
  24. package/dist/pdf-engines/utils/{engine.utils.d.ts → pdf-engines.utils.d.ts} +10 -1
  25. package/dist/pdf-engines/utils/{engine.utils.js → pdf-engines.utils.js} +24 -4
  26. package/dist/pdf-engines/utils/pdf-engines.utils.js.map +1 -0
  27. package/package.json +3 -3
  28. package/src/chromium/interfaces/common.types.ts +1 -1
  29. package/src/libre-office/index.ts +1 -2
  30. package/src/libre-office/interfaces/libre-office.types.ts +10 -0
  31. package/src/libre-office/libre-office.ts +58 -0
  32. package/src/libre-office/tests/libre-office.test.ts +56 -0
  33. package/src/libre-office/utils/libre-office.utils.ts +36 -1
  34. package/src/main.ts +2 -1
  35. package/src/pdf-engines/index.ts +1 -1
  36. package/src/pdf-engines/interfaces/pdf-engines.types.ts +10 -0
  37. package/src/pdf-engines/{pdf.engine.ts → pdf-engines.ts} +27 -39
  38. package/src/pdf-engines/tests/pdf.engine.test.ts +20 -19
  39. package/src/pdf-engines/utils/{engine.utils.ts → pdf-engines.utils.ts} +29 -1
  40. package/src/pdf-engines/utils/tests/{engine.utils.test.ts → pdf-engines.utils.test.ts} +6 -7
  41. package/dist/pdf-engines/pdf.engine.js.map +0 -1
  42. package/dist/pdf-engines/utils/engine.utils.js.map +0 -1
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
  [![downloads](https://img.shields.io/npm/dt/chromiumly.svg?color=brightgreen&style=flat-square)](https://npm-stat.com/charts.html?package=chromiumly)
9
9
  ![licence](https://img.shields.io/github/license/cherfia/chromiumly?style=flat-square)
10
10
 
11
- A lightweight Typescript library that interacts with [Gotenberg](https://gotenberg.dev/)'s different modules to convert
11
+ A lightweight Typescript library that interacts with [Gotenberg](https://gotenberg.dev/)'s different routes to convert
12
12
  a variety of document formats to PDF files.
13
13
 
14
14
  # Table of Contents
@@ -21,6 +21,7 @@ a variety of document formats to PDF files.
21
21
  - [dotenv](#dotenv)
22
22
  - [config](#config)
23
23
  3. [Modules](#modules)
24
+
24
25
  - [Chromium](#chromium)
25
26
  - [URL](#url)
26
27
  - [HTML](#html)
@@ -28,12 +29,14 @@ a variety of document formats to PDF files.
28
29
  - [Customization](#customization)
29
30
  - [Conversion](#conversion)
30
31
  - [Screenshot](#screenshot)
31
- - [PDF Engine](#pdf-engine)
32
+ - [LibreOffice](#libreoffice)
33
+ - [PDFEngines](#pdfengines)
32
34
  - [convert](#convert)
35
+ - [merge](#merge)
33
36
  - [readMetadata](#readmetadata)
34
37
  - [writeMetadata](#writemetadata)
35
- - [merge](#merge)
36
38
  - [generate](#generate)
39
+
37
40
  4. [Snippet](#snippet)
38
41
 
39
42
  ## Install
@@ -245,44 +248,59 @@ type ScreenshotOptions = {
245
248
  };
246
249
  ```
247
250
 
248
- ### PDF Engine
249
-
250
- The `PDFEngine` combines the functionality of
251
- Gotenberg's [PDF Engines](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route)
252
- and [LibreOffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) modules to manipulate different file formats.
251
+ ### LibreOffice
253
252
 
254
- #### convert
255
-
256
- This method interacts with [LibreOffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) module to convert different
257
- documents to PDF files. You can find the file extensions
253
+ The `LibreOffice` class comes with a single method `convert`. This method interacts with [LibreOffice](https://gotenberg.dev/docs/routes#convert-with-libreoffice) route to convert different documents to PDF files. You can find the file extensions
258
254
  accepted [here](https://gotenberg.dev/docs/routes#convert-with-libreoffice#route).
259
255
 
260
256
  ```typescript
261
- import { PDFEngine } from "chromiumly";
257
+ import { LibreOffice } from "chromiumly";
262
258
 
263
- const buffer = await PDFEngine.convert({
259
+ const buffer = await LibreOffice.convert({
264
260
  files: ["path/to/file.docx", "path/to/file.png"],
265
261
  });
266
262
  ```
267
263
 
268
- Similarly to Chromium's module `convert` method, this method takes the following optional parameters :
264
+ Similarly to Chromium's route `convert` method, this method takes the following optional parameters :
269
265
 
270
266
  - `properties`: changes how the PDF generated file will look like.
271
- - `pdfFormat`: PDF format of the conversion resulting file (i.e. `PDF/A-1a`, `PDF/A-2b`, `PDF/A-3b`).
272
- - `merge`: merge all the resulting files from the conversion into an individual PDF file.
267
+ - `pdfa`: PDF format of the conversion resulting file (i.e. `PDF/A-1a`, `PDF/A-2b`, `PDF/A-3b`).
268
+ - `pdfUA`: enables PDF for Universal Access for optimal accessibility.
269
+ - `merge`: merges all the resulting files from the conversion into an individual PDF file.
270
+ - `metadata`: writes metadata to the generated PDF file.
271
+
272
+ ### PDFEngines
273
+
274
+ The `PDFEngines` class interacts with Gotenberg's [PDF Engines](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) routes to manupilate PDF files.
275
+
276
+ #### convert
277
+
278
+ This method interacts with [PDF Engines](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) convertion route to transform PDF files into the requested PDF/A format and/or PDF/UA.
279
+
280
+ ```typescript
281
+ import { PDFEngines } from "chromiumly";
282
+
283
+ const buffer = await PDFEngines.convert({
284
+ files: ["path/to/file_1.pdf", "path/to/file_2.pdf"],
285
+ pdfa: PdfFormat.A_2b,
286
+ pdfUA: true,
287
+ });
288
+ ```
273
289
 
274
290
  #### merge
275
291
 
276
- This method interacts with [PDF Engines](https://gotenberg.dev/docs/routes#merge-pdfs-route) module which gathers different
292
+ This method interacts with [PDF Engines](https://gotenberg.dev/docs/routes#merge-pdfs-route) merge route which gathers different
277
293
  engines that can manipulate and merge PDF files such
278
294
  as: [PDFtk](https://gitlab.com/pdftk-java/pdftk), [PDFcpu](https://github.com/pdfcpu/pdfcpu), [QPDF](https://github.com/qpdf/qpdf),
279
295
  and [UNO](https://github.com/unoconv/unoconv).
280
296
 
281
297
  ```typescript
282
- import { PDFEngine } from "chromiumly";
298
+ import { PDFEngines } from "chromiumly";
283
299
 
284
- const buffer = await PDFEngine.merge({
285
- files: ["path/to/file.docx", "path/to/file.png"],
300
+ const buffer = await PDFEngines.merge({
301
+ files: ["path/to/file_1.pdf", "path/to/file_2.pdf"],
302
+ pdfa: PdfFormat.A_2b,
303
+ pdfUA: true,
286
304
  });
287
305
  ```
288
306
 
@@ -291,9 +309,9 @@ const buffer = await PDFEngine.merge({
291
309
  This method reads metadata from the provided PDF files.
292
310
 
293
311
  ```typescript
294
- import { PDFEngine } from "chromiumly";
312
+ import { PDFEngines } from "chromiumly";
295
313
 
296
- const metadataBuffer = await PDFEngine.readMetadata([
314
+ const metadataBuffer = await PDFEngines.readMetadata([
297
315
  "path/to/file_1.pdf",
298
316
  "path/to/file_2.pdf",
299
317
  ]);
@@ -304,9 +322,9 @@ const metadataBuffer = await PDFEngine.readMetadata([
304
322
  This method writes metadata to the provided PDF files.
305
323
 
306
324
  ```typescript
307
- import { PDFEngine } from "chromiumly";
325
+ import { PDFEngines } from "chromiumly";
308
326
 
309
- const buffer = await PDFEngine.writeMetadata({
327
+ const buffer = await PDFEngines.writeMetadata({
310
328
  files: [
311
329
  "path/to/file_1.pdf",
312
330
  "path/to/file_2.pdf",
@@ -333,7 +351,7 @@ Please note that all the PDF files can be found `__generated__` folder in the ro
333
351
  The following is a short snippet of how to use the library.
334
352
 
335
353
  ```typescript
336
- import { PDFEngine, UrlConverter } from "chromiumly";
354
+ import { PDFEngines, UrlConverter } from "chromiumly";
337
355
 
338
356
  async function run() {
339
357
  const urlConverter = new UrlConverter();
@@ -341,7 +359,7 @@ async function run() {
341
359
  url: "https://gotenberg.dev/",
342
360
  });
343
361
 
344
- await PDFEngine.generate("gotenberg.pdf", buffer);
362
+ await PDFEngines.generate("gotenberg.pdf", buffer);
345
363
  }
346
364
 
347
365
  run();
@@ -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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LibreOfficeUtils = void 0;
4
- var libre_office_utils_1 = require("./utils/libre-office.utils");
5
- Object.defineProperty(exports, "LibreOfficeUtils", { enumerable: true, get: function () { return libre_office_utils_1.LibreOfficeUtils; } });
3
+ exports.LibreOffice = void 0;
4
+ var libre_office_1 = require("./libre-office");
5
+ Object.defineProperty(exports, "LibreOffice", { enumerable: true, get: function () { return libre_office_1.LibreOffice; } });
6
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/libre-office/index.ts"],"names":[],"mappings":";;;AACA,iEAA8D;AAArD,sHAAA,gBAAgB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/libre-office/index.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAApC,2GAAA,WAAW,OAAA"}
@@ -1,3 +1,4 @@
1
+ import { Metadata, PdfFormat } from '../../common';
1
2
  export type PageProperties = {
2
3
  landscape?: boolean;
3
4
  nativePageRanges?: {
@@ -6,3 +7,10 @@ export type PageProperties = {
6
7
  };
7
8
  exportFormFields?: boolean;
8
9
  };
10
+ export type ConversionOptions = {
11
+ properties?: PageProperties;
12
+ merge?: boolean;
13
+ pdfa?: PdfFormat;
14
+ pdfUA?: boolean;
15
+ metadata?: Metadata;
16
+ };
@@ -0,0 +1,27 @@
1
+ /// <reference types="node" />
2
+ import { PathLikeOrReadStream, PdfFormat, Metadata } from '../common';
3
+ import { PageProperties } from './interfaces/libre-office.types';
4
+ /**
5
+ * Class representing a LibreOffice for various operations such as merging and conversion.
6
+ */
7
+ export declare class LibreOffice {
8
+ /**
9
+ * Converts various document formats to PDF.
10
+ *
11
+ * @param {Object} options - Options for the conversion operation.
12
+ * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the files to be converted to PDF.
13
+ * @param {PageProperties} [options.properties] - Page properties for the conversion.
14
+ * @param {pdfa} [options.pdfFormat] - PDF format options.
15
+ * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
16
+ * @param {boolean} [options.merge] - Indicates whether to merge the resulting PDFs.
17
+ * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
18
+ */
19
+ static convert({ files, properties, pdfa, pdfUA, merge, metadata }: {
20
+ files: PathLikeOrReadStream[];
21
+ properties?: PageProperties;
22
+ pdfa?: PdfFormat;
23
+ pdfUA?: boolean;
24
+ merge?: boolean;
25
+ metadata?: Metadata;
26
+ }): Promise<Buffer>;
27
+ }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LibreOffice = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const form_data_1 = tslib_1.__importDefault(require("form-data"));
6
+ const main_config_1 = require("../main.config");
7
+ const common_1 = require("../common");
8
+ const libre_office_utils_1 = require("./utils/libre-office.utils");
9
+ /**
10
+ * Class representing a LibreOffice for various operations such as merging and conversion.
11
+ */
12
+ class LibreOffice {
13
+ /**
14
+ * Converts various document formats to PDF.
15
+ *
16
+ * @param {Object} options - Options for the conversion operation.
17
+ * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the files to be converted to PDF.
18
+ * @param {PageProperties} [options.properties] - Page properties for the conversion.
19
+ * @param {pdfa} [options.pdfFormat] - PDF format options.
20
+ * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
21
+ * @param {boolean} [options.merge] - Indicates whether to merge the resulting PDFs.
22
+ * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
23
+ */
24
+ static convert(_a) {
25
+ return tslib_1.__awaiter(this, arguments, void 0, function* ({ files, properties, pdfa, pdfUA, merge, metadata }) {
26
+ const data = new form_data_1.default();
27
+ yield libre_office_utils_1.LibreOfficeUtils.addFiles(files, data);
28
+ yield libre_office_utils_1.LibreOfficeUtils.customize(data, {
29
+ properties,
30
+ merge,
31
+ pdfa,
32
+ pdfUA,
33
+ metadata
34
+ });
35
+ const endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.LIBRE_OFFICE_PATH}/${main_config_1.Chromiumly.LIBRE_OFFICE_ROUTES.convert}`;
36
+ return common_1.GotenbergUtils.fetch(endpoint, data);
37
+ });
38
+ }
39
+ }
40
+ exports.LibreOffice = LibreOffice;
41
+ //# sourceMappingURL=libre-office.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libre-office.js","sourceRoot":"","sources":["../../src/libre-office/libre-office.ts"],"names":[],"mappings":";;;;AAAA,kEAAiC;AAEjC,gDAA4C;AAC5C,sCAKmB;AAEnB,mEAA8D;AAE9D;;GAEG;AACH,MAAa,WAAW;IACpB;;;;;;;;;;OAUG;IACI,MAAM,CAAO,OAAO;qEAAC,EACxB,KAAK,EACL,UAAU,EACV,IAAI,EACJ,KAAK,EACL,KAAK,EACL,QAAQ,EAQX;YACG,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,MAAM,qCAAgB,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC7C,MAAM,qCAAgB,CAAC,SAAS,CAAC,IAAI,EAAE;gBACnC,UAAU;gBACV,KAAK;gBACL,IAAI;gBACJ,KAAK;gBACL,QAAQ;aACX,CAAC,CAAC;YAEH,MAAM,QAAQ,GAAG,GAAG,wBAAU,CAAC,kBAAkB,IAAI,wBAAU,CAAC,iBAAiB,IAAI,wBAAU,CAAC,mBAAmB,CAAC,OAAO,EAAE,CAAC;YAE9H,OAAO,uBAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAChD,CAAC;KAAA;CACJ;AA1CD,kCA0CC"}
@@ -1,6 +1,6 @@
1
1
  import FormData from 'form-data';
2
2
  import { PathLikeOrReadStream } from '../../common';
3
- import { PageProperties } from '../interfaces/libre-office.types';
3
+ import { ConversionOptions, PageProperties } from '../interfaces/libre-office.types';
4
4
  /**
5
5
  * Utility class for handling common tasks related to LibreOffice conversions.
6
6
  */
@@ -20,4 +20,12 @@ export declare class LibreOfficeUtils {
20
20
  * @param {PageProperties} pageProperties - The page properties to be added to the FormData.
21
21
  */
22
22
  static addPageProperties(data: FormData, pageProperties: PageProperties): void;
23
+ /**
24
+ * Customizes the FormData object based on the provided conversion options.
25
+ *
26
+ * @param {FormData} data - The FormData object to be customized.
27
+ * @param {ConversionOptions} options - The conversion options to apply to the FormData.
28
+ * @returns {Promise<void>} A Promise that resolves once the customization is complete.
29
+ */
30
+ static customize(data: FormData, options: ConversionOptions): Promise<void>;
23
31
  }
@@ -69,6 +69,32 @@ class LibreOfficeUtils {
69
69
  data.append('exportFormFields', String(pageProperties.exportFormFields));
70
70
  }
71
71
  }
72
+ /**
73
+ * Customizes the FormData object based on the provided conversion options.
74
+ *
75
+ * @param {FormData} data - The FormData object to be customized.
76
+ * @param {ConversionOptions} options - The conversion options to apply to the FormData.
77
+ * @returns {Promise<void>} A Promise that resolves once the customization is complete.
78
+ */
79
+ static customize(data, options) {
80
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
81
+ if (options.pdfa) {
82
+ data.append('pdfa', options.pdfa);
83
+ }
84
+ if (options.pdfUA) {
85
+ data.append('pdfUA', String(options.pdfUA));
86
+ }
87
+ if (options.merge) {
88
+ data.append('merge', String(options.merge));
89
+ }
90
+ if (options.metadata) {
91
+ data.append('metadata', JSON.stringify(options.metadata));
92
+ }
93
+ if (options.properties) {
94
+ LibreOfficeUtils.addPageProperties(data, options.properties);
95
+ }
96
+ });
97
+ }
72
98
  }
73
99
  exports.LibreOfficeUtils = LibreOfficeUtils;
74
100
  //# sourceMappingURL=libre-office.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"libre-office.utils.js","sourceRoot":"","sources":["../../../src/libre-office/utils/libre-office.utils.ts"],"names":[],"mappings":";;;;AAAA,2BAAuE;AACvE,wDAAwB;AAExB,yCAAmD;AAInD,yCAAoE;AACpE,2CAAsD;AAGtD;;GAEG;AACH,MAAa,gBAAgB;IACzB;;;;;;OAMG;IACI,MAAM,CAAO,QAAQ,CACxB,KAA6B,EAC7B,IAAc;;YAEd,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE,CAAC;gBACzC,IAAI,IAAI,GAAG,KAAK,CAAC;gBACjB,IAAI,QAAQ,CAAC;gBAEb,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;oBACzB,QAAQ,GAAG,MAAM,IAAA,sBAAU,EAAC,KAAK,CAAC,CAAC;gBACvC,CAAC;qBAAM,IAAI,KAAK,YAAY,eAAU,EAAE,CAAC;oBACrC,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
2
2
  export { HtmlConverter, HtmlScreenshot, MarkdownConverter, MarkdownScreenshot, UrlConverter, UrlScreenshot } from './chromium';
3
- export { PDFEngine } from './pdf-engines';
3
+ export { PDFEngines } from './pdf-engines';
4
+ export { LibreOffice } from './libre-office';
package/dist/main.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PDFEngine = exports.UrlScreenshot = exports.UrlConverter = exports.MarkdownScreenshot = exports.MarkdownConverter = exports.HtmlScreenshot = exports.HtmlConverter = exports.PdfFormat = void 0;
3
+ exports.LibreOffice = exports.PDFEngines = exports.UrlScreenshot = exports.UrlConverter = exports.MarkdownScreenshot = exports.MarkdownConverter = exports.HtmlScreenshot = exports.HtmlConverter = exports.PdfFormat = void 0;
4
4
  var constants_1 = require("./common/constants");
5
5
  Object.defineProperty(exports, "PdfFormat", { enumerable: true, get: function () { return constants_1.PdfFormat; } });
6
6
  var chromium_1 = require("./chromium");
@@ -11,5 +11,7 @@ Object.defineProperty(exports, "MarkdownScreenshot", { enumerable: true, get: fu
11
11
  Object.defineProperty(exports, "UrlConverter", { enumerable: true, get: function () { return chromium_1.UrlConverter; } });
12
12
  Object.defineProperty(exports, "UrlScreenshot", { enumerable: true, get: function () { return chromium_1.UrlScreenshot; } });
13
13
  var pdf_engines_1 = require("./pdf-engines");
14
- Object.defineProperty(exports, "PDFEngine", { enumerable: true, get: function () { return pdf_engines_1.PDFEngine; } });
14
+ Object.defineProperty(exports, "PDFEngines", { enumerable: true, get: function () { return pdf_engines_1.PDFEngines; } });
15
+ var libre_office_1 = require("./libre-office");
16
+ Object.defineProperty(exports, "LibreOffice", { enumerable: true, get: function () { return libre_office_1.LibreOffice; } });
15
17
  //# sourceMappingURL=main.js.map
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAAtC,sGAAA,SAAS,OAAA;AAClB,uCAOoB;AANhB,yGAAA,aAAa,OAAA;AACb,0GAAA,cAAc,OAAA;AACd,6GAAA,iBAAiB,OAAA;AACjB,8GAAA,kBAAkB,OAAA;AAClB,wGAAA,YAAY,OAAA;AACZ,yGAAA,aAAa,OAAA;AAEjB,6CAA0C;AAAjC,wGAAA,SAAS,OAAA"}
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;AAAA,gDAA+C;AAAtC,sGAAA,SAAS,OAAA;AAClB,uCAOoB;AANhB,yGAAA,aAAa,OAAA;AACb,0GAAA,cAAc,OAAA;AACd,6GAAA,iBAAiB,OAAA;AACjB,8GAAA,kBAAkB,OAAA;AAClB,wGAAA,YAAY,OAAA;AACZ,yGAAA,aAAa,OAAA;AAEjB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,+CAA6C;AAApC,2GAAA,WAAW,OAAA"}
@@ -1 +1 @@
1
- export { PDFEngine } from './pdf.engine';
1
+ export { PDFEngines } from './pdf-engines';
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PDFEngine = void 0;
4
- var pdf_engine_1 = require("./pdf.engine");
5
- Object.defineProperty(exports, "PDFEngine", { enumerable: true, get: function () { return pdf_engine_1.PDFEngine; } });
3
+ exports.PDFEngines = void 0;
4
+ var pdf_engines_1 = require("./pdf-engines");
5
+ Object.defineProperty(exports, "PDFEngines", { enumerable: true, get: function () { return pdf_engines_1.PDFEngines; } });
6
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pdf-engines/index.ts"],"names":[],"mappings":";;;AAAA,2CAAyC;AAAhC,uGAAA,SAAS,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pdf-engines/index.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAAlC,yGAAA,UAAU,OAAA"}
@@ -0,0 +1,8 @@
1
+ import { Metadata, PdfFormat } from '../../common';
2
+ export type ConversionOptions = {
3
+ pdfa?: PdfFormat;
4
+ pdfUA?: boolean;
5
+ };
6
+ export type MergeOptions = ConversionOptions & {
7
+ metadata?: Metadata;
8
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=pdf-engines.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pdf-engines.types.js","sourceRoot":"","sources":["../../../src/pdf-engines/interfaces/pdf-engines.types.ts"],"names":[],"mappings":""}
@@ -1,10 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import { PathLikeOrReadStream, PdfFormat, Metadata } from '../common';
3
- import { PageProperties } from '../libre-office';
4
3
  /**
5
- * Class representing a PDF engine for various operations such as merging and conversion.
4
+ * Class uses PDF engines for various operations such as merging and conversion.
6
5
  */
7
- export declare class PDFEngine {
6
+ export declare class PDFEngines {
8
7
  /**
9
8
  * Merges multiple PDF files into a single PDF document.
10
9
  *
@@ -12,30 +11,25 @@ export declare class PDFEngine {
12
11
  * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the PDF files to be merged.
13
12
  * @returns {Promise<Buffer>} A Promise resolving to the merged PDF content as a Buffer.
14
13
  */
15
- static merge({ files }: {
14
+ static merge({ files, pdfa, pdfUA, metadata }: {
16
15
  files: PathLikeOrReadStream[];
16
+ pdfa?: PdfFormat;
17
+ pdfUA?: boolean;
18
+ metadata?: Metadata;
17
19
  }): Promise<Buffer>;
18
20
  /**
19
21
  * Converts various document formats to PDF.
20
22
  *
21
23
  * @param {Object} options - Options for the conversion operation.
22
24
  * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the files to be converted to PDF.
23
- * @param {PageProperties} [options.properties] - Page properties for the conversion.
24
- * @param {PdfFormat} [options.pdfFormat] - PDF format options.
25
+ * @param {pdfa} [options.pdfa] - PDF format options.
25
26
  * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
26
- * @param {boolean} [options.merge] - Indicates whether to merge the resulting PDFs.
27
27
  * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
28
28
  */
29
- static convert({ files, properties, pdfFormat, pdfUA, merge }: {
29
+ static convert({ files, pdfa, pdfUA }: {
30
30
  files: PathLikeOrReadStream[];
31
- properties?: PageProperties;
32
- /**
33
- * @deprecated Starting from Gotenberg version 8.0.0, LibreOffice no longer provides support for pdfFormat.
34
- * @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
35
- */
36
- pdfFormat?: PdfFormat;
31
+ pdfa?: PdfFormat;
37
32
  pdfUA?: boolean;
38
- merge?: boolean;
39
33
  }): Promise<Buffer>;
40
34
  /**
41
35
  * Reads metadata from the provided files.
@@ -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 @@
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AAC;YACvE,MAAM,aAAQ,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,aAAa,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;QAC5E,CAAC;KAAA;CACJ;AAtHD,gCAsHC"}
@@ -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.10.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,7 +50,7 @@
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.12.4",
53
+ "@types/node": "20.12.5",
54
54
  "@types/node-fetch": "2.6.11",
55
55
  "@typescript-eslint/eslint-plugin": "7.5.0",
56
56
  "@typescript-eslint/parser": "7.5.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,5 +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
4
6
  exportFormFields?: boolean; // Set whether to export the form fields or to use the inputted/selected content of the fields (default true)
5
7
  };
8
+
9
+ export type ConversionOptions = {
10
+ properties?: PageProperties;
11
+ merge?: boolean;
12
+ pdfa?: PdfFormat;
13
+ pdfUA?: boolean;
14
+ metadata?: Metadata;
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
+ });
@@ -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.
@@ -89,4 +92,36 @@ export class LibreOfficeUtils {
89
92
  );
90
93
  }
91
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
+ }
126
+ }
92
127
  }
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
+ };
@@ -10,13 +10,12 @@ import {
10
10
  PdfFormat,
11
11
  Metadata
12
12
  } from '../common';
13
- import { LibreOfficeUtils, PageProperties } from '../libre-office';
14
- import { PDFEngineUtils } from './utils/engine.utils';
13
+ import { PDFEnginesUtils } from './utils/pdf-engines.utils';
15
14
 
16
15
  /**
17
- * Class representing a PDF engine for various operations such as merging and conversion.
16
+ * Class uses PDF engines for various operations such as merging and conversion.
18
17
  */
19
- export class PDFEngine {
18
+ export class PDFEngines {
20
19
  /**
21
20
  * Merges multiple PDF files into a single PDF document.
22
21
  *
@@ -25,12 +24,23 @@ export class PDFEngine {
25
24
  * @returns {Promise<Buffer>} A Promise resolving to the merged PDF content as a Buffer.
26
25
  */
27
26
  public static async merge({
28
- files
27
+ files,
28
+ pdfa,
29
+ pdfUA,
30
+ metadata
29
31
  }: {
30
32
  files: PathLikeOrReadStream[];
33
+ pdfa?: PdfFormat;
34
+ pdfUA?: boolean;
35
+ metadata?: Metadata;
31
36
  }): Promise<Buffer> {
32
37
  const data = new FormData();
33
- await PDFEngineUtils.addFiles(files, data);
38
+ await PDFEnginesUtils.addFiles(files, data);
39
+ await PDFEnginesUtils.customize(data, {
40
+ pdfa,
41
+ pdfUA,
42
+ metadata
43
+ });
34
44
  const endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.PDF_ENGINES_PATH}/${Chromiumly.PDF_ENGINE_ROUTES.merge}`;
35
45
  return GotenbergUtils.fetch(endpoint, data);
36
46
  }
@@ -40,48 +50,26 @@ export class PDFEngine {
40
50
  *
41
51
  * @param {Object} options - Options for the conversion operation.
42
52
  * @param {PathLikeOrReadStream[]} options.files - An array of PathLikes or ReadStreams to the files to be converted to PDF.
43
- * @param {PageProperties} [options.properties] - Page properties for the conversion.
44
- * @param {PdfFormat} [options.pdfFormat] - PDF format options.
53
+ * @param {pdfa} [options.pdfa] - PDF format options.
45
54
  * @param {boolean} [options.pdfUA] - Indicates whether to generate PDF/UA compliant output.
46
- * @param {boolean} [options.merge] - Indicates whether to merge the resulting PDFs.
47
55
  * @returns {Promise<Buffer>} A Promise resolving to the converted PDF content as a Buffer.
48
56
  */
49
57
  public static async convert({
50
58
  files,
51
- properties,
52
- pdfFormat,
53
- pdfUA,
54
- merge
59
+ pdfa,
60
+ pdfUA
55
61
  }: {
56
62
  files: PathLikeOrReadStream[];
57
- properties?: PageProperties;
58
- /**
59
- * @deprecated Starting from Gotenberg version 8.0.0, LibreOffice no longer provides support for pdfFormat.
60
- * @see {@link https://github.com/gotenberg/gotenberg/releases/tag/v8.0.0}
61
- */
62
- pdfFormat?: PdfFormat;
63
+ pdfa?: PdfFormat;
63
64
  pdfUA?: boolean;
64
- merge?: boolean;
65
65
  }): Promise<Buffer> {
66
66
  const data = new FormData();
67
67
 
68
- if (pdfFormat) {
69
- data.append('pdfa', pdfFormat);
70
- }
71
-
72
- if (pdfUA) {
73
- data.append('pdfUA', String(pdfUA));
74
- }
75
-
76
- if (merge) {
77
- data.append('merge', String(merge));
78
- }
79
-
80
- if (properties) {
81
- LibreOfficeUtils.addPageProperties(data, properties);
82
- }
83
-
84
- await LibreOfficeUtils.addFiles(files, data);
68
+ await PDFEnginesUtils.addFiles(files, data);
69
+ await PDFEnginesUtils.customize(data, {
70
+ pdfa,
71
+ pdfUA
72
+ });
85
73
 
86
74
  const endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.LIBRE_OFFICE_PATH}/${Chromiumly.LIBRE_OFFICE_ROUTES.convert}`;
87
75
 
@@ -99,7 +87,7 @@ export class PDFEngine {
99
87
  ): Promise<Buffer> {
100
88
  const data = new FormData();
101
89
 
102
- await PDFEngineUtils.addFiles(files, data);
90
+ await PDFEnginesUtils.addFiles(files, data);
103
91
 
104
92
  const endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.PDF_ENGINES_PATH}/${Chromiumly.PDF_ENGINE_ROUTES.readMetadata}`;
105
93
 
@@ -123,7 +111,7 @@ export class PDFEngine {
123
111
  const data = new FormData();
124
112
  data.append('metadata', JSON.stringify(metadata));
125
113
 
126
- await PDFEngineUtils.addFiles(files, data);
114
+ await PDFEnginesUtils.addFiles(files, data);
127
115
 
128
116
  const endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.PDF_ENGINES_PATH}/${Chromiumly.PDF_ENGINE_ROUTES.writeMetadata}`;
129
117
 
@@ -6,12 +6,12 @@ import fetch from 'node-fetch';
6
6
  import path from 'path';
7
7
 
8
8
  import { PdfFormat } from '../../common';
9
- import { PDFEngine } from '../pdf.engine';
9
+ import { PDFEngines } from '../pdf-engines';
10
10
 
11
11
  const { Response } = jest.requireActual('node-fetch');
12
12
  jest.mock('node-fetch', () => jest.fn());
13
13
 
14
- describe('PDFEngine', () => {
14
+ describe('PDFEngines', () => {
15
15
  const mockPromisesAccess = jest.spyOn(promises, 'access');
16
16
  const mockFetch = fetch as jest.MockedFunction<typeof fetch>;
17
17
  const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
@@ -31,8 +31,8 @@ describe('PDFEngine', () => {
31
31
  it('should return a buffer', async () => {
32
32
  mockPromisesAccess.mockResolvedValue();
33
33
  mockFetch.mockResolvedValue(new Response('content'));
34
- const buffer = await PDFEngine.convert({
35
- files: ['path/to/file.docx', 'path/to/file.bib']
34
+ const buffer = await PDFEngines.convert({
35
+ files: ['path/to/file_1.pdf', 'path/to/file_2.pdf']
36
36
  });
37
37
  expect(buffer).toEqual(Buffer.from('content'));
38
38
  expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
@@ -43,15 +43,13 @@ describe('PDFEngine', () => {
43
43
  it('should return a buffer', async () => {
44
44
  mockPromisesAccess.mockResolvedValue();
45
45
  mockFetch.mockResolvedValue(new Response('content'));
46
- const buffer = await PDFEngine.convert({
47
- files: ['path/to/file.docx', 'path/to/file.bib'],
48
- properties: { landscape: true },
49
- pdfFormat: PdfFormat.A_1a,
50
- pdfUA: true,
51
- merge: true
46
+ const buffer = await PDFEngines.convert({
47
+ files: ['path/to/file_1.pdf', 'path/to/file_2.pdf'],
48
+ pdfa: PdfFormat.A_2b,
49
+ pdfUA: true
52
50
  });
53
51
  expect(buffer).toEqual(Buffer.from('content'));
54
- expect(mockFormDataAppend).toHaveBeenCalledTimes(6);
52
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(4);
55
53
  });
56
54
  });
57
55
  });
@@ -60,11 +58,14 @@ describe('PDFEngine', () => {
60
58
  it('should return a buffer', async () => {
61
59
  mockPromisesAccess.mockResolvedValue();
62
60
  mockFetch.mockResolvedValue(new Response('content'));
63
- const buffer = await PDFEngine.merge({
64
- files: ['path/to/file.pdf', 'path/to/another-file.pdf']
61
+ const buffer = await PDFEngines.merge({
62
+ files: ['path/to/file.pdf', 'path/to/another-file.pdf'],
63
+ pdfa: PdfFormat.A_2b,
64
+ pdfUA: true,
65
+ metadata: { Author: 'John Doe' }
65
66
  });
66
67
  expect(buffer).toEqual(Buffer.from('content'));
67
- expect(mockFormDataAppend).toHaveBeenCalledTimes(2);
68
+ expect(mockFormDataAppend).toHaveBeenCalledTimes(5);
68
69
  });
69
70
  });
70
71
 
@@ -72,7 +73,7 @@ describe('PDFEngine', () => {
72
73
  it('should return a buffer', async () => {
73
74
  mockPromisesAccess.mockResolvedValue();
74
75
  mockFetch.mockResolvedValue(new Response('content'));
75
- const buffer = await PDFEngine.readMetadata(['path/to/file.pdf']);
76
+ const buffer = await PDFEngines.readMetadata(['path/to/file.pdf']);
76
77
  expect(buffer).toEqual(Buffer.from('content'));
77
78
  expect(mockFormDataAppend).toHaveBeenCalledTimes(1);
78
79
  });
@@ -82,7 +83,7 @@ describe('PDFEngine', () => {
82
83
  it('should return a buffer', async () => {
83
84
  mockPromisesAccess.mockResolvedValue();
84
85
  mockFetch.mockResolvedValue(new Response('content'));
85
- const buffer = await PDFEngine.writeMetadata({
86
+ const buffer = await PDFEngines.writeMetadata({
86
87
  files: ['path/to/file.pdf'],
87
88
  metadata: {
88
89
  Author: 'John Doe',
@@ -127,7 +128,7 @@ describe('PDFEngine', () => {
127
128
  .spyOn(fs, 'writeFile')
128
129
  .mockResolvedValueOnce();
129
130
 
130
- await PDFEngine.generate(mockFilename, mockBuffer);
131
+ await PDFEngines.generate(mockFilename, mockBuffer);
131
132
 
132
133
  expect(mockPromisesMkDir).toHaveBeenCalledWith(mockGeneratedDir, {
133
134
  recursive: true
@@ -145,7 +146,7 @@ describe('PDFEngine', () => {
145
146
  );
146
147
 
147
148
  await expect(
148
- PDFEngine.generate(mockFilename, mockBuffer)
149
+ PDFEngines.generate(mockFilename, mockBuffer)
149
150
  ).rejects.toThrow('Cannot create directory');
150
151
  });
151
152
 
@@ -155,7 +156,7 @@ describe('PDFEngine', () => {
155
156
  );
156
157
 
157
158
  await expect(
158
- PDFEngine.generate(mockFilename, mockBuffer)
159
+ PDFEngines.generate(mockFilename, mockBuffer)
159
160
  ).rejects.toThrow('Failed to write to file');
160
161
  });
161
162
  });
@@ -3,11 +3,15 @@ import path from 'path';
3
3
 
4
4
  import FormData from 'form-data';
5
5
  import { PathLikeOrReadStream } from '../../common';
6
+ import {
7
+ ConversionOptions,
8
+ MergeOptions
9
+ } from '../interfaces/pdf-engines.types';
6
10
 
7
11
  /**
8
12
  * Utility class for handling common tasks related to PDF engine operations.
9
13
  */
10
- export class PDFEngineUtils {
14
+ export class PDFEnginesUtils {
11
15
  /**
12
16
  * Adds PDF files to the FormData object.
13
17
  *
@@ -37,4 +41,28 @@ export class PDFEngineUtils {
37
41
  }
38
42
  }
39
43
  }
44
+
45
+ /**
46
+ * Customizes the FormData object based on the provided conversion options.
47
+ *
48
+ * @param {FormData} data - The FormData object to be customized.
49
+ * @param {ConversionOptions | MergeOptions} options - The options to apply to the FormData.
50
+ * @returns {Promise<void>} A Promise that resolves once the customization is complete.
51
+ */
52
+ public static async customize(
53
+ data: FormData,
54
+ options: ConversionOptions | MergeOptions
55
+ ): Promise<void> {
56
+ if (options.pdfa) {
57
+ data.append('pdfa', options.pdfa);
58
+ }
59
+
60
+ if (options.pdfUA) {
61
+ data.append('pdfUA', String(options.pdfUA));
62
+ }
63
+
64
+ if ('metadata' in options && options.metadata) {
65
+ data.append('metadata', JSON.stringify(options.metadata));
66
+ }
67
+ }
40
68
  }
@@ -1,10 +1,9 @@
1
1
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
2
  import { createReadStream, promises } from 'fs';
3
3
  import FormData from 'form-data';
4
+ import { PDFEnginesUtils } from '../pdf-engines.utils';
4
5
 
5
- import { PDFEngineUtils } from '../engine.utils';
6
-
7
- describe('PDFEngineUtils', () => {
6
+ describe('PDFEnginesUtils', () => {
8
7
  const mockPromisesAccess = jest.spyOn(promises, 'access');
9
8
  const mockFormDataAppend = jest.spyOn(FormData.prototype, 'append');
10
9
  const data = new FormData();
@@ -24,7 +23,7 @@ describe('PDFEngineUtils', () => {
24
23
  describe('when files parameter contains paths', () => {
25
24
  it('should append each file to data', async () => {
26
25
  mockPromisesAccess.mockResolvedValue();
27
- await PDFEngineUtils.addFiles(
26
+ await PDFEnginesUtils.addFiles(
28
27
  ['path/to/file.pdf', 'path/to/another-file.pdf'],
29
28
  data
30
29
  );
@@ -34,7 +33,7 @@ describe('PDFEngineUtils', () => {
34
33
  describe('when files parameter contains a buffer', () => {
35
34
  it('should append each file to data', async () => {
36
35
  mockPromisesAccess.mockResolvedValue();
37
- await PDFEngineUtils.addFiles(
36
+ await PDFEnginesUtils.addFiles(
38
37
  [Buffer.from('data'), 'path/to/another-file.pdf'],
39
38
  data
40
39
  );
@@ -47,7 +46,7 @@ describe('PDFEngineUtils', () => {
47
46
  it('should throw an error', async () => {
48
47
  mockPromisesAccess.mockResolvedValue();
49
48
  await expect(() =>
50
- PDFEngineUtils.addFiles(
49
+ PDFEnginesUtils.addFiles(
51
50
  ['path/to/file.docx', 'path/to/file.pdf'],
52
51
  data
53
52
  )
@@ -61,7 +60,7 @@ describe('PDFEngineUtils', () => {
61
60
  "ENOENT: no such file or directory, access 'path/to/index.html'";
62
61
  mockPromisesAccess.mockRejectedValue(new Error(errorMessage));
63
62
  await expect(() =>
64
- PDFEngineUtils.addFiles(
63
+ PDFEnginesUtils.addFiles(
65
64
  ['path/to/file.pdf', 'path/to/another-file.pdf'],
66
65
  data
67
66
  )
@@ -1 +0,0 @@
1
- {"version":3,"file":"pdf.engine.js","sourceRoot":"","sources":["../../src/pdf-engines/pdf.engine.ts"],"names":[],"mappings":";;;;AAAA,2BAA8B;AAC9B,wDAAwB;AAExB,kEAAiC;AAEjC,gDAA4C;AAC5C,sCAKmB;AACnB,kDAAmE;AACnE,uDAAsD;AAEtD;;GAEG;AACH,MAAa,SAAS;IAClB;;;;;;OAMG;IACI,MAAM,CAAO,KAAK;qEAAC,EACtB,KAAK,EAGR;YACG,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAC5B,MAAM,6BAAc,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;YAC3C,MAAM,QAAQ,GAAG,GAAG,wBAAU,CAAC,kBAAkB,IAAI,wBAAU,CAAC,gBAAgB,IAAI,wBAAU,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;YACzH,OAAO,uBAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAChD,CAAC;KAAA;IAED;;;;;;;;;;OAUG;IACI,MAAM,CAAO,OAAO;qEAAC,EACxB,KAAK,EACL,UAAU,EACV,SAAS,EACT,KAAK,EACL,KAAK,EAWR;YACG,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;YAE5B,IAAI,SAAS,EAAE,CAAC;gBACZ,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YACnC,CAAC;YAED,IAAI,KAAK,EAAE,CAAC;gBACR,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACxC,CAAC;YAED,IAAI,KAAK,EAAE,CAAC;gBACR,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACxC,CAAC;YAED,IAAI,UA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