From fe21bb1702c7df73c268fdd740848384d3d8a008 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Sat, 30 Oct 2021 19:34:16 +0100 Subject: [PATCH 1/2] #1256 Add page border demos --- .github/workflows/demos.yml | 9 ++++++ demo/71-page-borders-2.ts | 63 +++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 demo/71-page-borders-2.ts diff --git a/.github/workflows/demos.yml b/.github/workflows/demos.yml index 176049294c..7a8a01bec4 100644 --- a/.github/workflows/demos.yml +++ b/.github/workflows/demos.yml @@ -679,3 +679,12 @@ jobs: with: xml-file: build/extracted-doc/word/document.xml xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd + - name: Run Demo + run: npm run ts-node -- ./demo/71-line-numbers-suppression.ts + - name: Extract Word Document + run: npm run extract + - name: Validate XML + uses: ChristophWurst/xmllint-action@v1 + with: + xml-file: build/extracted-doc/word/document.xml + xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd \ No newline at end of file diff --git a/demo/71-page-borders-2.ts b/demo/71-page-borders-2.ts new file mode 100644 index 0000000000..f156e25b3a --- /dev/null +++ b/demo/71-page-borders-2.ts @@ -0,0 +1,63 @@ +// Example demonstrating page borders with style, colors and size +// Import from 'docx' rather than '../build' if you install from npm +import * as fs from "fs"; +import { Document, Packer, TextRun, Paragraph, BorderStyle, PageBorderDisplay, PageBorderOffsetFrom, PageBorderZOrder } from "../build"; + +const doc = new Document({ + sections: [ + { + properties: { + page: { + borders: { + pageBorderBottom: { + style: BorderStyle.SINGLE, + size: 2 * 8, //2pt; + color: "000000", + }, + pageBorderLeft: { + style: BorderStyle.SINGLE, + size: 1 * 8, //1pt; + color: "000000", + }, + pageBorderRight: { + style: BorderStyle.SINGLE, + size: 1 * 8, //1pt; + color: "FF00AA", + }, + pageBorderTop: { + style: BorderStyle.SINGLE, + size: 1 * 8, //1pt; + color: "000000", + }, + pageBorders: { + display: PageBorderDisplay.ALL_PAGES, + offsetFrom: PageBorderOffsetFrom.TEXT, + zOrder: PageBorderZOrder.FRONT, + }, + }, + }, + }, + children: [ + new Paragraph({ + children: [ + new TextRun({ + 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.`, + }), + ], + }), + new Paragraph({ + children: [ + new TextRun({ + 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.`, + }), + ], + }), + ], + }, + ], +}); + +// Used to export the file into a .docx file +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); From dd657a9e8888a54a739df7445cb6d23f2b4fff6a Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Sun, 31 Oct 2021 20:25:52 +0000 Subject: [PATCH 2/2] Fix typo --- .github/workflows/demos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/demos.yml b/.github/workflows/demos.yml index 7a8a01bec4..c0f0330b04 100644 --- a/.github/workflows/demos.yml +++ b/.github/workflows/demos.yml @@ -680,7 +680,7 @@ jobs: xml-file: build/extracted-doc/word/document.xml xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd - name: Run Demo - run: npm run ts-node -- ./demo/71-line-numbers-suppression.ts + run: npm run ts-node -- ./demo/71-page-borders-2.ts - name: Extract Word Document run: npm run extract - name: Validate XML