@docx-editor.dev/fonts-cjk
This package supplies Noto Sans CJK JP for Chinese, Japanese, and Korean text. The @docx-editor.dev/docx-to-pdf package uses it as an optional fallback, and the editor uses it through the cjkFonts() resolver. The font file is about 16 MB, so it ships separately.
Install
Use Node.js ^20.16.0 || >=22.3.0. Install the package with the PDF converter and its required engine peer:
npm install @docx-editor.dev/docx-to-pdf @docx-editor.dev/core @docx-editor.dev/fonts-cjk
The converter declares @docx-editor.dev/fonts-cjk as an optional peer dependency. Use versions that satisfy the converter's peer dependency ranges. PDF export finds the package without configuration and reads its font from disk. It makes no network request for the font.
Font selection
PDF export uses this font when earlier sources lack the requested CJK family or characters. Your fonts, enabled system fonts, packaged substitutes, and fallbackFonts sources take priority. This font resolves before document-embedded fonts and lastResortFonts. For the complete order, see Configure PDF fonts.
The default glyph fallback list includes this font. 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'.
You can omit this package when installed or supplied fonts cover your CJK text. Installed fonts such as SimSun, Batang, and MS Gothic take priority when useSystemFonts is true. If no font covers a CJK character, export reports a missing-glyph diagnostic. When this package is absent, the diagnostic names it. Strict export fails for missing glyphs.
Deploy the package
Add the package to your production dependencies. Keep it external to your server bundle so Node.js can resolve it at runtime. Retain its dist/ and assets/ directories in their package locations. Include its license files when distributing the package.
An installed package with missing or unreadable font assets reports font-origin-failed. Inspect result.fontResolution.originFailures to find the cause. Setting fontPolicy: 'strict' rejects these source failures.
For deployment examples, see Integrate PDF conversion.
Use the font in the editor
For a browser editor, install this package alongside your existing editor dependencies:
npm install @docx-editor.dev/fonts-cjk
The @docx-editor.dev/fonts-cjk/browser entry exports cjkFonts(), a font resolver with the same shape as packagedFonts() and googleFonts() from @docx-editor.dev/fonts. Put it after the origins whose fonts you prefer:
import { packagedFonts } from '@docx-editor.dev/fonts';
import { googleFonts } from '@docx-editor.dev/fonts/google';
import { cjkFonts } from '@docx-editor.dev/fonts-cjk/browser';
const fonts = [packagedFonts(), googleFonts(), cjkFonts()];
The first paint does not wait for this download. The editor paints the document with its other fonts, then lays it out again when this font arrives. To install it with the other fonts instead, pass cjkFonts({ loading: 'wait' }). A document export that receives this resolver always waits for the font.
If you can load fonts from a third party, googleFonts({ cjk: true }) from @docx-editor.dev/fonts/google is an alternative. It loads a smaller regional face for each language a document uses. Do not combine cjk: true with cjkFonts(): both fonts would download, and the origin listed first would paint.
The resolver downloads the font only when a document names one of the CJK_SUBSTITUTED_FAMILIES, or one of their localized names in LOCALIZED_CJK_FAMILIES. Your bundler emits the font file as an asset, and the resolver fetches it from there. No request goes to a third party. The browser entry is ECMAScript modules only, because it finds the file through import.meta.url.
A failed download calls the onFailure option, or writes a console warning. The document then keeps its other fonts.
Use the font directly
The Node.js entry has these public exports:
| Export | Type | Value |
|---|---|---|
NOTO_SANS_CJK_JP_FAMILY | String literal | 'Noto Sans CJK JP' |
NOTO_SANS_CJK_JP_URL | URL | A file: URL for assets/NotoSansCJKjp-Regular.otf. |
CJK_SUBSTITUTED_FAMILIES | readonly string[] | The East Asian families the font stands in for. |
LOCALIZED_CJK_FAMILIES | ReadonlyMap<string, string> | Localized family names, mapped to their English names. |
Use the exported URL to read the font without constructing a package path:
import { readFile } from 'node:fs/promises';
import { NOTO_SANS_CJK_JP_FAMILY, NOTO_SANS_CJK_JP_URL } from '@docx-editor.dev/fonts-cjk';
const bytes = await readFile(NOTO_SANS_CJK_JP_URL);
console.log(NOTO_SANS_CJK_JP_FAMILY, bytes.byteLength);
The Node.js entry does not bundle the font into JavaScript or install a browser font.
Coverage and limits
- The package includes one OpenType font with CFF outlines: Noto Sans CJK JP Regular.
- Its weight is
400, and its style is'normal'. - It supplies the Japanese regional face, without separate Chinese or Korean regional faces.
- PDF export can synthesize bold and italic from this regular face.
- Substituting this font can change glyph forms, line breaks, and page counts.
- Characters outside the font's coverage still require another font.
Supply your own font through the converter's fonts option when you need a specific regional face or designed style.
Licenses
The package code uses the Apache License 2.0. For more information, see LICENSE. The PDF converter uses the separate EigenPal Pro License.
The font uses the SIL Open Font License, Version 1.1. The license text is in licenses/NotoSansCJK-OFL.txt.
- Font: Noto Sans CJK JP Regular, version 2.004.
- Copyright: © 2014-2021 Adobe (http://www.adobe.com/).
- Trademark: Noto is a trademark of Google Inc.
- Source:
notofonts/noto-cjk.
The font file is the unmodified upstream binary. assets/sources.json records its source URL and SHA-256 hash. PDF export embeds only the glyphs that the document uses.