chromiumly 2.10.0 → 3.0.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 (43) hide show
  1. package/README.md +51 -29
  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 +18 -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 +10 -2
  10. package/dist/libre-office/utils/libre-office.utils.js +47 -26
  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 -4
  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 +150 -0
  31. package/src/libre-office/libre-office.ts +56 -0
  32. package/src/libre-office/tests/libre-office.test.ts +56 -0
  33. package/src/libre-office/utils/libre-office.utils.ts +61 -32
  34. package/src/libre-office/utils/tests/libre-office.utils.test.ts +9 -10
  35. package/src/main.ts +2 -1
  36. package/src/pdf-engines/index.ts +1 -1
  37. package/src/pdf-engines/interfaces/pdf-engines.types.ts +10 -0
  38. package/src/pdf-engines/{pdf.engine.ts → pdf-engines.ts} +27 -39
  39. package/src/pdf-engines/tests/pdf.engine.test.ts +20 -19
  40. package/src/pdf-engines/utils/{engine.utils.ts → pdf-engines.utils.ts} +29 -1
  41. package/src/pdf-engines/utils/tests/{engine.utils.test.ts → pdf-engines.utils.test.ts} +6 -7
  42. package/dist/pdf-engines/pdf.engine.js.map +0 -1
  43. 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,63 @@ 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
