Deprecate createParagraph in all demos

This commit is contained in:
Dolan
2019-06-13 01:07:00 +01:00
parent cb42c74a8d
commit 5497dabaf9
17 changed files with 284 additions and 125 deletions

View File

@ -1,32 +1,44 @@
// Custom styles using JavaScript configuration
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer } from "../build";
import { Document, HeadingLevel, Packer, Paragraph } from "../build";
const doc = new Document();
const myStyles = doc.Styles;
// The first argument is an ID you use to apply the style to paragraphs
// The second argument is a human-friendly name to show in the UI
myStyles.createParagraphStyle("myWonkyStyle", "My Wonky Style")
myStyles
.createParagraphStyle("myWonkyStyle", "My Wonky Style")
.basedOn("Normal")
.next("Normal")
.color("990000")
.italics()
.indent({left: 720}) // 720 TWIP === 720 / 20 pt === .5 in
.spacing({line: 276}); // 276 / 240 = 1.15x line spacing
.indent({ left: 720 }) // 720 TWIP === 720 / 20 pt === .5 in
.spacing({ line: 276 }); // 276 / 240 = 1.15x line spacing
myStyles.createParagraphStyle("Heading2", "Heading 2")
myStyles
.createParagraphStyle("Heading2", "Heading 2")
.basedOn("Normal")
.next("Normal")
.quickFormat()
.size(26) // 26 half-points === 13pt font
.size(26) // 26 half-points === 13pt font
.bold()
.underline("double", "FF0000")
.spacing({before: 240, after: 120}); // TWIP for both
.spacing({ before: 240, after: 120 }); // TWIP for both
doc.createParagraph("Hello").style("myWonkyStyle");
doc.createParagraph("World").heading2(); // Uses the Heading2 style
doc.addParagraph(
new Paragraph({
text: "Hello",
style: "myWonkyStyle",
}),
);
doc.addParagraph(
new Paragraph({
text: "World",
heading: HeadingLevel.HEADING_2,
}),
); // Uses the Heading2 style
const packer = new Packer();