@hilvana/office 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +9 -2
- package/dist/convert.d.ts +13 -0
- package/dist/convert.js +35 -0
- package/dist/fonts.d.ts +45 -0
- package/dist/fonts.js +146 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +6 -0
- package/dist/layout.d.ts +43 -0
- package/dist/layout.js +525 -0
- package/dist/libreoffice.d.ts +11 -0
- package/dist/libreoffice.js +63 -0
- package/dist/model.d.ts +129 -0
- package/dist/model.js +3 -0
- package/dist/parse.d.ts +21 -0
- package/dist/parse.js +929 -0
- package/dist/word.d.ts +20 -0
- package/dist/word.js +22 -0
- package/package.json +56 -4
package/dist/word.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type FontLoader } from './fonts.js';
|
|
2
|
+
export type WordWarning = 'TEXTBOX_SKIPPED' | 'FLOATING_IMAGE_INLINED' | 'UNSUPPORTED_IMAGE_FORMAT' | 'LEGACY_SHAPE_SKIPPED' | 'NOTES_SKIPPED' | 'FIRST_PAGE_HEADER_IGNORED' | 'PAGE_FIELD_IN_BODY' | 'CONTENT_TALLER_THAN_PAGE' | 'MISSING_GLYPHS' | 'COLUMNS_IGNORED';
|
|
3
|
+
export interface WordToPdfResult {
|
|
4
|
+
pdf: Uint8Array;
|
|
5
|
+
pageCount: number;
|
|
6
|
+
/** Things the native engine simplified or skipped, as stable codes. */
|
|
7
|
+
warnings: WordWarning[];
|
|
8
|
+
engine: 'native' | 'libreoffice';
|
|
9
|
+
}
|
|
10
|
+
export interface WordToPdfOptions {
|
|
11
|
+
/** Where to load fonts from. Defaults to the installed @fontsource packages (Node). Browsers pass a fetch-based loader. */
|
|
12
|
+
fonts?: FontLoader;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Converts a .docx to PDF entirely in-process (no network, no external programs).
|
|
16
|
+
* Text is real and selectable; fonts are embedded and subset.
|
|
17
|
+
* Covers paragraphs, styles, lists, tables, inline images, page/section breaks, headers and footers with page numbers.
|
|
18
|
+
*/
|
|
19
|
+
export declare function wordToPdf(docx: Uint8Array, opts?: WordToPdfOptions): Promise<WordToPdfResult>;
|
|
20
|
+
//# sourceMappingURL=word.d.ts.map
|
package/dist/word.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { PDFDocument } from 'pdf-lib';
|
|
2
|
+
import { FontManager, nodeFontLoader } from './fonts.js';
|
|
3
|
+
import { LayoutEngine } from './layout.js';
|
|
4
|
+
import { parseDocx } from './parse.js';
|
|
5
|
+
/**
|
|
6
|
+
* Converts a .docx to PDF entirely in-process (no network, no external programs).
|
|
7
|
+
* Text is real and selectable; fonts are embedded and subset.
|
|
8
|
+
* Covers paragraphs, styles, lists, tables, inline images, page/section breaks, headers and footers with page numbers.
|
|
9
|
+
*/
|
|
10
|
+
export async function wordToPdf(docx, opts = {}) {
|
|
11
|
+
const model = parseDocx(docx);
|
|
12
|
+
const doc = await PDFDocument.create({ updateMetadata: false });
|
|
13
|
+
const fonts = new FontManager(doc, opts.fonts ?? nodeFontLoader);
|
|
14
|
+
const engine = new LayoutEngine(doc, fonts, model);
|
|
15
|
+
await engine.prepare();
|
|
16
|
+
const pageCount = engine.render();
|
|
17
|
+
const warnings = new Set([...model.warnings, ...engine.warnings]);
|
|
18
|
+
if (fonts.missingGlyphs)
|
|
19
|
+
warnings.add('MISSING_GLYPHS');
|
|
20
|
+
return { pdf: await doc.save({ useObjectStreams: true }), pageCount, warnings: [...warnings], engine: 'native' };
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=word.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,58 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hilvana/office",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Hilvana office conversions that run locally: Word (.docx) to PDF with real, selectable text.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"docx",
|
|
7
|
+
"word",
|
|
8
|
+
"pdf",
|
|
9
|
+
"convert",
|
|
10
|
+
"word-to-pdf",
|
|
11
|
+
"local"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "Jorge Grajales (https://jorgegrajales.dev)",
|
|
15
|
+
"homepage": "https://github.com/gethilvana/hilvana#readme",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/gethilvana/hilvana/issues"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/gethilvana/hilvana.git",
|
|
22
|
+
"directory": "packages/office"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js"
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"!dist/**/*.map",
|
|
36
|
+
"README.md",
|
|
37
|
+
"LICENSE"
|
|
38
|
+
],
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"provenance": true
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@fontsource/arimo": "^5.3.0",
|
|
48
|
+
"@fontsource/caladea": "^5.3.0",
|
|
49
|
+
"@fontsource/carlito": "^5.3.0",
|
|
50
|
+
"@fontsource/cousine": "^5.3.0",
|
|
51
|
+
"@fontsource/noto-sans-symbols-2": "^5.3.0",
|
|
52
|
+
"@fontsource/tinos": "^5.3.0",
|
|
53
|
+
"@pdf-lib/fontkit": "^1.1.1",
|
|
54
|
+
"@xmldom/xmldom": "^0.9.12",
|
|
55
|
+
"fflate": "^0.8.3",
|
|
56
|
+
"pdf-lib": "^1.17.1"
|
|
57
|
+
}
|
|
58
|
+
}
|