DocxDocumentBuilder class

Fluent builder for creating DOCX documents.

Simple API Example

final doc = Docx()
  .h1('Title')
  .p('Some text with **bold** and *italic*.')
  .bullet(['Item 1', 'Item 2', 'Item 3'])
  .table([['A', 'B'], ['1', '2']])
  .build();

await doc.save('output.docx');

Constructors

DocxDocumentBuilder()

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(DocxNode node) DocxDocumentBuilder
Adds any DocxNode element.
addEndnote(DocxEndnote note) DocxDocumentBuilder
Adds an endnote to the document.
addFont(String familyName, Uint8List bytes) DocxDocumentBuilder
Adds a custom font to the document.
addFootnote(DocxFootnote note) DocxDocumentBuilder
Adds a footnote to the document.
addList(DocxList list) DocxDocumentBuilder
Adds a custom list.
addSectionBreak(DocxSectionDef section) DocxDocumentBuilder
Adds a section break, defining properties for the preceding section.
addTable(DocxTable table) DocxDocumentBuilder
Adds a custom table.
build() DocxBuiltDocument
Builds the final document.
bullet(List<String> items) DocxDocumentBuilder
Adds a bulleted list.
code(String code) DocxDocumentBuilder
Adds a code block.
divider() DocxDocumentBuilder
Adds a divider (alias for hr).
h1(String text) DocxDocumentBuilder
Adds a heading level 1.
h2(String text) DocxDocumentBuilder
Adds a heading level 2.
h3(String text) DocxDocumentBuilder
Adds a heading level 3.
heading(DocxHeadingLevel level, String text) DocxDocumentBuilder
Adds a heading at specified level.
heading1(String text) DocxDocumentBuilder
Adds a heading level 1.
heading2(String text) DocxDocumentBuilder
Adds a heading level 2.
heading3(String text) DocxDocumentBuilder
Adds a heading level 3.
hr() DocxDocumentBuilder
Adds a horizontal rule / divider.
image(DocxImage image) DocxDocumentBuilder
Adds an image.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
numbered(List<String> items) DocxDocumentBuilder
Adds a numbered list.
p(String text, {DocxAlign align = DocxAlign.left, DocxBorderSide? borderBottom}) DocxDocumentBuilder
Adds a paragraph with plain text.
pageBreak() DocxDocumentBuilder
Adds a page break.
paragraph(DocxParagraph paragraph) DocxDocumentBuilder
Adds a paragraph element.
quote(String text) DocxDocumentBuilder
Adds a blockquote.
section({DocxPageOrientation orientation = DocxPageOrientation.portrait, DocxPageSize pageSize = DocxPageSize.letter, DocxHeader? header, DocxFooter? footer, DocxColor? backgroundColor, DocxBackgroundImage? backgroundImage, int? marginTop, int? marginBottom, int? marginLeft, int? marginRight}) DocxDocumentBuilder
Sets section properties (headers, footers, page layout, background).
table(List<List<String>> data, {bool hasHeader = true, DocxTableStyle style = const DocxTableStyle()}) DocxDocumentBuilder
Adds a table from 2D data.
text(String content, {DocxAlign align = DocxAlign.left}) DocxDocumentBuilder
Adds simple text as a paragraph.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited