@docx-editor.dev/docx-to-pdf 2.22.0 → 2.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/fonts.md CHANGED
@@ -18,7 +18,7 @@ Sources resolve in this order:
18
18
  2. Installed fonts, unless `useSystemFonts` is `false`.
19
19
  3. Packaged substitutes.
20
20
  4. Your `fallbackFonts` sources.
21
- 5. Supplemental packaged faces.
21
+ 5. Supplemental packaged faces, including `@docx-editor.dev/fonts-cjk` when it is installed.
22
22
  6. Document-embedded fonts.
23
23
  7. Your `lastResortFonts` sources.
24
24
  8. Generic substitutes for unresolved families.
@@ -27,6 +27,64 @@ Earlier sources take priority. Each option accepts one source or an ordered arra
27
27
 
28
28
  The default sources need no network access. A resolver that you supply can make network requests.
29
29
 
30
+ ## Add Chinese, Japanese, and Korean text
31
+
32
+ The converter package does not include a Chinese, Japanese, or Korean (CJK) font. If your server has no suitable font, install the optional package:
33
+
34
+ ```sh
35
+ npm install @docx-editor.dev/fonts-cjk
36
+ ```
37
+
38
+ The converter declares this package as an optional peer dependency. Install a version that satisfies its peer dependency range. The converter finds the package at runtime and needs no configuration. Its Noto Sans CJK JP font supplies CJK characters that earlier sources do not cover. It also substitutes for unavailable families such as SimSun, MS Mincho, and Malgun Gothic.
39
+
40
+ If you previously relied on bundled CJK coverage, add this package to your production dependencies. Keep the package external to your server bundle. Retain its `dist/` and `assets/` directories in their package locations. Include its license files when distributing the package.
41
+
42
+ You can omit the package when installed fonts or your supplied fonts cover every required character. An installed package with missing or unreadable assets reports `font-origin-failed`. Inspect `result.fontResolution.originFailures` for the cause.
43
+
44
+ When `useSystemFonts` is `true`, suitable installed fonts take priority. Setting `useSystemFonts: false` still permits the optional package and fonts that you supply.
45
+
46
+ If no source covers a CJK character, export reports `missing-glyph`, and strict export fails. When the optional package is absent, the diagnostic names it. An unavailable CJK family uses a generic substitute and reports `font-substitution`.
47
+
48
+ ### CJK package API
49
+
50
+ `@docx-editor.dev/fonts-cjk` runs on Node.js `^20.16.0 || >=22.3.0`. It exports the font family and its local file URL:
51
+
52
+ | Export | Type | Value |
53
+ | --- | --- | --- |
54
+ | `NOTO_SANS_CJK_JP_FAMILY` | String literal | `'Noto Sans CJK JP'` |
55
+ | `NOTO_SANS_CJK_JP_URL` | `URL` | A `file:` URL for `assets/NotoSansCJKjp-Regular.otf`. |
56
+
57
+ Use the URL to read the font directly:
58
+
59
+ ```ts
60
+ import { readFile } from 'node:fs/promises';
61
+ import {
62
+ NOTO_SANS_CJK_JP_FAMILY,
63
+ NOTO_SANS_CJK_JP_URL,
64
+ } from '@docx-editor.dev/fonts-cjk';
65
+
66
+ const fontBytes = new Uint8Array(await readFile(NOTO_SANS_CJK_JP_URL));
67
+ console.log(NOTO_SANS_CJK_JP_FAMILY, fontBytes.byteLength);
68
+ ```
69
+
70
+ Automatic PDF fallback needs no direct import. If you supply `glyphFallbacks`, your list replaces the defaults. For this fallback, add an entry with `family: NOTO_SANS_CJK_JP_FAMILY`, `weight: 400`, and `style: 'normal'`.
71
+
72
+ ### CJK font coverage and licensing
73
+
74
+ The package supplies Noto Sans CJK JP Regular as an OpenType font with CFF outlines. It contains one weight (`400`) and one style (`'normal'`). PDF export can synthesize bold and italic from the regular face.
75
+
76
+ The package contains the Japanese regional face, without separate Chinese or Korean regional faces. Substitution can change glyph forms, line breaks, and page counts. Supply your own font through `fonts` when you need a specific regional face or designed style.
77
+
78
+ The package reads its font from disk without network access. It does not bundle the font into JavaScript or install a browser font.
79
+
80
+ The package code uses the Apache License 2.0. The font uses the SIL Open Font License, Version 1.1. The PDF converter uses the separate EigenPal Pro License.
81
+
82
+ ## Export Arabic and Hebrew text
83
+
84
+ Default fallback fonts cover Arabic and Hebrew. Arabic fallback selection requires a font with Arabic shaping support. Arabic joining continues across formatting runs, including changes in text color. The PDF text layer preserves logical word order for Arabic, Persian, and Hebrew text extraction.
85
+
86
+ When a selected face lacks bold or italic variants, the writer can draw synthetic styles. It preserves text extraction and glyph positions. To use your own designed variants, supply separate regular, bold, italic, and bold-italic font files.
87
+
30
88
  ## Supply a font file
31
89
 
32
90
  Use `createFontSource` from the converter package to validate your font bytes. This example expects your licensed regular font file and a document that requests `Application Sans`:
@@ -88,6 +146,6 @@ Each `font-origin-failed` diagnostic provides the source index, optional source
88
146
  | `font-substitution` diagnostic | Supply the requested family through `fonts` or review best-effort output. |
89
147
  | Strict font policy rejects conversion | Inspect the callback report for failed sources and missing face variants. |
90
148
  | Missing font assets after bundling | Keep converter packages external and copy their assets with deployment output. |
91
- | Missing glyphs | Supply a face that contains the requested characters. |
149
+ | Missing glyphs | Supply a face that contains the requested characters. For CJK text, install `@docx-editor.dev/fonts-cjk`. |
92
150
 
93
151
  For server setup, see [Integrate PDF conversion](integrations.md).
@@ -70,11 +70,12 @@ export default {
70
70
  '@docx-editor.dev/docx-to-pdf',
71
71
  '@docx-editor.dev/core',
72
72
  '@docx-editor.dev/fonts',
73
+ '@docx-editor.dev/fonts-cjk',
73
74
  ],
74
75
  };
75
76
  ```
76
77
 
77
- If you deploy a standalone bundle, include the converter's `assets/` directory and the fonts package's assets. Keep the package directory structure intact. Test the deployment artifact with a real conversion before release.
78
+ For a standalone deployment, include the `assets/` directories from the converter and `@docx-editor.dev/fonts`. If you install `@docx-editor.dev/fonts-cjk`, include its `assets/` directory too. Keep the package directory structure intact. Test the deployment artifact with a real conversion before release.
78
79
 
79
80
  ## Convert a batch
80
81
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docx-editor.dev/docx-to-pdf",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "private": false,
5
5
  "description": "Convert DOCX to PDF on Node.js with searchable text, embedded fonts, and comments.",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "licenses"
30
30
  ],
31
31
  "scripts": {
32
- "build": "tsup",
32
+ "build": "node ../../scripts/check-built-siblings.mjs && tsup",
33
33
  "typecheck": "tsc --noEmit",
34
34
  "check:consumer": "node scripts/check-consumer.mjs",
35
35
  "license:check": "license-check-and-add check -f license-check.json",
@@ -42,15 +42,22 @@
42
42
  "validation": "bun scripts/validator/launch.mjs"
43
43
  },
44
44
  "peerDependencies": {
45
- "@docx-editor.dev/core": "~2.22.0"
45
+ "@docx-editor.dev/core": "~2.23.0",
46
+ "@docx-editor.dev/fonts-cjk": "~2.23.0"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "@docx-editor.dev/fonts-cjk": {
50
+ "optional": true
51
+ }
46
52
  },
47
53
  "dependencies": {
48
- "@docx-editor.dev/fonts": "~2.22.0",
54
+ "@docx-editor.dev/fonts": "~2.23.0",
49
55
  "fontkit": "2.0.4",
50
56
  "pdf-lib": "1.17.1"
51
57
  },
52
58
  "devDependencies": {
53
59
  "@docx-editor.dev/core": "workspace:*",
60
+ "@docx-editor.dev/fonts-cjk": "workspace:*",
54
61
  "dejavu-fonts-ttf": "^2.37.3",
55
62
  "license-check-and-add": "^4.0.5",
56
63
  "pdfjs-dist": "5.4.624",
Binary file
@@ -1,92 +0,0 @@
1
- This Font Software is licensed under the SIL Open Font License,
2
- Version 1.1.
3
-
4
- This license is copied below, and is also available with a FAQ at:
5
- http://scripts.sil.org/OFL
6
-
7
- -----------------------------------------------------------
8
- SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
9
- -----------------------------------------------------------
10
-
11
- PREAMBLE
12
- The goals of the Open Font License (OFL) are to stimulate worldwide
13
- development of collaborative font projects, to support the font
14
- creation efforts of academic and linguistic communities, and to
15
- provide a free and open framework in which fonts may be shared and
16
- improved in partnership with others.
17
-
18
- The OFL allows the licensed fonts to be used, studied, modified and
19
- redistributed freely as long as they are not sold by themselves. The
20
- fonts, including any derivative works, can be bundled, embedded,
21
- redistributed and/or sold with any software provided that any reserved
22
- names are not used by derivative works. The fonts and derivatives,
23
- however, cannot be released under any other type of license. The
24
- requirement for fonts to remain under this license does not apply to
25
- any document created using the fonts or their derivatives.
26
-
27
- DEFINITIONS
28
- "Font Software" refers to the set of files released by the Copyright
29
- Holder(s) under this license and clearly marked as such. This may
30
- include source files, build scripts and documentation.
31
-
32
- "Reserved Font Name" refers to any names specified as such after the
33
- copyright statement(s).
34
-
35
- "Original Version" refers to the collection of Font Software
36
- components as distributed by the Copyright Holder(s).
37
-
38
- "Modified Version" refers to any derivative made by adding to,
39
- deleting, or substituting -- in part or in whole -- any of the
40
- components of the Original Version, by changing formats or by porting
41
- the Font Software to a new environment.
42
-
43
- "Author" refers to any designer, engineer, programmer, technical
44
- writer or other person who contributed to the Font Software.
45
-
46
- PERMISSION & CONDITIONS
47
- Permission is hereby granted, free of charge, to any person obtaining
48
- a copy of the Font Software, to use, study, copy, merge, embed,
49
- modify, redistribute, and sell modified and unmodified copies of the
50
- Font Software, subject to the following conditions:
51
-
52
- 1) Neither the Font Software nor any of its individual components, in
53
- Original or Modified Versions, may be sold by itself.
54
-
55
- 2) Original or Modified Versions of the Font Software may be bundled,
56
- redistributed and/or sold with any software, provided that each copy
57
- contains the above copyright notice and this license. These can be
58
- included either as stand-alone text files, human-readable headers or
59
- in the appropriate machine-readable metadata fields within text or
60
- binary files as long as those fields can be easily viewed by the user.
61
-
62
- 3) No Modified Version of the Font Software may use the Reserved Font
63
- Name(s) unless explicit written permission is granted by the
64
- corresponding Copyright Holder. This restriction only applies to the
65
- primary font name as presented to the users.
66
-
67
- 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
68
- Software shall not be used to promote, endorse or advertise any
69
- Modified Version, except to acknowledge the contribution(s) of the
70
- Copyright Holder(s) and the Author(s) or with their explicit written
71
- permission.
72
-
73
- 5) The Font Software, modified or unmodified, in part or in whole,
74
- must be distributed entirely under this license, and must not be
75
- distributed under any other license. The requirement for fonts to
76
- remain under this license does not apply to any document created using
77
- the Font Software.
78
-
79
- TERMINATION
80
- This license becomes null and void if any of the above conditions are
81
- not met.
82
-
83
- DISCLAIMER
84
- THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
85
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
86
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
87
- OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
88
- COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
89
- INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
90
- DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
91
- FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
92
- OTHER DEALINGS IN THE FONT SOFTWARE.