diff --git a/demo/53-chinese.ts b/demo/53-chinese.ts new file mode 100644 index 0000000000..eb9afb39a2 --- /dev/null +++ b/demo/53-chinese.ts @@ -0,0 +1,46 @@ +// Chinese text - Chinese need to use a Chinese font. And ascii Text Need to use a ascii font. +// Different from the `52-japanese.ts`. +// `52-japanese.ts` will set all characters to use Japanese font. +// `53-chinese.ts` will set Chinese characters to use Chinese font, and set ascii characters to use ascii font. + +// Note that if the compute have not install `KaiTi` font, this demo doesn't work. + +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { Document, HeadingLevel, Packer, Paragraph } from "../build"; + +const doc = new Document({ + styles: { + paragraphStyles: [ + { + id: "Normal", + name: "Normal", + basedOn: "Normal", + next: "Normal", + quickFormat: true, + run: { + font: { + ascii: "Times", + eastAsia: "KaiTi", + }, + }, + }, + ], + }, +}); + +doc.addSection({ + children: [ + new Paragraph({ + text: "中文和英文 Chinese and English", + heading: HeadingLevel.HEADING_1, + }), + new Paragraph({ + text: "中文和英文 Chinese and English", + }), + ], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/docs/usage/styling-with-js.md b/docs/usage/styling-with-js.md index c8bbb5c8db..0dafac2904 100644 --- a/docs/usage/styling-with-js.md +++ b/docs/usage/styling-with-js.md @@ -26,7 +26,7 @@ const name = new TextRun({ - `emphasisMark({type="dot"})`: Set the emphasis mark style - `color(color)`: Set the text color, using 6 hex characters for RRGGBB (no leading `#`) - `size(halfPts)`: Set the font size, measured in half-points -- `font(name)`: Set the run's font +- `font(name)` or `font({ascii, cs, eastAsia, hAnsi, hint})`: Set the run's font - `style(name)`: Apply a named run style - `characterSpacing(value)`: Set the character spacing adjustment (in TWIPs)