Files
docx-js/demo/27-declaritive-styles-3.ts

68 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-02-26 22:20:20 +00:00
// Custom styles using JavaScript configuration
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
2020-12-24 03:37:43 +00:00
import { Document, convertInchesToTwip, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
2019-10-10 01:08:01 +01:00
const doc = new Document({
styles: {
paragraphStyles: [
{
id: "myWonkyStyle",
name: "My Wonky Style",
basedOn: "Normal",
next: "Normal",
run: {
color: "990000",
italics: true,
},
paragraph: {
indent: {
2020-12-24 03:37:43 +00:00
left: convertInchesToTwip(0.5),
2019-10-10 01:08:01 +01:00
},
spacing: {
line: 276,
},
},
},
{
id: "Heading2",
name: "Heading 2",
basedOn: "Normal",
next: "Normal",
quickFormat: true,
run: {
bold: true,
size: 26,
underline: {
type: UnderlineType.DOUBLE,
color: "FF0000",
},
},
paragraph: {
spacing: {
before: 240,
after: 120,
},
},
},
],
},
});
2019-07-31 08:48:02 +01:00
doc.addSection({
children: [
new Paragraph({
text: "Hello",
style: "myWonkyStyle",
}),
new Paragraph({
text: "World",
heading: HeadingLevel.HEADING_2,
}),
],
});
2019-08-07 22:12:14 +01:00
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});