chromiumly 1.0.3 → 2.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 (103) hide show
  1. package/README.md +64 -20
  2. package/dist/chromium/converters/converter.d.ts +5 -0
  3. package/dist/chromium/converters/converter.js +11 -0
  4. package/dist/chromium/converters/converter.js.map +1 -0
  5. package/dist/chromium/converters/html.converter.d.ts +14 -0
  6. package/dist/chromium/converters/html.converter.js +36 -0
  7. package/dist/chromium/converters/html.converter.js.map +1 -0
  8. package/dist/chromium/converters/markdown.converter.d.ts +15 -0
  9. package/dist/chromium/converters/markdown.converter.js +38 -0
  10. package/dist/chromium/converters/markdown.converter.js.map +1 -0
  11. package/dist/chromium/converters/url.converter.d.ts +13 -0
  12. package/dist/{converters → chromium/converters}/url.converter.js +10 -6
  13. package/dist/chromium/converters/url.converter.js.map +1 -0
  14. package/dist/chromium/index.d.ts +3 -0
  15. package/dist/chromium/index.js +10 -0
  16. package/dist/chromium/index.js.map +1 -0
  17. package/dist/{common → chromium/interfaces}/converter.interface.d.ts +2 -1
  18. package/dist/{common → chromium/interfaces}/converter.interface.js +0 -0
  19. package/dist/chromium/interfaces/converter.interface.js.map +1 -0
  20. package/dist/{common → chromium/interfaces}/converter.types.d.ts +0 -0
  21. package/dist/{common → chromium/interfaces}/converter.types.js +0 -0
  22. package/dist/chromium/interfaces/converter.types.js.map +1 -0
  23. package/dist/chromium/utils/converter.utils.d.ts +5 -0
  24. package/dist/chromium/utils/converter.utils.js +45 -0
  25. package/dist/chromium/utils/converter.utils.js.map +1 -0
  26. package/dist/common/constants.d.ts +5 -0
  27. package/dist/common/constants.js +10 -0
  28. package/dist/common/constants.js.map +1 -0
  29. package/dist/common/gotenberg.utils.d.ts +6 -0
  30. package/dist/common/gotenberg.utils.js +27 -0
  31. package/dist/common/gotenberg.utils.js.map +1 -0
  32. package/dist/common/index.d.ts +2 -0
  33. package/dist/common/index.js +8 -0
  34. package/dist/common/index.js.map +1 -0
  35. package/dist/libre-office/index.d.ts +2 -0
  36. package/dist/libre-office/index.js +6 -0
  37. package/dist/libre-office/index.js.map +1 -0
  38. package/dist/libre-office/interfaces/libre-office.types.d.ts +7 -0
  39. package/dist/libre-office/interfaces/libre-office.types.js +3 -0
  40. package/dist/libre-office/interfaces/libre-office.types.js.map +1 -0
  41. package/dist/libre-office/utils/constants.d.ts +1 -0
  42. package/dist/libre-office/utils/constants.js +82 -0
  43. package/dist/libre-office/utils/constants.js.map +1 -0
  44. package/dist/libre-office/utils/libre-office.utils.d.ts +8 -0
  45. package/dist/libre-office/utils/libre-office.utils.js +44 -0
  46. package/dist/libre-office/utils/libre-office.utils.js.map +1 -0
  47. package/dist/main.config.d.ts +22 -10
  48. package/dist/main.config.js +28 -15
  49. package/dist/main.config.js.map +1 -1
  50. package/dist/main.d.ts +3 -3
  51. package/dist/main.js +9 -7
  52. package/dist/main.js.map +1 -1
  53. package/dist/pdf-engines/index.d.ts +1 -0
  54. package/dist/pdf-engines/index.js +6 -0
  55. package/dist/pdf-engines/index.js.map +1 -0
  56. package/dist/pdf-engines/pdf.engine.d.ts +16 -0
  57. package/dist/pdf-engines/pdf.engine.js +47 -0
  58. package/dist/pdf-engines/pdf.engine.js.map +1 -0
  59. package/dist/pdf-engines/utils/engine.utils.d.ts +6 -0
  60. package/dist/pdf-engines/utils/engine.utils.js +24 -0
  61. package/dist/pdf-engines/utils/engine.utils.js.map +1 -0
  62. package/package.json +3 -2
  63. package/src/chromium/converters/converter.ts +9 -0
  64. package/src/chromium/converters/html.converter.ts +41 -0
  65. package/src/chromium/converters/markdown.converter.ts +45 -0
  66. package/src/{converters → chromium/converters}/url.converter.ts +13 -7
  67. package/src/chromium/index.ts +3 -0
  68. package/src/{common → chromium/interfaces}/converter.interface.ts +2 -1
  69. package/src/{common → chromium/interfaces}/converter.types.ts +0 -0
  70. package/src/chromium/utils/converter.utils.ts +75 -0
  71. package/src/common/constants.ts +5 -0
  72. package/src/common/gotenberg.utils.ts +25 -0
  73. package/src/common/index.ts +2 -0
  74. package/src/libre-office/index.ts +2 -0
  75. package/src/libre-office/interfaces/libre-office.types.ts +4 -0
  76. package/src/libre-office/utils/constants.ts +78 -0
  77. package/src/libre-office/utils/libre-office.utils.ts +51 -0
  78. package/src/main.config.ts +23 -10
  79. package/src/main.ts +3 -3
  80. package/src/pdf-engines/index.ts +1 -0
  81. package/src/pdf-engines/pdf.engine.ts +53 -0
  82. package/src/pdf-engines/utils/engine.utils.ts +18 -0
  83. package/dist/common/converter.d.ts +0 -7
  84. package/dist/common/converter.interface.js.map +0 -1
  85. package/dist/common/converter.js +0 -21
  86. package/dist/common/converter.js.map +0 -1
  87. package/dist/common/converter.types.js.map +0 -1
  88. package/dist/common/converter.utils.d.ts +0 -8
  89. package/dist/common/converter.utils.js +0 -66
  90. package/dist/common/converter.utils.js.map +0 -1
  91. package/dist/converters/html.converter.d.ts +0 -12
  92. package/dist/converters/html.converter.js +0 -26
  93. package/dist/converters/html.converter.js.map +0 -1
  94. package/dist/converters/markdown.converter.d.ts +0 -13
  95. package/dist/converters/markdown.converter.js +0 -27
  96. package/dist/converters/markdown.converter.js.map +0 -1
  97. package/dist/converters/url.converter.d.ts +0 -11
  98. package/dist/converters/url.converter.js.map +0 -1
  99. package/src/.DS_Store +0 -0
  100. package/src/common/converter.ts +0 -18
  101. package/src/common/converter.utils.ts +0 -101
  102. package/src/converters/html.converter.ts +0 -30
  103. package/src/converters/markdown.converter.ts +0 -33
