Skip to content

Commit

Permalink
Merge pull request #1271 from dolanmiu/feature/page-border-demos
Browse files Browse the repository at this point in the history
#1256 Add page border demos
  • Loading branch information
dolanmiu authored Oct 31, 2021
2 parents a01d352 + dd657a9 commit 89040e0
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/demos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 63 additions & 0 deletions demo/71-page-borders-2.ts
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 89040e0

Please sign in to comment.