diff --git a/demo/95-paragraph-style-with-shading-and-borders.ts b/demo/95-paragraph-style-with-shading-and-borders.ts new file mode 100644 index 0000000000..d6b0cf8b33 --- /dev/null +++ b/demo/95-paragraph-style-with-shading-and-borders.ts @@ -0,0 +1,60 @@ +import * as fs from "fs"; +import { BorderStyle, Document, Packer, Paragraph, TextRun } from "docx"; + +const doc = new Document({ + styles: { + paragraphStyles: [ + { + id: "withSingleBlackBordersAndYellowShading", + name: "Paragraph Style with Black Borders and Yellow Shading", + basedOn: "Normal", + paragraph: { + shading: { + color: "#fff000", + type: "solid", + }, + border: { + top: { + style: BorderStyle.SINGLE, + color: "#000000", + size: 4, + }, + bottom: { + style: BorderStyle.SINGLE, + color: "#000000", + size: 4, + }, + left: { + style: BorderStyle.SINGLE, + color: "#000000", + size: 4, + }, + right: { + style: BorderStyle.SINGLE, + color: "#000000", + size: 4, + }, + }, + }, + }, + ], + }, + sections: [ + { + children: [ + new Paragraph({ + style: "withSingleBlackBordersAndYellowShading", + children: [ + new TextRun({ + text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", + }), + ], + }), + ], + }, + ], +}); + +Packer.toBuffer(doc).then((buffer) => { + fs.writeFileSync("My Document.docx", buffer); +}); diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index b8d050c6a2..360050db4e 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -38,6 +38,8 @@ export type ILevelParagraphStylePropertiesOptions = { }; export type IParagraphStylePropertiesOptions = { + readonly border?: IBordersOptions; + readonly shading?: IShadingAttributesProperties; readonly numbering?: | { readonly reference: string; @@ -49,7 +51,6 @@ export type IParagraphStylePropertiesOptions = { } & ILevelParagraphStylePropertiesOptions; export type IParagraphPropertiesOptions = { - readonly border?: IBordersOptions; readonly heading?: (typeof HeadingLevel)[keyof typeof HeadingLevel]; readonly bidirectional?: boolean; readonly pageBreakBefore?: boolean; @@ -58,7 +59,6 @@ export type IParagraphPropertiesOptions = { readonly bullet?: { readonly level: number; }; - readonly shading?: IShadingAttributesProperties; readonly widowControl?: boolean; readonly frame?: IFrameOptions; readonly suppressLineNumbers?: boolean;