officetopdf-js 0.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 (40) hide show
  1. package/LICENSE +216 -0
  2. package/README.md +152 -0
  3. package/dist/browser.cjs +155 -0
  4. package/dist/browser.d.ts +8 -0
  5. package/dist/browser.d.ts.map +1 -0
  6. package/dist/browser.js +86 -0
  7. package/dist/chunk-A2DPXSQU.js +64 -0
  8. package/dist/errors/OfficeToPdfError.d.ts +11 -0
  9. package/dist/errors/OfficeToPdfError.d.ts.map +1 -0
  10. package/dist/index.cjs +229 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +153 -0
  14. package/dist/internal/binary.d.ts +2 -0
  15. package/dist/internal/binary.d.ts.map +1 -0
  16. package/dist/internal/cli-args.d.ts +4 -0
  17. package/dist/internal/cli-args.d.ts.map +1 -0
  18. package/dist/internal/convenience.d.ts +11 -0
  19. package/dist/internal/convenience.d.ts.map +1 -0
  20. package/dist/internal/shared.d.ts +4 -0
  21. package/dist/internal/shared.d.ts.map +1 -0
  22. package/dist/node.d.ts +8 -0
  23. package/dist/node.d.ts.map +1 -0
  24. package/dist/types.d.ts +37 -0
  25. package/dist/types.d.ts.map +1 -0
  26. package/package.json +92 -0
  27. package/src/__tests__/binary.test.ts +53 -0
  28. package/src/__tests__/cli-args.test.ts +87 -0
  29. package/src/__tests__/convenience.test.ts +36 -0
  30. package/src/__tests__/shared.test.ts +43 -0
  31. package/src/browser.ts +125 -0
  32. package/src/errors/OfficeToPdfError.ts +27 -0
  33. package/src/index.ts +1 -0
  34. package/src/internal/binary.ts +49 -0
  35. package/src/internal/cli-args.ts +28 -0
  36. package/src/internal/convenience.ts +19 -0
  37. package/src/internal/shared.ts +31 -0
  38. package/src/node.ts +124 -0
  39. package/src/types/officetopdf-wasm.d.ts +37 -0
  40. package/src/types.ts +42 -0
