-
-
Notifications
You must be signed in to change notification settings - Fork 578
Paragraph
Everything (text, images, graphs etc) in OpenXML is organised in paragraphs. You can add more text to the paragraph by doing this:
var paragraph = new docx.Paragraph(),var text = new docx.TextRun('Lorem Ipsum Foo Bar');
var paragraph = new docx.Paragraph();
paragraph.addRun(text);var paragraph = new docx.Paragraph("Short hand notation for adding text.");After you create the paragraph, you must add the paragraph into the document:
doc.addParagraph(paragraph);Styles is a very important part of the look of a word document. At the moment, only headings and title is supported, but son the rest will be supported along with custom styles!
paragraph.heading1();
paragraph.heading2();
paragraph.heading3();
paragraph.heading4();
paragraph.heading5();paragraph.title();To change the text alignment of a paragraph, for center, left, right or justified:
paragraph.center();paragraph.left();paragraph.right();paragraph.justified();paragraph.heading1().center();The above will create a heading 1 which is centered.
To add a break in the page, simply add .thematicBreak() on a paragraph:
var paragraph = new docx.Paragraph("Amazing Heading").heading1().thematicBreak();The above example will create a heading with a page break directly under it.
To move to a new page (insert a page break), simply add .pageBreak() on a paragraph:
var paragraph = new docx.Paragraph("Amazing Heading").heading1().pageBreak();The above example will create a heading and start a new page immediately afterwards.
Paragraphs have .keepLines() and .keepNext() methods that allow restricting page breaks within and between paragraphs. See this Microsoft article for more details)
