Merge pull request #1271 from dolanmiu/feature/page-border-demos

#1256 Add page border demos
This commit is contained in:
Dolan
2021-10-31 21:47:21 +00:00
committed by GitHub
2 changed files with 72 additions and 0 deletions

View File

@ -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-page-borders-2.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

63
demo/71-page-borders-2.ts Normal file
View File

@ -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);
});