package/README.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # Chromiumly
2
2
 
3
- A lightweight Typescrpit library which interacts with [Gotenberg](https://gotenberg.dev/)'s Chromium module to convert HTML documents to PDF.
3
+ A lightweight Typescrpit library which interacts with [Gotenberg](https://gotenberg.dev/)'s different modules to convert a variety of document formats to PDF files.
4
+
5
+ ## Install
6
+
7
+ Using npm:
8
+
9
+ ```bash
10
+ npm install chromiumly
11
+ ```
12
+
13
+ Using yarn:
14
+
15
+ ```bash
16
+ yarn add chromiumly
17
+ ```
4
18
 
5
19
  ## Prerequisites
6
20
 
@@ -21,7 +35,7 @@ Chromiumly supports both [dotenv](https://www.npmjs.com/package/dotenv) and [con
21
35
  #### dotenv
22
36
 
23
37
  ```bash
24
- GOTENBERG_ENDPOINT=localhost:3000
38
+ GOTENBERG_ENDPOINT=http://localhost:3000
25
39
  ```
26
40
 
27
41
  #### config
@@ -29,28 +43,18 @@ GOTENBERG_ENDPOINT=localhost:3000
29
43
  ```json
30
44
  {
31
45
  "gotenberg": {
32
- "enpdoint": "localhost:3000"
46
+ "enpdoint": "http://localhost:3000"
33
47
  }
34
48
  }
35
49
  ```
36
50
 
37
- ### Usage
38
-
39
- Chromiumly introduces different classes that serve as wrappers to Gotenberg's Chromium [routes](https://gotenberg.dev/docs/modules/chromium#routes).
51
+ ## Modules
40
52
 
41
- Each class comes with two methods :
53
+ Chromiumly introduces different classes that serve as wrappers to Gotenberg's [modules](https://gotenberg.dev/docs/modules/api#modules).
42
54
 
43
- #### convert
44
-
45
- This method takes either a `url`, an `html` file path or `html` and `markdown` file paths and returns a `buffer` which contains the converted PDF file content.
46
-
47
- #### generate
48
-
49
- It is just a generic complementary method that takes the `buffer` returned by the `convert` method, and a chosen `filename` to generate the PDF file.
55
+ ### Chormium
50
56
 
51
- Please note that all the PDF files can be found `__generated__` folder in the root folder of your project
52
-
53
- ### Modules
57
+ There are three different classes that come with a single method (i.e.`convert`) which calls one of Chromium's [routes](https://gotenberg.dev/docs/modules/chromium#routes) to convert `html` and `markdown` files, or a `url` to a `buffer` which contains the converted PDF file content.
54
58
 
55
59
  #### URL
56
60
 
@@ -115,12 +119,52 @@ type PageProperties = {
115
119
  };
116
120
  ```
117
121
 
118
- ### Snippet
122
+ ### PDF Engine
123
+
124
+ The `PDFEngine` combines the functionality of both Gotenberg's [PDF Engines](https://gotenberg.dev/docs/modules/pdf-engines) and [LibreOffice](https://gotenberg.dev/docs/modules/libreoffice) modules to manipulate different file formats.
125
+
126
+ #### convert
127
+
128
+ This method interacts with [LibreOffice](https://gotenberg.dev/docs/modules/libreoffice) module to convert different documents to PDF files. You can find the file extensions accepted [here](https://gotenberg.dev/docs/modules/libreoffice#route).
129
+
130
+ ```typescript
131
+ import { PDFEngine } from "chromiumly";
132
+
133
+ const buffer = await PDFEngine.convert({
134
+ files: ["path/to/file.docx", "path/to/file.png"],
135
+ });
136
+ ```
137
+
138
+ Similarly to Chromium's module `convert` method, this method takes the following optional parameters :
139
+
140
+ - `properties`: changes how the PDF generated file will look like.
141
+ - `pdfFormat`: PDF format of the conversion resulting file (i.e. `PDF/A-1a`, `PDF/A-2b`, `PDF/A-3b`).
142
+ - `merge`: merge all the resulting files from the conversion into an individual PDF file.
143
+
144
+ #### merge
145
+
146
+ This method interacts with [PDF Engines](https://gotenberg.dev/docs/modules/pdf-engines) module which gathers different engines that can manipulate and merge PDF files such as: [PDFtk](https://gitlab.com/pdftk-java/pdftk), [PDFcpu](https://github.com/pdfcpu/pdfcpu), [QPDF](https://github.com/qpdf/qpdf), and [UNO](https://github.com/unoconv/unoconv).
147
+
148
+ ```typescript
149
+ import { PDFEngine } from "chromiumly";
150
+
151
+ const buffer = await PDFEngine.merge({
152
+ files: ["path/to/file.docx", "path/to/file.png"],
153
+ });
154
+ ```
155
+
156
+ #### generate
157
+
158
+ It is just a generic complementary method that takes the `buffer` returned by the `convert` method, and a chosen `filename` to generate the PDF file.
159
+
160
+ Please note that all the PDF files can be found `__generated__` folder in the root folder of your project.
161
+
162
+ ## Snippet
119
163
 
120
164
  The following is a short snippet of how to use the library.
121
165
 
122
166
  ```typescript
123
- import { UrlConverter } from "chromiumly";
167
+ import { PDFEngine, UrlConverter } from "chromiumly";
124
168
 
125
169
  async function run() {
126
170
  const urlConverter = new UrlConverter();
@@ -128,7 +172,7 @@ async function run() {
128
172
  url: "https://gotenberg.dev/",
129
173
  });
130
174
 
131
- await urlConverter.generate("gotenberg.pdf", buffer);
175
+ await PDFEngine.generate("gotenberg.pdf", buffer);
132
176
  }
133
177
 
134
178
  run();
@@ -0,0 +1,5 @@
1
+ import { ChromiumRoute } from "../../main.config";
2
+ export declare abstract class Converter {
3
+ readonly endpoint: string;
4
+ constructor(route: ChromiumRoute);
5
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Converter = void 0;
4
+ const main_config_1 = require("../../main.config");
5
+ class Converter {
6
+ constructor(route) {
7
+ this.endpoint = `${main_config_1.Chromiumly.GOTENBERG_ENDPOINT}/${main_config_1.Chromiumly.CHROMIUM_PATH}/${main_config_1.Chromiumly.CHROMIUM_ROUTES[route]}`;
8
+ }
9
+ }
10
+ exports.Converter = Converter;
11
+ //# sourceMappingURL=converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/converter.ts"],"names":[],"mappings":";;;AAAA,mDAA8D;AAE9D,MAAsB,SAAS;IAG7B,YAAY,KAAoB;QAC9B,IAAI,CAAC,QAAQ,GAAG,GAAG,wBAAU,CAAC,kBAAkB,IAAI,wBAAU,CAAC,aAAa,IAAI,wBAAU,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;IACtH,CAAC;CACF;AAND,8BAMC"}
@@ -0,0 +1,14 @@
1
+ /// <reference types="node" />
2
+ import { PathLike } from "fs";
3
+ import { PdfFormat } from "../../common";
4
+ import { IConverter } from "../interfaces/converter.interface";
5
+ import { PageProperties } from "../interfaces/converter.types";
6
+ import { Converter } from "./converter";
7
+ export declare class HtmlConverter extends Converter implements IConverter {
8
+ constructor();
9
+ convert({ html, properties, pdfFormat, }: {
10
+ html: PathLike;
11
+ properties?: PageProperties;
12
+ pdfFormat?: PdfFormat;
13
+ }): Promise<Buffer>;
14
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HtmlConverter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = require("fs");
6
+ const form_data_1 = tslib_1.__importDefault(require("form-data"));
7
+ const common_1 = require("../../common");
8
+ const converter_utils_1 = require("../utils/converter.utils");
9
+ const converter_1 = require("./converter");
10
+ const main_config_1 = require("../../main.config");
11
+ class HtmlConverter extends converter_1.Converter {
12
+ constructor() {
13
+ super(main_config_1.ChromiumRoute.HTML);
14
+ }
15
+ convert({ html, properties, pdfFormat, }) {
16
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
17
+ try {
18
+ yield fs_1.promises.access(html, fs_1.constants.R_OK);
19
+ const data = new form_data_1.default();
20
+ if (pdfFormat) {
21
+ data.append("pdfFormat", pdfFormat);
22
+ }
23
+ data.append("index.html", (0, fs_1.createReadStream)(html));
24
+ if (properties) {
25
+ converter_utils_1.ConverterUtils.injectPageProperties(data, properties);
26
+ }
27
+ return common_1.GotenbergUtils.fetch(this.endpoint, data);
28
+ }
29
+ catch (error) {
30
+ throw error;
31
+ }
32
+ });
33
+ }
34
+ }
35
+ exports.HtmlConverter = HtmlConverter;
36
+ //# sourceMappingURL=html.converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/html.converter.ts"],"names":[],"mappings":";;;;AAAA,2BAAqE;AAErE,kEAAiC;AAEjC,yCAAyD;AAGzD,8DAA0D;AAC1D,2CAAwC;AACxC,mDAAkD;AAElD,MAAa,aAAc,SAAQ,qBAAS;IAC1C;QACE,KAAK,CAAC,2BAAa,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEK,OAAO,CAAC,EACZ,IAAI,EACJ,UAAU,EACV,SAAS,GAKV;;YACC,IAAI;gBACF,MAAM,aAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;gBAC5C,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;gBAC5B,IAAI,SAAS,EAAE;oBACb,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;iBACrC;gBACD,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC,CAAC;gBAClD,IAAI,UAAU,EAAE;oBACd,gCAAc,CAAC,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;iBACvD;gBACD,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AA7BD,sCA6BC"}
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ import { PathLike } from "fs";
3
+ import { PdfFormat } from "../../common";
4
+ import { IConverter } from "../interfaces/converter.interface";
5
+ import { PageProperties } from "../interfaces/converter.types";
6
+ import { Converter } from "./converter";
7
+ export declare class MarkdownConverter extends Converter implements IConverter {
8
+ constructor();
9
+ convert({ html, markdown, properties, pdfFormat, }: {
10
+ html: PathLike;
11
+ markdown: PathLike;
12
+ properties?: PageProperties;
13
+ pdfFormat?: PdfFormat;
14
+ }): Promise<Buffer>;
15
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MarkdownConverter = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = require("fs");
6
+ const form_data_1 = tslib_1.__importDefault(require("form-data"));
7
+ const common_1 = require("../../common");
8
+ const converter_utils_1 = require("../utils/converter.utils");
9
+ const converter_1 = require("./converter");
10
+ const main_config_1 = require("../../main.config");
11
+ class MarkdownConverter extends converter_1.Converter {
12
+ constructor() {
13
+ super(main_config_1.ChromiumRoute.MARKDOWN);
14
+ }
15
+ convert({ html, markdown, properties, pdfFormat, }) {
16
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
17
+ try {
18
+ yield fs_1.promises.access(html, fs_1.constants.R_OK);
19
+ yield fs_1.promises.access(markdown, fs_1.constants.R_OK);
20
+ const data = new form_data_1.default();
21
+ if (pdfFormat) {
22
+ data.append("pdfFormat", pdfFormat);
23
+ }
24
+ data.append("index.html", (0, fs_1.createReadStream)(html));
25
+ data.append("file.md", (0, fs_1.createReadStream)(markdown));
26
+ if (properties) {
27
+ converter_utils_1.ConverterUtils.injectPageProperties(data, properties);
28
+ }
29
+ return common_1.GotenbergUtils.fetch(this.endpoint, data);
30
+ }
31
+ catch (error) {
32
+ throw error;
33
+ }
34
+ });
35
+ }
36
+ }
37
+ exports.MarkdownConverter = MarkdownConverter;
38
+ //# sourceMappingURL=markdown.converter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/markdown.converter.ts"],"names":[],"mappings":";;;;AAAA,2BAAqE;AAErE,kEAAiC;AAEjC,yCAAyD;AAGzD,8DAA0D;AAC1D,2CAAwC;AACxC,mDAAkD;AAElD,MAAa,iBAAkB,SAAQ,qBAAS;IAC9C;QACE,KAAK,CAAC,2BAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAEK,OAAO,CAAC,EACZ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,SAAS,GAMV;;YACC,IAAI;gBACF,MAAM,aAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;gBAC5C,MAAM,aAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAS,CAAC,IAAI,CAAC,CAAC;gBAChD,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;gBAC5B,IAAI,SAAS,EAAE;oBACb,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;iBACrC;gBACD,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAC,CAAC;gBAClD,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,IAAA,qBAAgB,EAAC,QAAQ,CAAC,CAAC,CAAC;gBACnD,IAAI,UAAU,EAAE;oBACd,gCAAc,CAAC,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;iBACvD;gBACD,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AAjCD,8CAiCC"}
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import { PdfFormat } from "../../common";
3
+ import { IConverter } from "../interfaces/converter.interface";
4
+ import { PageProperties } from "../interfaces/converter.types";
5
+ import { Converter } from "./converter";
6
+ export declare class UrlConverter extends Converter implements IConverter {
7
+ constructor();
8
+ convert({ url, properties, pdfFormat, }: {
9
+ url: string;
10
+ properties?: PageProperties;
11
+ pdfFormat?: PdfFormat;
12
+ }): Promise<Buffer>;
13
+ }
@@ -4,23 +4,27 @@ exports.UrlConverter = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const url_1 = require("url");
6
6
  const form_data_1 = tslib_1.__importDefault(require("form-data"));
7
- const converter_utils_1 = require("../common/converter.utils");
8
- const converter_1 = require("../common/converter");
9
- const main_config_1 = require("../main.config");
7
+ const common_1 = require("../../common");
8
+ const converter_utils_1 = require("../utils/converter.utils");
9
+ const converter_1 = require("./converter");
10
+ const main_config_1 = require("../../main.config");
10
11
  class UrlConverter extends converter_1.Converter {
11
12
  constructor() {
12
- super(main_config_1.Route.URL);
13
+ super(main_config_1.ChromiumRoute.URL);
13
14
  }
14
- convert({ url, properties, }) {
15
+ convert({ url, properties, pdfFormat, }) {
15
16
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
17
  try {
17
18
  const _url = new url_1.URL(url);
18
19
  const data = new form_data_1.default();
20
+ if (pdfFormat) {
21
+ data.append("pdfFormat", pdfFormat);
22
+ }
19
23
  data.append("url", _url.href);
20
24
  if (properties) {
21
25
  converter_utils_1.ConverterUtils.injectPageProperties(data, properties);
22
26
  }
23
- return converter_utils_1.ConverterUtils.fetch(this.endpoint, data);
27
+ return common_1.GotenbergUtils.fetch(this.endpoint, data);
24
28
  }
25
29
  catch (error) {
26
30
  throw error;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.converter.js","sourceRoot":"","sources":["../../../src/chromium/converters/url.converter.ts"],"names":[],"mappings":";;;;AAAA,6BAA0B;AAE1B,kEAAiC;AAEjC,yCAAyD;AAGzD,8DAA0D;AAC1D,2CAAwC;AACxC,mDAAkD;AAElD,MAAa,YAAa,SAAQ,qBAAS;IACzC;QACE,KAAK,CAAC,2BAAa,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEK,OAAO,CAAC,EACZ,GAAG,EACH,UAAU,EACV,SAAS,GAKV;;YACC,IAAI;gBACF,MAAM,IAAI,GAAG,IAAI,SAAG,CAAC,GAAG,CAAC,CAAC;gBAC1B,MAAM,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;gBAC5B,IAAI,SAAS,EAAE;oBACb,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;iBACrC;gBACD,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC9B,IAAI,UAAU,EAAE;oBACd,gCAAc,CAAC,oBAAoB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;iBACvD;gBACD,OAAO,uBAAc,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;aAClD;YAAC,OAAO,KAAK,EAAE;gBACd,MAAM,KAAK,CAAC;aACb;QACH,CAAC;KAAA;CACF;AA7BD,oCA6BC"}
@@ -0,0 +1,3 @@
1
+ export { HtmlConverter } from "./converters/html.converter";
2
+ export { MarkdownConverter } from "./converters/markdown.converter";
3
+ export { UrlConverter } from "./converters/url.converter";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UrlConverter = exports.MarkdownConverter = exports.HtmlConverter = void 0;
4
+ var html_converter_1 = require("./converters/html.converter");
5
+ Object.defineProperty(exports, "HtmlConverter", { enumerable: true, get: function () { return html_converter_1.HtmlConverter; } });
6
+ var markdown_converter_1 = require("./converters/markdown.converter");
7
+ Object.defineProperty(exports, "MarkdownConverter", { enumerable: true, get: function () { return markdown_converter_1.MarkdownConverter; } });
8
+ var url_converter_1 = require("./converters/url.converter");
9
+ Object.defineProperty(exports, "UrlConverter", { enumerable: true, get: function () { return url_converter_1.UrlConverter; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chromium/index.ts"],"names":[],"mappings":";;;AAAA,8DAA4D;AAAnD,+GAAA,aAAa,OAAA;AACtB,sEAAoE;AAA3D,uHAAA,iBAAiB,OAAA;AAC1B,4DAA0D;AAAjD,6GAAA,YAAY,OAAA"}
@@ -1,8 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import { PathLike } from "fs";
3
+ import { PdfFormat } from "../../common";
3
4
  import { PageProperties } from "./converter.types";
4
5
  export interface IConverter {
5
6
  convert({ ...args }: {
6
- [x: string]: string | PathLike | PageProperties;
7
+ [x: string]: string | PathLike | PageProperties | PdfFormat;
7
8
  }): Promise<Buffer>;
8
9
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converter.interface.js","sourceRoot":"","sources":["../../../src/chromium/interfaces/converter.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converter.types.js","sourceRoot":"","sources":["../../../src/chromium/interfaces/converter.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import FormData from "form-data";
2
+ import { PageProperties } from "../interfaces/converter.types";
3
+ export declare class ConverterUtils {
4
+ static injectPageProperties(data: FormData, pageProperties: PageProperties): void;
5
+ }
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConverterUtils = void 0;
4
+ const gotenberg_utils_1 = require("../../common/gotenberg.utils");
5
+ class ConverterUtils {
6
+ static injectPageProperties(data, pageProperties) {
7
+ if (pageProperties.size) {
8
+ gotenberg_utils_1.GotenbergUtils.assert(pageProperties.size.width >= 1.0 && pageProperties.size.height >= 1.5, "size is smaller than the minimum printing requirements (i.e. 1.0 x 1.5 in)");
9
+ data.append("paperWidth", pageProperties.size.width);
10
+ data.append("paperHeight", pageProperties.size.height);
11
+ }
12
+ if (pageProperties.margins) {
13
+ gotenberg_utils_1.GotenbergUtils.assert(pageProperties.margins.top >= 0 &&
14
+ pageProperties.margins.bottom >= 0 &&
15
+ pageProperties.margins.left >= 0 &&
16
+ pageProperties.margins.left >= 0, "negative margins are not allowed");
17
+ data.append("marginTop", pageProperties.margins.top);
18
+ data.append("marginBottom", pageProperties.margins.bottom);
19
+ data.append("marginLeft", pageProperties.margins.left);
20
+ data.append("marginRight", pageProperties.margins.right);
21
+ }
22
+ if (pageProperties.preferCssPageSize) {
23
+ data.append("preferCssPageSize", String(pageProperties.preferCssPageSize));
24
+ }
25
+ if (pageProperties.printBackground) {
26
+ data.append("printBackground", String(pageProperties.printBackground));
27
+ }
28
+ if (pageProperties.landscape) {
29
+ data.append("landscape", String(pageProperties.landscape));
30
+ }
31
+ if (pageProperties.scale) {
32
+ gotenberg_utils_1.GotenbergUtils.assert(pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0, "scale is outside of [0.1 - 2] range");
33
+ data.append("scale", pageProperties.scale);
34
+ }
35
+ if (pageProperties.nativePageRanges) {
36
+ gotenberg_utils_1.GotenbergUtils.assert(pageProperties.nativePageRanges.from > 0 &&
37
+ pageProperties.nativePageRanges.to > 0 &&
38
+ pageProperties.nativePageRanges.to >=
39
+ pageProperties.nativePageRanges.from, "page ranges syntax error");
40
+ data.append("nativePageRanges", `${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`);
41
+ }
42
+ }
43
+ }
44
+ exports.ConverterUtils = ConverterUtils;
45
+ //# sourceMappingURL=converter.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"converter.utils.js","sourceRoot":"","sources":["../../../src/chromium/utils/converter.utils.ts"],"names":[],"mappings":";;;AAEA,kEAA8D;AAG9D,MAAa,cAAc;IAClB,MAAM,CAAC,oBAAoB,CAChC,IAAc,EACd,cAA8B;QAE9B,IAAI,cAAc,CAAC,IAAI,EAAE;YACvB,gCAAc,CAAC,MAAM,CACnB,cAAc,CAAC,IAAI,CAAC,KAAK,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,IAAI,GAAG,EACrE,4EAA4E,CAC7E,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACrD,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACxD;QAED,IAAI,cAAc,CAAC,OAAO,EAAE;YAC1B,gCAAc,CAAC,MAAM,CACnB,cAAc,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;gBAC7B,cAAc,CAAC,OAAO,CAAC,MAAM,IAAI,CAAC;gBAClC,cAAc,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;gBAChC,cAAc,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,EAClC,kCAAkC,CACnC,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YACrD,IAAI,CAAC,MAAM,CAAC,cAAc,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC3D,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACvD,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;SAC1D;QAED,IAAI,cAAc,CAAC,iBAAiB,EAAE;YACpC,IAAI,CAAC,MAAM,CACT,mBAAmB,EACnB,MAAM,CAAC,cAAc,CAAC,iBAAiB,CAAC,CACzC,CAAC;SACH;QAED,IAAI,cAAc,CAAC,eAAe,EAAE;YAClC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC,CAAC;SACxE;QAED,IAAI,cAAc,CAAC,SAAS,EAAE;YAC5B,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;SAC5D;QAED,IAAI,cAAc,CAAC,KAAK,EAAE;YACxB,gCAAc,CAAC,MAAM,CACnB,cAAc,CAAC,KAAK,IAAI,GAAG,IAAI,cAAc,CAAC,KAAK,IAAI,GAAG,EAC1D,qCAAqC,CACtC,CAAC;YAEF,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC;SAC5C;QAED,IAAI,cAAc,CAAC,gBAAgB,EAAE;YACnC,gCAAc,CAAC,MAAM,CACnB,cAAc,CAAC,gBAAgB,CAAC,IAAI,GAAG,CAAC;gBACtC,cAAc,CAAC,gBAAgB,CAAC,EAAE,GAAG,CAAC;gBACtC,cAAc,CAAC,gBAAgB,CAAC,EAAE;oBAChC,cAAc,CAAC,gBAAgB,CAAC,IAAI,EACxC,0BAA0B,CAC3B,CAAC;YAEF,IAAI,CAAC,MAAM,CACT,kBAAkB,EAClB,GAAG,cAAc,CAAC,gBAAgB,CAAC,IAAI,IAAI,cAAc,CAAC,gBAAgB,CAAC,EAAE,EAAE,CAChF,CAAC;SACH;IACH,CAAC;CACF;AArED,wCAqEC"}
@@ -0,0 +1,5 @@
1
+ export declare enum PdfFormat {
2
+ A_1a = "PDF/A-1a",
3
+ A_2b = "PDF/A-2b",
4
+ A_3b = "PDF/A-3b"
5
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PdfFormat = void 0;
4
+ var PdfFormat;
5
+ (function (PdfFormat) {
6
+ PdfFormat["A_1a"] = "PDF/A-1a";
7
+ PdfFormat["A_2b"] = "PDF/A-2b";
8
+ PdfFormat["A_3b"] = "PDF/A-3b";
9
+ })(PdfFormat = exports.PdfFormat || (exports.PdfFormat = {}));
10
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;AACnB,CAAC,EAJW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAIpB"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import FormData from "form-data";
3
+ export declare class GotenbergUtils {
4
+ static assert(condition: boolean, message: string): asserts condition;
5
+ static fetch(endpoint: string, data: FormData): Promise<Buffer>;
6
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GotenbergUtils = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
6
+ class GotenbergUtils {
7
+ static assert(condition, message) {
8
+ if (!condition) {
9
+ throw new Error(message);
10
+ }
11
+ }
12
+ static fetch(endpoint, data) {
13
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
+ const response = yield (0, node_fetch_1.default)(endpoint, {
15
+ method: "post",
16
+ body: data,
17
+ headers: Object.assign({}, data.getHeaders()),
18
+ });
19
+ if (!response.ok) {
20
+ throw new Error(`${response.status} ${response.statusText}`);
21
+ }
22
+ return response.buffer();
23
+ });
24
+ }
25
+ }
26
+ exports.GotenbergUtils = GotenbergUtils;
27
+ //# sourceMappingURL=gotenberg.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gotenberg.utils.js","sourceRoot":"","sources":["../../src/common/gotenberg.utils.ts"],"names":[],"mappings":";;;;AACA,oEAA+B;AAE/B,MAAa,cAAc;IAClB,MAAM,CAAC,MAAM,CAAC,SAAkB,EAAE,OAAe;QACtD,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;SAC1B;IACH,CAAC;IAEM,MAAM,CAAO,KAAK,CAAC,QAAgB,EAAE,IAAc;;YACxD,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,QAAQ,EAAE;gBACrC,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI;gBACV,OAAO,oBACF,IAAI,CAAC,UAAU,EAAE,CACrB;aACF,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;gBAChB,MAAM,IAAI,KAAK,CAAC,GAAG,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;aAC9D;YACD,OAAO,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC3B,CAAC;KAAA;CACF;AArBD,wCAqBC"}
@@ -0,0 +1,2 @@
1
+ export { PdfFormat } from "./constants";
2
+ export { GotenbergUtils } from "./gotenberg.utils";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GotenbergUtils = exports.PdfFormat = void 0;
4
+ var constants_1 = require("./constants");
5
+ Object.defineProperty(exports, "PdfFormat", { enumerable: true, get: function () { return constants_1.PdfFormat; } });
6
+ var gotenberg_utils_1 = require("./gotenberg.utils");
7
+ Object.defineProperty(exports, "GotenbergUtils", { enumerable: true, get: function () { return gotenberg_utils_1.GotenbergUtils; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common/index.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAA/B,sGAAA,SAAS,OAAA;AAClB,qDAAmD;AAA1C,iHAAA,cAAc,OAAA"}
@@ -0,0 +1,2 @@
1
+ export { PageProperties } from "./interfaces/libre-office.types";
2
+ export { LibreOfficeUtils } from "./utils/libre-office.utils";
@@ -0,0 +1,6 @@
1
+ "use strict";
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; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/libre-office/index.ts"],"names":[],"mappings":";;;AACA,iEAA8D;AAArD,sHAAA,gBAAgB,OAAA"}
@@ -0,0 +1,7 @@
1
+ export declare type PageProperties = {
2
+ landscape?: boolean;
3
+ nativePageRanges?: {
4
+ from: number;
5
+ to: number;
6
+ };
7
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=libre-office.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"libre-office.types.js","sourceRoot":"","sources":["../../../src/libre-office/interfaces/libre-office.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare const LIBRE_OFFICE_EXTENSIONS: string[];
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LIBRE_OFFICE_EXTENSIONS = void 0;
4
+ exports.LIBRE_OFFICE_EXTENSIONS = [
5
+ ".bib",
6
+ ".doc",
7
+ ".xml",
8
+ ".docx",
9
+ ".fodt",
10
+ ".html",
11
+ ".ltx",
12
+ ".txt",
13
+ ".odt",
14
+ ".ott",
15
+ ".pdb",
16
+ ".pdf",
17
+ ".psw",
18
+ ".rtf",
19
+ ".sdw",
20
+ ".stw",
21
+ ".sxw",
22
+ ".uot",
23
+ ".vor",
24
+ ".wps",
25
+ ".epub",
26
+ ".png",
27
+ ".bmp",
28
+ ".emf",
29
+ ".eps",
30
+ ".fodg",
31
+ ".gif",
32
+ ".jpg",
33
+ ".met",
34
+ ".odd",
35
+ ".otg",
36
+ ".pbm",
37
+ ".pct",
38
+ ".pgm",
39
+ ".ppm",
40
+ ".ras",
41
+ ".std",
42
+ ".svg",
43
+ ".svm",
44
+ ".swf",
45
+ ".sxd",
46
+ ".sxw",
47
+ ".tiff",
48
+ ".xhtml",
49
+ ".xpm",
50
+ ".fodp",
51
+ ".potm",
52
+ ".pot",
53
+ ".pptx",
54
+ ".pps",
55
+ ".ppt",
56
+ ".pwp",
57
+ ".sda",
58
+ ".sdd",
59
+ ".sti",
60
+ ".sxi",
61
+ ".uop",
62
+ ".wmf",
63
+ ".csv",
64
+ ".dbf",
65
+ ".dif",
66
+ ".fods",
67
+ ".ods",
68
+ ".ots",
69
+ ".pxl",
70
+ ".sdc",
71
+ ".slk",
72
+ ".stc",
73
+ ".sxc",
74
+ ".uos",
75
+ ".xls",
76
+ ".xlt",
77
+ ".xlsx",
78
+ ".tif",
79
+ ".jpeg",
80
+ ".odp",
81
+ ];
82
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/libre-office/utils/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAG;IACrC,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,OAAO;IACP,MAAM;CACP,CAAC"}