@@ -0,0 +1,64 @@
1
+ // src/errors/OfficeToPdfError.ts
2
+ var OfficeToPdfError = class extends Error {
3
+ constructor(message, options) {
4
+ super(message, options);
5
+ this.name = "OfficeToPdfError";
6
+ }
7
+ };
8
+ var UnsupportedPlatformError = class extends OfficeToPdfError {
9
+ constructor(platform, arch, options) {
10
+ super(
11
+ `No office2pdf binary is available for ${platform}-${arch}. Install the matching platform package, or set OFFICE2PDF_BINARY to a local binary.`,
12
+ options
13
+ );
14
+ this.name = "UnsupportedPlatformError";
15
+ }
16
+ };
17
+ var ConversionFailedError = class extends OfficeToPdfError {
18
+ constructor(message, detail) {
19
+ super(detail ? `${message}: ${detail}` : message);
20
+ this.detail = detail;
21
+ this.name = "ConversionFailedError";
22
+ }
23
+ detail;
24
+ };
25
+
26
+ // src/internal/convenience.ts
27
+ function shortcut(convert, format) {
28
+ return (input, options) => convert(input, { ...options, format });
29
+ }
30
+ function createFormatShortcuts(convert) {
31
+ return {
32
+ docxToPdf: shortcut(convert, "docx"),
33
+ pptxToPdf: shortcut(convert, "pptx"),
34
+ xlsxToPdf: shortcut(convert, "xlsx")
35
+ };
36
+ }
37
+
38
+ // src/internal/shared.ts
39
+ var FORMATS = ["docx", "pptx", "xlsx"];
40
+ async function toBytes(input) {
41
+ if (input instanceof Uint8Array) return input;
42
+ if (input instanceof ArrayBuffer) return new Uint8Array(input);
43
+ if (typeof Blob !== "undefined" && input instanceof Blob) {
44
+ return new Uint8Array(await input.arrayBuffer());
45
+ }
46
+ throw new OfficeToPdfError("Input must be a Uint8Array, ArrayBuffer, or Blob.");
47
+ }
48
+ function resolveFormat(input, options) {
49
+ if (options.format) {
50
+ if (!FORMATS.includes(options.format)) {
51
+ throw new OfficeToPdfError(`Unsupported format "${options.format}".`);
52
+ }
53
+ return options.format;
54
+ }
55
+ const name = input.name;
56
+ const extension = typeof name === "string" ? name.split(".").pop()?.toLowerCase() : void 0;
57
+ const inferred = FORMATS.find((format) => format === extension);
58
+ if (inferred) return inferred;
59
+ throw new OfficeToPdfError(
60
+ 'Unable to infer the input format. Pass { format: "docx" | "pptx" | "xlsx" }.'
61
+ );
62
+ }
63
+
64
+ export { ConversionFailedError, OfficeToPdfError, UnsupportedPlatformError, createFormatShortcuts, resolveFormat, toBytes };
@@ -0,0 +1,11 @@
1
+ export declare class OfficeToPdfError extends Error {
2
+ constructor(message: string, options?: ErrorOptions);
3
+ }
4
+ export declare class UnsupportedPlatformError extends OfficeToPdfError {
5
+ constructor(platform: string, arch: string, options?: ErrorOptions);
6
+ }
7
+ export declare class ConversionFailedError extends OfficeToPdfError {
8
+ readonly detail?: string | undefined;
9
+ constructor(message: string, detail?: string | undefined);
10
+ }
11
+ //# sourceMappingURL=OfficeToPdfError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OfficeToPdfError.d.ts","sourceRoot":"","sources":["../../src/errors/OfficeToPdfError.ts"],"names":[],"mappings":"AAAA,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAGlD;CACF;AAED,qBAAa,wBAAyB,SAAQ,gBAAgB;IAC5D,YAAY,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,EAOjE;CACF;AAED,qBAAa,qBAAsB,SAAQ,gBAAgB;IAGvD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IAF1B,YACE,OAAO,EAAE,MAAM,EACN,MAAM,CAAC,EAAE,MAAM,YAAA,EAIzB;CACF"}
package/dist/index.cjs ADDED
@@ -0,0 +1,229 @@
1
+ 'use strict';
2
+
3
+ var child_process = require('child_process');
4
+ var promises = require('fs/promises');
5
+ var os = require('os');
6
+ var path = require('path');
7
+ var util = require('util');
8
+ var module$1 = require('module');
9
+ var process = require('process');
10
+
11
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var process__default = /*#__PURE__*/_interopDefault(process);
15
+
16
+ // src/node.ts
17
+
18
+ // src/errors/OfficeToPdfError.ts
19
+ var OfficeToPdfError = class extends Error {
20
+ constructor(message, options) {
21
+ super(message, options);
22
+ this.name = "OfficeToPdfError";
23
+ }
24
+ };
25
+ var UnsupportedPlatformError = class extends OfficeToPdfError {
26
+ constructor(platform, arch, options) {
27
+ super(
28
+ `No office2pdf binary is available for ${platform}-${arch}. Install the matching platform package, or set OFFICE2PDF_BINARY to a local binary.`,
29
+ options
30
+ );
31
+ this.name = "UnsupportedPlatformError";
32
+ }
33
+ };
34
+ var ConversionFailedError = class extends OfficeToPdfError {
35
+ constructor(message, detail) {
36
+ super(detail ? `${message}: ${detail}` : message);
37
+ this.detail = detail;
38
+ this.name = "ConversionFailedError";
39
+ }
40
+ detail;
41
+ };
42
+ var require2 = module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
43
+ var PLATFORM_PACKAGES = {
44
+ "darwin-arm64": "officetopdf-darwin-arm64",
45
+ "darwin-x64": "officetopdf-darwin-x64",
46
+ "linux-arm64": "officetopdf-linux-arm64",
47
+ "linux-x64": "officetopdf-linux-x64",
48
+ "linux-x64-musl": "officetopdf-linux-x64-musl",
49
+ "win32-x64": "officetopdf-windows-x64"
50
+ };
51
+ function isMusl() {
52
+ const report = process__default.default.report?.getReport();
53
+ if (typeof report === "object" && report !== null && "header" in report) {
54
+ const header = report.header;
55
+ return !header?.glibcVersionRuntime;
56
+ }
57
+ return false;
58
+ }
59
+ function currentTarget() {
60
+ const target = `${process__default.default.platform}-${process__default.default.arch}`;
61
+ return target === "linux-x64" && isMusl() ? "linux-x64-musl" : target;
62
+ }
63
+ var cached;
64
+ function resolveBinaryPath(override) {
65
+ const explicit = override ?? process__default.default.env.OFFICE2PDF_BINARY;
66
+ if (explicit) return explicit;
67
+ if (cached) return cached;
68
+ const target = currentTarget();
69
+ const packageName = PLATFORM_PACKAGES[target];
70
+ if (!packageName) throw new UnsupportedPlatformError(process__default.default.platform, process__default.default.arch);
71
+ const executable = process__default.default.platform === "win32" ? "office2pdf.exe" : "office2pdf";
72
+ try {
73
+ cached = path.join(path.dirname(require2.resolve(`${packageName}/package.json`)), executable);
74
+ } catch (cause) {
75
+ throw new UnsupportedPlatformError(process__default.default.platform, process__default.default.arch, { cause });
76
+ }
77
+ return cached;
78
+ }
79
+
80
+ // src/internal/cli-args.ts
81
+ function buildArgs(inputPath, outputPath, fontPaths, options) {
82
+ const args = [inputPath, "--output", outputPath];
83
+ if (options.paperSize) args.push("--paper", options.paperSize);
84
+ if (options.landscape) args.push("--landscape");
85
+ if (options.pdfA) args.push("--pdf-a");
86
+ if (options.tagged) args.push("--tagged");
87
+ if (options.pdfUa) args.push("--pdf-ua");
88
+ if (options.sheets?.length) args.push("--sheets", options.sheets.join(","));
89
+ if (options.slides) args.push("--slides", options.slides);
90
+ for (const fontPath of fontPaths) args.push("--font-path", fontPath);
91
+ return args;
92
+ }
93
+ function fontExtension(bytes) {
94
+ const magic = String.fromCharCode(...bytes.subarray(0, 4));
95
+ if (magic === "ttcf") return "ttc";
96
+ if (magic === "OTTO") return "otf";
97
+ return "ttf";
98
+ }
99
+
100
+ // src/internal/convenience.ts
101
+ function shortcut(convert2, format) {
102
+ return (input, options) => convert2(input, { ...options, format });
103
+ }
104
+ function createFormatShortcuts(convert2) {
105
+ return {
106
+ docxToPdf: shortcut(convert2, "docx"),
107
+ pptxToPdf: shortcut(convert2, "pptx"),
108
+ xlsxToPdf: shortcut(convert2, "xlsx")
109
+ };
110
+ }
111
+
112
+ // src/internal/shared.ts
113
+ var FORMATS = ["docx", "pptx", "xlsx"];
114
+ async function toBytes(input) {
115
+ if (input instanceof Uint8Array) return input;
116
+ if (input instanceof ArrayBuffer) return new Uint8Array(input);
117
+ if (typeof Blob !== "undefined" && input instanceof Blob) {
118
+ return new Uint8Array(await input.arrayBuffer());
119
+ }
120
+ throw new OfficeToPdfError("Input must be a Uint8Array, ArrayBuffer, or Blob.");
121
+ }
122
+ function resolveFormat(input, options) {
123
+ if (options.format) {
124
+ if (!FORMATS.includes(options.format)) {
125
+ throw new OfficeToPdfError(`Unsupported format "${options.format}".`);
126
+ }
127
+ return options.format;
128
+ }
129
+ const name = input.name;
130
+ const extension = typeof name === "string" ? name.split(".").pop()?.toLowerCase() : void 0;
131
+ const inferred = FORMATS.find((format) => format === extension);
132
+ if (inferred) return inferred;
133
+ throw new OfficeToPdfError(
134
+ 'Unable to infer the input format. Pass { format: "docx" | "pptx" | "xlsx" }.'
135
+ );
136
+ }
137
+
138
+ // src/node.ts
139
+ var execFileAsync = util.promisify(child_process.execFile);
140
+ var DEFAULT_TIMEOUT_MS = 12e4;
141
+ function reportWarnings(stderr, onWarning) {
142
+ if (!onWarning) return;
143
+ for (const line of stderr.split("\n")) {
144
+ const message = line.trim();
145
+ if (message) onWarning({ message });
146
+ }
147
+ }
148
+ var NodeConverter = class {
149
+ constructor(options = {}) {
150
+ this.options = options;
151
+ this.binaryPath = resolveBinaryPath(options.binaryPath);
152
+ this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
153
+ }
154
+ options;
155
+ binaryPath;
156
+ timeoutMs;
157
+ fontDir;
158
+ async convert(input, options = {}) {
159
+ const format = resolveFormat(input, options);
160
+ const bytes = await toBytes(input);
161
+ const fontPaths = await this.resolveFontPaths();
162
+ const workDir = await promises.mkdtemp(path.join(os.tmpdir(), "office2pdf-"));
163
+ try {
164
+ const inputPath = path.join(workDir, `input.${format}`);
165
+ const outputPath = path.join(workDir, "output.pdf");
166
+ await promises.writeFile(inputPath, bytes);
167
+ const { stderr } = await execFileAsync(
168
+ this.binaryPath,
169
+ buildArgs(inputPath, outputPath, fontPaths, options),
170
+ { timeout: this.timeoutMs, signal: options.signal, windowsHide: true }
171
+ ).catch((cause) => {
172
+ throw new ConversionFailedError(
173
+ `Converting ${format} to PDF failed`,
174
+ cause.stderr?.trim() || cause.message
175
+ );
176
+ });
177
+ reportWarnings(stderr, options.onWarning);
178
+ return await promises.readFile(outputPath);
179
+ } finally {
180
+ await promises.rm(workDir, { recursive: true, force: true });
181
+ }
182
+ }
183
+ async dispose() {
184
+ const dir = await this.fontDir;
185
+ this.fontDir = void 0;
186
+ if (dir) await promises.rm(dir, { recursive: true, force: true });
187
+ }
188
+ async resolveFontPaths() {
189
+ const configured = this.options.fontPaths ?? [];
190
+ const registered = await this.materializeFonts();
191
+ return registered ? [...configured, registered] : configured;
192
+ }
193
+ materializeFonts() {
194
+ this.fontDir ??= (async () => {
195
+ const fonts = this.options.fonts ?? [];
196
+ if (fonts.length === 0) return void 0;
197
+ const dir = await promises.mkdtemp(path.join(os.tmpdir(), "office2pdf-fonts-"));
198
+ await Promise.all(
199
+ fonts.map(async (font, index) => {
200
+ const bytes = await toBytes(font);
201
+ return promises.writeFile(path.join(dir, `font-${index}.${fontExtension(bytes)}`), bytes);
202
+ })
203
+ );
204
+ return dir;
205
+ })();
206
+ return this.fontDir;
207
+ }
208
+ };
209
+ function createConverter(options) {
210
+ return new NodeConverter(options);
211
+ }
212
+ async function convert(input, options) {
213
+ const converter = new NodeConverter();
214
+ try {
215
+ return await converter.convert(input, options);
216
+ } finally {
217
+ await converter.dispose();
218
+ }
219
+ }
220
+ var { docxToPdf, pptxToPdf, xlsxToPdf } = createFormatShortcuts(convert);
221
+
222
+ exports.ConversionFailedError = ConversionFailedError;
223
+ exports.OfficeToPdfError = OfficeToPdfError;
224
+ exports.UnsupportedPlatformError = UnsupportedPlatformError;
225
+ exports.convert = convert;
226
+ exports.createConverter = createConverter;
227
+ exports.docxToPdf = docxToPdf;
228
+ exports.pptxToPdf = pptxToPdf;
229
+ exports.xlsxToPdf = xlsxToPdf;
@@ -0,0 +1,2 @@
1
+ export * from "./node.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,153 @@
1
+ import { createFormatShortcuts, resolveFormat, toBytes, ConversionFailedError, UnsupportedPlatformError } from './chunk-A2DPXSQU.js';
2
+ export { ConversionFailedError, OfficeToPdfError, UnsupportedPlatformError } from './chunk-A2DPXSQU.js';
3
+ import { execFile } from 'child_process';
4
+ import { mkdtemp, writeFile, readFile, rm } from 'fs/promises';
5
+ import { tmpdir } from 'os';
6
+ import { join, dirname } from 'path';
7
+ import { promisify } from 'util';
8
+ import { createRequire } from 'module';
9
+ import process from 'process';
10
+
11
+ var require2 = createRequire(import.meta.url);
12
+ var PLATFORM_PACKAGES = {
13
+ "darwin-arm64": "officetopdf-darwin-arm64",
14
+ "darwin-x64": "officetopdf-darwin-x64",
15
+ "linux-arm64": "officetopdf-linux-arm64",
16
+ "linux-x64": "officetopdf-linux-x64",
17
+ "linux-x64-musl": "officetopdf-linux-x64-musl",
18
+ "win32-x64": "officetopdf-windows-x64"
19
+ };
20
+ function isMusl() {
21
+ const report = process.report?.getReport();
22
+ if (typeof report === "object" && report !== null && "header" in report) {
23
+ const header = report.header;
24
+ return !header?.glibcVersionRuntime;
25
+ }
26
+ return false;
27
+ }
28
+ function currentTarget() {
29
+ const target = `${process.platform}-${process.arch}`;
30
+ return target === "linux-x64" && isMusl() ? "linux-x64-musl" : target;
31
+ }
32
+ var cached;
33
+ function resolveBinaryPath(override) {
34
+ const explicit = override ?? process.env.OFFICE2PDF_BINARY;
35
+ if (explicit) return explicit;
36
+ if (cached) return cached;
37
+ const target = currentTarget();
38
+ const packageName = PLATFORM_PACKAGES[target];
39
+ if (!packageName) throw new UnsupportedPlatformError(process.platform, process.arch);
40
+ const executable = process.platform === "win32" ? "office2pdf.exe" : "office2pdf";
41
+ try {
42
+ cached = join(dirname(require2.resolve(`${packageName}/package.json`)), executable);
43
+ } catch (cause) {
44
+ throw new UnsupportedPlatformError(process.platform, process.arch, { cause });
45
+ }
46
+ return cached;
47
+ }
48
+
49
+ // src/internal/cli-args.ts
50
+ function buildArgs(inputPath, outputPath, fontPaths, options) {
51
+ const args = [inputPath, "--output", outputPath];
52
+ if (options.paperSize) args.push("--paper", options.paperSize);
53
+ if (options.landscape) args.push("--landscape");
54
+ if (options.pdfA) args.push("--pdf-a");
55
+ if (options.tagged) args.push("--tagged");
56
+ if (options.pdfUa) args.push("--pdf-ua");
57
+ if (options.sheets?.length) args.push("--sheets", options.sheets.join(","));
58
+ if (options.slides) args.push("--slides", options.slides);
59
+ for (const fontPath of fontPaths) args.push("--font-path", fontPath);
60
+ return args;
61
+ }
62
+ function fontExtension(bytes) {
63
+ const magic = String.fromCharCode(...bytes.subarray(0, 4));
64
+ if (magic === "ttcf") return "ttc";
65
+ if (magic === "OTTO") return "otf";
66
+ return "ttf";
67
+ }
68
+
69
+ // src/node.ts
70
+ var execFileAsync = promisify(execFile);
71
+ var DEFAULT_TIMEOUT_MS = 12e4;
72
+ function reportWarnings(stderr, onWarning) {
73
+ if (!onWarning) return;
74
+ for (const line of stderr.split("\n")) {
75
+ const message = line.trim();
76
+ if (message) onWarning({ message });
77
+ }
78
+ }
79
+ var NodeConverter = class {
80
+ constructor(options = {}) {
81
+ this.options = options;
82
+ this.binaryPath = resolveBinaryPath(options.binaryPath);
83
+ this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
84
+ }
85
+ options;
86
+ binaryPath;
87
+ timeoutMs;
88
+ fontDir;
89
+ async convert(input, options = {}) {
90
+ const format = resolveFormat(input, options);
91
+ const bytes = await toBytes(input);
92
+ const fontPaths = await this.resolveFontPaths();
93
+ const workDir = await mkdtemp(join(tmpdir(), "office2pdf-"));
94
+ try {
95
+ const inputPath = join(workDir, `input.${format}`);
96
+ const outputPath = join(workDir, "output.pdf");
97
+ await writeFile(inputPath, bytes);
98
+ const { stderr } = await execFileAsync(
99
+ this.binaryPath,
100
+ buildArgs(inputPath, outputPath, fontPaths, options),
101
+ { timeout: this.timeoutMs, signal: options.signal, windowsHide: true }
102
+ ).catch((cause) => {
103
+ throw new ConversionFailedError(
104
+ `Converting ${format} to PDF failed`,
105
+ cause.stderr?.trim() || cause.message
106
+ );
107
+ });
108
+ reportWarnings(stderr, options.onWarning);
109
+ return await readFile(outputPath);
110
+ } finally {
111
+ await rm(workDir, { recursive: true, force: true });
112
+ }
113
+ }
114
+ async dispose() {
115
+ const dir = await this.fontDir;
116
+ this.fontDir = void 0;
117
+ if (dir) await rm(dir, { recursive: true, force: true });
118
+ }
119
+ async resolveFontPaths() {
120
+ const configured = this.options.fontPaths ?? [];
121
+ const registered = await this.materializeFonts();
122
+ return registered ? [...configured, registered] : configured;
123
+ }
124
+ materializeFonts() {
125
+ this.fontDir ??= (async () => {
126
+ const fonts = this.options.fonts ?? [];
127
+ if (fonts.length === 0) return void 0;
128
+ const dir = await mkdtemp(join(tmpdir(), "office2pdf-fonts-"));
129
+ await Promise.all(
130
+ fonts.map(async (font, index) => {
131
+ const bytes = await toBytes(font);
132
+ return writeFile(join(dir, `font-${index}.${fontExtension(bytes)}`), bytes);
133
+ })
134
+ );
135
+ return dir;
136
+ })();
137
+ return this.fontDir;
138
+ }
139
+ };
140
+ function createConverter(options) {
141
+ return new NodeConverter(options);
142
+ }
143
+ async function convert(input, options) {
144
+ const converter = new NodeConverter();
145
+ try {
146
+ return await converter.convert(input, options);
147
+ } finally {
148
+ await converter.dispose();
149
+ }
150
+ }
151
+ var { docxToPdf, pptxToPdf, xlsxToPdf } = createFormatShortcuts(convert);
152
+
153
+ export { convert, createConverter, docxToPdf, pptxToPdf, xlsxToPdf };
@@ -0,0 +1,2 @@
1
+ export declare function resolveBinaryPath(override?: string): string;
2
+ //# sourceMappingURL=binary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"binary.d.ts","sourceRoot":"","sources":["../../src/internal/binary.ts"],"names":[],"mappings":"AAgCA,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAgB3D"}
@@ -0,0 +1,4 @@
1
+ import type { ConvertOptions } from "../types.js";
2
+ export declare function buildArgs(inputPath: string, outputPath: string, fontPaths: readonly string[], options: ConvertOptions): string[];
3
+ export declare function fontExtension(bytes: Uint8Array): string;
4
+ //# sourceMappingURL=cli-args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-args.d.ts","sourceRoot":"","sources":["../../src/internal/cli-args.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAElD,wBAAgB,SAAS,CACvB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,SAAS,MAAM,EAAE,EAC5B,OAAO,EAAE,cAAc,GACtB,MAAM,EAAE,CAaV;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAKvD"}
@@ -0,0 +1,11 @@
1
+ import type { ConvertInput, ConvertOptions } from "../types.js";
2
+ export type FormatOptions = Omit<ConvertOptions, "format">;
3
+ export type FormatShortcut = (input: ConvertInput, options?: FormatOptions) => Promise<Uint8Array>;
4
+ type Convert = (input: ConvertInput, options?: ConvertOptions) => Promise<Uint8Array>;
5
+ export declare function createFormatShortcuts(convert: Convert): {
6
+ docxToPdf: FormatShortcut;
7
+ pptxToPdf: FormatShortcut;
8
+ xlsxToPdf: FormatShortcut;
9
+ };
10
+ export {};
11
+ //# sourceMappingURL=convenience.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convenience.d.ts","sourceRoot":"","sources":["../../src/internal/convenience.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAgB,MAAM,aAAa,CAAC;AAE9E,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;AAE3D,MAAM,MAAM,cAAc,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AAEnG,KAAK,OAAO,GAAG,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AAMtF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO;IAElD,SAAS;IACT,SAAS;IACT,SAAS;EAEZ"}
@@ -0,0 +1,4 @@
1
+ import type { ConvertInput, ConvertOptions, OfficeFormat } from "../types.js";
2
+ export declare function toBytes(input: ConvertInput): Promise<Uint8Array>;
3
+ export declare function resolveFormat(input: ConvertInput, options: ConvertOptions): OfficeFormat;
4
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/internal/shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI9E,wBAAsB,OAAO,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAOtE;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,GAAG,YAAY,CAgBxF"}
package/dist/node.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { Converter, ConverterOptions, ConvertInput, ConvertOptions } from "./types.js";
2
+ export declare function createConverter(options?: ConverterOptions): Converter;
3
+ export declare function convert(input: ConvertInput, options?: ConvertOptions): Promise<Uint8Array>;
4
+ export declare const docxToPdf: import("./internal/convenience.js").FormatShortcut, pptxToPdf: import("./internal/convenience.js").FormatShortcut, xlsxToPdf: import("./internal/convenience.js").FormatShortcut;
5
+ export { ConversionFailedError, OfficeToPdfError, UnsupportedPlatformError, } from "./errors/OfficeToPdfError.js";
6
+ export type { FormatOptions, FormatShortcut } from "./internal/convenience.js";
7
+ export type { ConversionWarning, Converter, ConverterOptions, ConvertInput, ConvertOptions, OfficeFormat, PaperSize, } from "./types.js";
8
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAoF5F,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAErE;AAED,wBAAsB,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAOhG;AAED,eAAO,MAAQ,SAAS,sDAAE,SAAS,sDAAE,SAAS,oDAAmC,CAAC;AAElF,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC/E,YAAY,EACV,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,SAAS,GACV,MAAM,YAAY,CAAC"}
@@ -0,0 +1,37 @@
1
+ export type OfficeFormat = "docx" | "pptx" | "xlsx";
2
+ export type PaperSize = "a4" | "letter" | "legal";
3
+ export type ConvertInput = Uint8Array | ArrayBuffer | Blob;
4
+ export interface ConversionWarning {
5
+ message: string;
6
+ kind?: string;
7
+ format?: string;
8
+ from?: string;
9
+ to?: string;
10
+ element?: string;
11
+ detail?: string;
12
+ reason?: string;
13
+ }
14
+ export interface ConvertOptions {
15
+ format?: OfficeFormat;
16
+ paperSize?: PaperSize;
17
+ landscape?: boolean;
18
+ pdfA?: boolean;
19
+ tagged?: boolean;
20
+ pdfUa?: boolean;
21
+ sheets?: string[];
22
+ slides?: string;
23
+ signal?: AbortSignal;
24
+ onWarning?: (warning: ConversionWarning) => void;
25
+ }
26
+ export interface ConverterOptions {
27
+ fonts?: ConvertInput[];
28
+ fontPaths?: string[];
29
+ lastResortFontFamily?: string;
30
+ binaryPath?: string;
31
+ timeoutMs?: number;
32
+ }
33
+ export interface Converter {
34
+ convert(input: ConvertInput, options?: ConvertOptions): Promise<Uint8Array>;
35
+ dispose(): Promise<void>;
36
+ }
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,QAAQ,GAAG,OAAO,CAAC;AAElD,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,IAAI,CAAC;AAE3D,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAClD;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC5E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
package/package.json ADDED
@@ -0,0 +1,92 @@
1
+ {
2
+ "name": "officetopdf-js",
3
+ "version": "0.0.1",
4
+ "description": "Convert DOCX, PPTX and XLSX to PDF in Node.js, Bun and the browser. No LibreOffice, no Chromium.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Nilesh9106/officetopdf.git"
12
+ },
13
+ "devDependencies": {
14
+ "@biomejs/biome": "^2.4.14",
15
+ "@types/bun": "latest",
16
+ "tsup": "^8.5.0",
17
+ "typescript": "^7.0.2"
18
+ },
19
+ "exports": {
20
+ ".": {
21
+ "browser": {
22
+ "types": "./dist/browser.d.ts",
23
+ "import": "./dist/browser.js",
24
+ "require": "./dist/browser.cjs"
25
+ },
26
+ "types": "./dist/index.d.ts",
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs",
29
+ "default": "./dist/index.js"
30
+ },
31
+ "./browser": {
32
+ "types": "./dist/browser.d.ts",
33
+ "import": "./dist/browser.js",
34
+ "require": "./dist/browser.cjs"
35
+ },
36
+ "./node": {
37
+ "types": "./dist/index.d.ts",
38
+ "import": "./dist/index.js",
39
+ "require": "./dist/index.cjs"
40
+ },
41
+ "./package.json": "./package.json"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/Nilesh9106/officetopdf/issues"
45
+ },
46
+ "engines": {
47
+ "node": ">=18",
48
+ "bun": ">=1.1.0"
49
+ },
50
+ "files": [
51
+ "dist",
52
+ "src",
53
+ "LICENSE"
54
+ ],
55
+ "homepage": "https://github.com/Nilesh9106/officetopdf#readme",
56
+ "keywords": [
57
+ "docx",
58
+ "pptx",
59
+ "xlsx",
60
+ "pdf",
61
+ "office",
62
+ "convert",
63
+ "wasm",
64
+ "typst"
65
+ ],
66
+ "license": "Apache-2.0",
67
+ "scripts": {
68
+ "build": "bunx --bun tsup && bunx --bun tsc --emitDeclarationOnly --noEmit false --outDir dist",
69
+ "test": "bun test",
70
+ "typecheck": "bunx --bun tsc --noEmit",
71
+ "lint": "bunx --bun @biomejs/biome check .",
72
+ "lint:fix": "bunx --bun @biomejs/biome check --write .",
73
+ "format": "bunx --bun @biomejs/biome format --write .",
74
+ "clean": "rm -rf dist",
75
+ "ci:check": "bun run lint && bun run typecheck && bun run test && bun run build",
76
+ "prepublishOnly": "bun run ci:check",
77
+ "publish:npm": "npm publish --access public",
78
+ "binaries:fetch": "bun run scripts/fetch-binaries.ts",
79
+ "wasm:build": "bash scripts/build-wasm.sh"
80
+ },
81
+ "sideEffects": false,
82
+ "browser": "./dist/browser.js",
83
+ "optionalDependencies": {
84
+ "officetopdf-darwin-arm64": "0.0.1",
85
+ "officetopdf-darwin-x64": "0.0.1",
86
+ "officetopdf-linux-arm64": "0.0.1",
87
+ "officetopdf-linux-x64": "0.0.1",
88
+ "officetopdf-linux-x64-musl": "0.0.1",
89
+ "officetopdf-wasm": "0.0.1",
90
+ "officetopdf-windows-x64": "0.0.1"
91
+ }
92
+ }