Skip to content

Commit fe21bb1

Browse files
committed
dolanmiu#1256 Add page border demos
1 parent a01d352 commit fe21bb1

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

.github/workflows/demos.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,12 @@ jobs:
679679
with:
680680
xml-file: build/extracted-doc/word/document.xml
681681
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
682+
- name: Run Demo
683+
run: npm run ts-node -- ./demo/71-line-numbers-suppression.ts
684+
- name: Extract Word Document
685+
run: npm run extract
686+
- name: Validate XML
687+
uses: ChristophWurst/xmllint-action@v1
688+
with:
689+
xml-file: build/extracted-doc/word/document.xml
690+
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd

demo/71-page-borders-2.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Example demonstrating page borders with style, colors and size
2+
// Import from 'docx' rather than '../build' if you install from npm
3+
import * as fs from "fs";
4+
import { Document, Packer, TextRun, Paragraph, BorderStyle, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder } from "../build";
5+
6+
const doc = new Document({
7+
sections: [
8+
{
9+
properties: {
10+
page: {
11+
borders: {
12+
pageBorderBottom: {
13+
style: BorderStyle.SINGLE,
14+
size: 2 * 8, //2pt;
15+
color: "000000",
16+
},
17+
pageBorderLeft: {
18+
style: BorderStyle.SINGLE,
19+
size: 1 * 8, //1pt;
20+
color: "000000",
21+
},
22+
pageBorderRight: {
23+
style: BorderStyle.SINGLE,
24+
size: 1 * 8, //1pt;
25+
color: "FF00AA",
26+
},
27+
pageBorderTop: {
28+
style: BorderStyle.SINGLE,
29+
size: 1 * 8, //1pt;
30+
color: "000000",
31+
},
32+
pageBorders: {
33+
display: PageBorderDisplay.ALL_PAGES,
34+
offsetFrom: PageBorderOffsetFrom.TEXT,
35+
zOrder: PageBorderZOrder.FRONT,
36+
},
37+
},
38+
},
39+
},
40+
children: [
41+
new Paragraph({
42+
children: [
43+
new TextRun({
44+
text: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`,
45+
}),
46+
],
47+
}),
48+
new Paragraph({
49+
children: [
50+
new TextRun({
51+
text: `Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.`,
52+
}),
53+
],
54+
}),
55+
],
56+
},
57+
],
58+
});
59+
60+
// Used to export the file into a .docx file
61+
Packer.toBuffer(doc).then((buffer) => {
62+
fs.writeFileSync("My Document.docx", buffer);
63+
});

0 commit comments

Comments
 (0)