258
- accepted [here](https://gotenberg.dev/docs/routes#convert-with-libreoffice#route).
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
254
+ accepted [here](https://gotenberg.dev/docs/routes#convert-with-libreoffice).
259
255
 
260
256
  ```typescript
261
- import { PDFEngine } from "chromiumly";
257
+ import { LibreOffice } from "chromiumly";
262
258
 
263
- const buffer = await PDFEngine.convert({
264
- files: ["path/to/file.docx", "path/to/file.png"],
259
+ const buffer = await LibreOffice.convert({
260
+ files: [
261
+ "path/to/file.docx",
262
+ "path/to/file.png",
263
+ { data: xlsxFileBuffer, ext: "xlsx" },
264
+ ],
265
265
  });
266
266
  ```
267
267
 
268
- Similarly to Chromium's module `convert` method, this method takes the following optional parameters :
268
+ Similarly to Chromium's route `convert` method, this method takes the following optional parameters :
269
269
 
270
270
  - `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.
271
+ - `pdfa`: PDF format of the conversion resulting file (i.e. `PDF/A-1a`, `PDF/A-2b`, `PDF/A-3b`).
272
+ - `pdfUA`: enables PDF for Universal Access for optimal accessibility.
273
+ - `merge`: merges all the resulting files from the conversion into an individual PDF file.
274
+ - `metadata`: writes metadata to the generated PDF file.
275
+
276
+ ### PDFEngines
277
+
278
+ The `PDFEngines` class interacts with Gotenberg's [PDF Engines](https://gotenberg.dev/docs/routes#convert-into-pdfa--pdfua-route) routes to manupilate PDF files.
279
+
280
+ #### convert
281
+
282
+ 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.
283
+
284
+ ```typescript
285
+ import { PDFEngines } from "chromiumly";
286
+
287
+ const buffer = await PDFEngines.convert({
288
+ files: ["path/to/file_1.pdf", "path/to/file_2.pdf"],
289
+ pdfa: PdfFormat.A_2b,
290
+ pdfUA: true,
291
+ });
292
+ ```
273
293
 
274
294
  #### merge
275
295
 
276
- This method interacts with [PDF Engines](https://gotenberg.dev/docs/routes#merge-pdfs-route) module which gathers different
296
+ This method interacts with [PDF Engines](https://gotenberg.dev/docs/routes#merge-pdfs-route) merge route which gathers different
277
297
  engines that can manipulate and merge PDF files such
278
298
  as: [PDFtk](https://gitlab.com/pdftk-java/pdftk), [PDFcpu](https://github.com/pdfcpu/pdfcpu), [QPDF](https://github.com/qpdf/qpdf),
279
299
  and [UNO](https://github.com/unoconv/unoconv).
280
300
 
281
301
  ```typescript
282
- import { PDFEngine } from "chromiumly";
302
+ import { PDFEngines } from "chromiumly";
283
303
 
284
- const buffer = await PDFEngine.merge({
285
- files: ["path/to/file.docx", "path/to/file.png"],
304
+ const buffer = await PDFEngines.merge({
305
+ files: ["path/to/file_1.pdf", "path/to/file_2.pdf"],
306
+ pdfa: PdfFormat.A_2b,
307
+ pdfUA: true,
286
308
  });
287
309
  ```
288
310
 
@@ -291,9 +313,9 @@ const buffer = await PDFEngine.merge({
291
313
  This method reads metadata from the provided PDF files.
292
314
 
293
315
  ```typescript
294
- import { PDFEngine } from "chromiumly";
316
+ import { PDFEngines } from "chromiumly";
295
317
 
296
- const metadataBuffer = await PDFEngine.readMetadata([
318
+ const metadataBuffer = await PDFEngines.readMetadata([
297
319
  "path/to/file_1.pdf",
298
320
  "path/to/file_2.pdf",
299
321
  ]);
@@ -304,9 +326,9 @@ const metadataBuffer = await PDFEngine.readMetadata([
304
326
  This method writes metadata to the provided PDF files.
305
327
 
306
328
  ```typescript
307
- import { PDFEngine } from "chromiumly";
329
+ import { PDFEngines } from "chromiumly";
308
330
 
309
- const buffer = await PDFEngine.writeMetadata({
331
+ const buffer = await PDFEngines.writeMetadata({
310
332
  files: [
311
333
  "path/to/file_1.pdf",
312
334
  "path/to/file_2.pdf",
@@ -333,7 +355,7 @@ Please note that all the PDF files can be found `__generated__` folder in the ro
333
355
  The following is a short snippet of how to use the library.
334
356
 
335
357
  ```typescript
336
- import { PDFEngine, UrlConverter } from "chromiumly";
358
+ import { PDFEngines, UrlConverter } from "chromiumly";
337
359
 
338
360
  async function run() {
339
361
  const urlConverter = new UrlConverter();
@@ -341,7 +363,7 @@ async function run() {
341
363
  url: "https://gotenberg.dev/",
342
364
  });
343
365
 
344
- await PDFEngine.generate("gotenberg.pdf", buffer);
366
+ await PDFEngines.generate("gotenberg.pdf", buffer);
345
367
  }
346
368
 
347
369
  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,13 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { ReadStream } from 'fs';
4
+ import { Metadata, PdfFormat } from '../../common';
5
+ type FileExtension = '123' | '602' | 'abw' | 'bib' | 'bmp' | 'cdr' | 'cgm' | 'cmx' | 'csv' | 'cwk' | 'dbf' | 'dif' | 'doc' | 'docm' | 'docx' | 'dot' | 'dotm' | 'dotx' | 'dxf' | 'emf' | 'eps' | 'epub' | 'fodg' | 'fodp' | 'fods' | 'fodt' | 'fopd' | 'gif' | 'htm' | 'html' | 'hwp' | 'jpeg' | 'jpg' | 'key' | 'ltx' | 'lwp' | 'mcw' | 'met' | 'mml' | 'mw' | 'numbers' | 'odd' | 'odg' | 'odm' | 'odp' | 'ods' | 'odt' | 'otg' | 'oth' | 'otp' | 'ots' | 'ott' | 'pages' | 'pbm' | 'pcd' | 'pct' | 'pcx' | 'pdb' | 'pdf' | 'pgm' | 'png' | 'pot' | 'potm' | 'potx' | 'ppm' | 'pps' | 'ppt' | 'pptm' | 'pptx' | 'psd' | 'psw' | 'pub' | 'pwp' | 'pxl' | 'ras' | 'rtf' | 'sda' | 'sdc' | 'sdd' | 'sdp' | 'sdw' | 'sgl' | 'slk' | 'smf' | 'stc' | 'std' | 'sti' | 'stw' | 'svg' | 'svm' | 'swf' | 'sxc' | 'sxd' | 'sxg' | 'sxi' | 'sxm' | 'sxw' | 'tga' | 'tif' | 'tiff' | 'txt' | 'uof' | 'uop' | 'uos' | 'uot' | 'vdx' | 'vor' | 'vsd' | 'vsdm' | 'vsdx' | 'wb2' | 'wk1' | 'wks' | 'wmf' | 'wpd' | 'wpg' | 'wps' | 'xbm' | 'xhtml' | 'xls' | 'xlsb' | 'xlsm' | 'xlsx' | 'xlt' | 'xltm' | 'xltx' | 'xlw' | 'xml' | 'xpm' | 'zabw';
6
+ type FileInfo = {
7
+ data: Buffer | ReadStream;
8
+ ext: FileExtension;
9
+ };
10
+ export type PathLikeOrReadStream = string | FileInfo;
1
11
  export type PageProperties = {
2
12
  landscape?: boolean;
3
13
  nativePageRanges?: {
@@ -6,3 +16,11 @@ export type PageProperties = {
6
16
  };
7
17
  exportFormFields?: boolean;
8
18
  };
19
+ export type ConversionOptions = {
20
+ properties?: PageProperties;
21
+ merge?: boolean;
22
+ pdfa?: PdfFormat;
23
+ pdfUA?: boolean;
24
+ metadata?: Metadata;
25
+ };
26
+ export {};
@@ -0,0 +1,27 @@
1
+ /// <reference types="node" />
2
+ import { PdfFormat, Metadata } from '../common';
3
+ import { PageProperties, PathLikeOrReadStream } 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,sCAAgE;AAKhE,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,10 +1,10 @@
1
1
  import FormData from 'form-data';
2
- import { PathLikeOrReadStream } from '../../common';
3
- import { PageProperties } from '../interfaces/libre-office.types';
2
+ import { ConversionOptions, PageProperties, PathLikeOrReadStream } from '../interfaces/libre-office.types';
4
3
  /**
5
4
  * Utility class for handling common tasks related to LibreOffice conversions.
6
5
  */
7
6
  export declare class LibreOfficeUtils {
7
+ private static getFileInfo;
8
8
  /**
9
9
  * Adds files to the FormData object for LibreOffice conversion.
10
10
  *
@@ -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
  }
@@ -4,13 +4,27 @@ exports.LibreOfficeUtils = 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
- const file_type_1 = require("file-type");
8
7
  const common_1 = require("../../common");
9
8
  const constants_1 = require("./constants");
10
9
  /**
11
10
  * Utility class for handling common tasks related to LibreOffice conversions.
12
11
  */
13
12
  class LibreOfficeUtils {
13
+ static getFileInfo(file) {
14
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
+ if (typeof file === 'string') {
16
+ yield fs_1.promises.access(file, fs_1.constants.R_OK);
17
+ const filename = path_1.default.basename(path_1.default.parse(file).base);
18
+ return {
19
+ data: (0, fs_1.createReadStream)(file),
20
+ ext: path_1.default.extname(filename).slice(1)
21
+ };
22
+ }
23
+ else {
24
+ return { data: file.data, ext: file.ext };
25
+ }
26
+ });
27
+ }
14
28
  /**
15
29
  * Adds files to the FormData object for LibreOffice conversion.
16
30
  *
@@ -20,32 +34,13 @@ class LibreOfficeUtils {
20
34
  */
21
35
  static addFiles(files, data) {
22
36
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
23
- for (const [key, value] of files.entries()) {
24
- let file = value;
25
- let fileInfo;
26
- if (Buffer.isBuffer(value)) {
27
- fileInfo = yield (0, file_type_1.fromBuffer)(value);
28
- }
29
- else if (value instanceof fs_1.ReadStream) {
30
- fileInfo = yield (0, file_type_1.fromStream)(value);
37
+ yield Promise.all(files.map((file, key) => tslib_1.__awaiter(this, void 0, void 0, function* () {
38
+ const fileInfo = yield this.getFileInfo(file);
39
+ if (!constants_1.LIBRE_OFFICE_EXTENSIONS.includes(fileInfo.ext)) {
40
+ throw new Error(`${fileInfo.ext} is not supported`);
31
41
  }
32
- else {
33
- yield fs_1.promises.access(value, fs_1.constants.R_OK);
34
- const filename = path_1.default.basename(value.toString());
35
- fileInfo = { ext: path_1.default.extname(filename).slice(1) };
36
- file = (0, fs_1.createReadStream)(value);
37
- }
38
- if (!fileInfo) {
39
- throw new Error('File type could not be determined');
40
- }
41
- const extension = fileInfo.ext;
42
- if (constants_1.LIBRE_OFFICE_EXTENSIONS.includes(extension)) {
43
- data.append('files', file, `${key}.${extension}`);
44
- }
45
- else {
46
- throw new Error(`${extension} is not supported`);
47
- }
48
- }
42
+ data.append('files', fileInfo.data, `${key}.${fileInfo.ext}`);
43
+ })));
49
44
  });
50
45
  }
51
46
  /**
@@ -69,6 +64,32 @@ class LibreOfficeUtils {
69
64
  data.append('exportFormFields', String(pageProperties.exportFormFields));
70
65
  }
71
66
  }
67
+ /**
68
+ * Customizes the FormData object based on the provided conversion options.
69
+ *
70
+ * @param {FormData} data - The FormData object to be customized.
71
+ * @param {ConversionOptions} options - The conversion options to apply to the FormData.
72
+ * @returns {Promise<void>} A Promise that resolves once the customization is complete.
73
+ */
74
+ static customize(data, options) {
75
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
76
+ if (options.pdfa) {
77
+ data.append('pdfa', options.pdfa);
78
+ }
79
+ if (options.pdfUA) {
80
+ data.append('pdfUA', String(options.pdfUA));
81
+ }
82
+ if (options.merge) {
83
+ data.append('merge', String(options.merge));
84
+ }
85
+ if (options.metadata) {
86
+ data.append('metadata', JSON.stringify(options.metadata));
87
+ }
88
+ if (options.properties) {
89
+ LibreOfficeUtils.addPageProperties(data, options.properties);
90
+ }
91
+ });
92
+ }
72
93
  }
73
94
  exports.LibreOfficeUtils = LibreOfficeUtils;
74
95
  //# 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,wD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SAAS,EAAE,CAAC,CAAC;gBACtD,CAAC;qBAAM,CAAC;oBACJ,MAAM,IAAI,KAAK,CAAC,GAAG,SAAS,mBAAmB,CAAC,CAAC;gBACrD,CAAC;YACL,CAAC;QACL,CAAC;KAAA;IAED;;;;;OAKG;IACI,MAAM,CAAC,iBAAiB,CAC3B,IAAc,EACd,cAA8B;QAE9B,IAAI,cAAc,CAAC,SAAS,EAAE,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,cAAc,CAAC,gBAAgB,EAAE,CAAC;YAClC,uBAAc,CAAC,MAAM,CACjB,cAAc,CAAC,gBAAgB,CAAC,IAAI,GAAG,CAAC;gBACpC,cAAc,CAAC,gBAAgB,CAAC,EAAE,GAAG,CAAC;gBACtC,cAAc,CAAC,gBAAgB,CAAC,EAAE;oBAC9B,cAAc,CAAC,gBAAgB,CAAC,IAAI,EAC5C,0BAA0B,CAC7B,CAAC;YAEF,IAAI,CAAC,MAAM,CACP,kBAAkB,EAClB,GAAG,cAAc,CAAC,gBAAgB,CAAC,IAAI,IAAI,cAAc,CAAC,gBAAgB,CAAC,EAAE,EAAE,CAClF,CAAC;QACN,CAAC;QAED,IAAI,cAAc,CAAC,gBAAgB,KAAK,KAAK,EAAE,CAAC;YAC5C,IAAI,CAAC,MAAM,CACP,kBAAkB,EAClB,MAAM,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAC1C,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AA7ED,4CA6EC"}
1
+ {"version":3,"file":"libre-office.utils.js","sourceRoot":"","sources":["../../../src/libre-office/utils/libre-office.utils.ts"],"names":[],"mappings":";;;;AAAA,2BAA2D;AAC3D,wDAAwB;AAIxB,yCAA8C;AAC9C,2CAAsD;AAOtD;;GAEG;AACH,MAAa,gBAAgB;IACjB,MAAM,CAAO,WAAW,CAAC,IAA0B;;YACvD,IAAI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Q,EAAE,CAAC;gBACnB,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC9D,CAAC;YAED,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gBACrB,gBAAgB,CAAC,iBAAiB,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;YACjE,CAAC;QACL,CAAC;KAAA;CACJ;AAxGD,4CAwGC"}
package/dist/main.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { PdfFormat } from './common/constants';
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.