docx_creator library
docx_creator - A developer-first DOCX generation library
Create professional Word documents with a fluent API:
import 'package:docx_creator/docx_creator.dart';
final doc = docx()
.h1('Title')
.p('Content')
.build();
await DocxExporter().exportToFile(doc, 'output.docx');
Classes
- BlockParser
- Parses block-level content (paragraphs, lists, tables).
- ContentTypesGenerator
-
Automates the generation of
Content_Types.xml for DOCX archives. - DocxBackgroundImage
- A background image for document pages.
- DocxBlock
- Base class for block-level elements (paragraphs, tables, etc.).
- DocxBorderSide
- Defines a single border side properties.
- DocxBuiltDocument
- A built document ready for export.
- DocxCheckbox
- A clickable checkbox (form field).
- DocxColor
- A color value for text, backgrounds, and borders.
- DocxDocumentBuilder
- Fluent builder for creating DOCX documents.
- DocxDropCap
- A paragraph with drop cap styling (large initial letter).
- DocxEndnote
- An endnote definition.
- DocxEndnoteRef
- An endnote reference in inline text.
- DocxExporter
- Exports DocxBuiltDocument to .docx format.
- DocxFont
- Represents the w:rFonts element properties.
- Footer content for a document section.
- DocxFootnote
- A footnote definition.
- DocxFootnoteRef
- A footnote reference in inline text.
- DocxHeader
- Header content for a document section.
- DocxHeadingStyle
- Customizable heading style.
- DocxIdGenerator
- Generates unique IDs for DOCX document elements.
- DocxIdTracker
- Tracks and validates document IDs to prevent duplicates.
- DocxImage
- An image element in the document (Block Level).
- DocxInline
- Base class for inline elements (text, inline images, etc.).
- DocxInlineImage
- An inline image element (can be used inside paragraphs).
- DocxLineBreak
- A line break.
- DocxList
- A list element (bulleted or numbered).
- DocxListItem
- A single item in a list.
- DocxListStyle
- List styling configuration.
- DocxMeasurements
- Common measurement constants for DOCX documents.
- DocxNode
- Abstract base class for all nodes in the document AST.
- DocxNumberingDef
- Numbering definition from numbering.xml.
- DocxNumberingLevel
- A single level in a numbering definition.
- DocxPageCount
- Total page count field.
- DocxPageNumber
- Page number field.
- DocxParagraph
- A paragraph containing styled text and inline elements.
- DocxParser
- Parses HTML content into DocxNode elements.
- DocxRawInline
- Represents raw inline XML content that should be preserved as-is.
- DocxRawXml
- Represents raw XML content that should be preserved as-is.
- DocxReader
- Reads and parses existing .docx files.
- DocxRelationship
- Represents a relationship entry from .rels files.
- DocxSection
- Base class for section elements (page layout, headers, footers).
- DocxSectionBreakBlock
- Represents a section break in the document.
- DocxSectionDef
- Document section with page layout and headers/footers.
- DocxSectionProperties
- Section properties from document.xml.
- DocxShape
- Represents a DrawingML shape in the document.
- DocxShapeBlock
- Block-level drawing shape container.
- DocxStyle
- Represents parsed style properties from styles.xml.
- DocxStyleIds
- Word's built-in style IDs.
- DocxTab
- A tab character.
- DocxTable
- A table element in the document.
- DocxTableCell
- A cell within a DocxTableRow.
- DocxTableLook
- Table look flags (conditional formatting).
- DocxTableOfContents
- Represents a Table of Contents (TOC) in the document.
- DocxTablePosition
- Floating table position properties.
- DocxTableRow
- A row within a DocxTable.
- DocxTableStyle
- Table styling options.
- DocxText
- A styled text run within a paragraph.
- DocxTheme
- Represents the complete theme and style information from a DOCX document.
- DocxThemeColors
- Theme color definitions from theme1.xml.
- DocxThemeFonts
- Theme font definitions from theme1.xml.
- DocxValidator
- Validates DOCX document structure before export.
- DocxVisitor
- Visitor interface for traversing the document AST.
- FontReader
- Reads and parses embedded fonts from fontTable.xml.
- HtmlExporter
- Exports DocxBuiltDocument to HTML format.
- HtmlStyleContext
- Style context for inline text formatting inheritance.
- InlineParser
- Parses inline content (runs, text, hyperlinks).
- LatentStyleDef
- Latent style definition for styles not explicitly defined.
- MarkdownParser
- Parses Markdown content into DocxNode elements.
- NumberingParser
- Parses numbering definitions from numbering.xml.
- PdfAnnotation
- Represents a PDF annotation.
- PdfBox
- Represents a rectangular box in PDF coordinates.
- PdfDocument
- Represents a parsed PDF document.
- PdfEncryption
- PDF encryption handler.
- PdfExporter
- Exports DocxBuiltDocument to PDF format.
- PdfExtractedImage
- Extracted image with metadata.
- PdfFormField
- Represents a PDF form field.
- PdfMetadata
- PDF document metadata.
- PdfOutlineItem
- Represents a PDF document outline (bookmark) item.
- PdfPageInfo
- Detailed information about a PDF page.
- PdfPageInfoExtractor
- Extracts page information from a PDF document.
- PdfPermissions
- Permissions wrapper for easier access.
- PdfReader
- Reads PDF files and converts content to DocxNode elements.
- ReaderContext
- Shared context for all reader components.
- RelationshipManager
- Manages document relationships and content types.
- ResolvedStyle
- Represents the fully resolved (effective) style for an element.
- SectionParser
- Parses document section properties (page size, margins, headers, footers).
- StyleParser
- Parses and manages document styles from styles.xml.
- StyleResolver
- Resolves style inheritance chains to produce effective styles.
- TableParser
- Parses table elements (w:tbl).
- ThemeParser
- Parses theme colors and fonts from theme1.xml.
- XmlExtensionMap
- Stores unknown XML attributes and child elements for round-trip preservation.
- XmpMetadata
- XMP (Extensible Metadata Platform) metadata.
Enums
- DocxAlign
- Text alignment within a paragraph or table cell.
- DocxBackgroundFillMode
- Fill mode for background images on document pages.
- DocxBorder
- Border styles for tables, paragraphs, and sections.
- DocxDrawingPosition
- Drawing position mode - how the drawing is placed relative to text.
- DocxDropCapStyle
- Drop cap style.
- DocxFontStyle
- DocxFontWeight
- DocxHeadingLevel
- DocxHighlight
- Highlight (background) colors for text.
- DocxHorizontalPositionFrom
- Horizontal position origin for floating drawings
- DocxNumberFormat
- Number format for ordered lists.
- DocxPageOrientation
- DocxPageSize
- DocxSectionBreak
- DocxShapePreset
- Preset shape geometry types
- DocxTableHAnchor
- Horizontal anchor position for floating tables.
- DocxTableVAnchor
- Vertical anchor position for floating tables.
- DocxTextDecoration
- DocxTextWrap
- Text wrapping mode for floating drawings
- DocxVerticalAlign
- DocxVerticalPositionFrom
- Vertical position origin for floating drawings
- DocxWidthType
- DrawingHAlign
- Horizontal alignment for floating drawings
- DrawingVAlign
- Vertical alignment for floating drawings
- PdfAnnotationType
- Types of PDF annotations.
- PdfFieldType
- Types of PDF form fields.
Extensions
- DocxBorderExtension on DocxBorder
- DocxHeadingLevelExtension on DocxHeadingLevel
- EighthPointsToOther on int
- Eighths of a point to other unit conversions
- EmuToOther on int
- EMU to other unit conversions
- FiftiethsPercentToOther on int
- Percentage (in fiftieths of a percent) conversions
- HalfPointsToOther on int
- Half-points to other unit conversions
- InchesToEmu on double
- Inches to EMU conversion
- InchesToTwips on double
- Inches to Twips conversion
- PercentToFiftieths on double
- Percentage to fiftieths conversion
- PointsToEighthPoints on double
- Points to eighths of a point conversion
- PointsToEmu on double
- Points to EMU conversion
- PointsToHalfPoints on double
- Points to half-points conversion
- PointsToTwips on double
- Points to Twips conversion
- TwipsToOther on int
- Twips to other unit conversions
Constants
- kDefaultCellPadding → const int
- Default table cell padding in twips.
- kDefaultFontFamily → const String
- Default font family.
- kDefaultFontSize → const double
- Default font size in points.
- Default footer distance from bottom edge in twips.
- kDefaultHeaderDistance → const int
- Default header distance from top edge in twips.
- kDefaultHeadingFontFamily → const String
- Default heading font family.
- kDefaultImageHeight → const double
- Default image height in points.
- kDefaultImageWidth → const double
- Default image width in points.
- kDefaultLineSpacing → const int
- Default line spacing (single = 240, 1.5 = 360, double = 480).
- kDefaultMarginBottom → const int
- kDefaultMarginLeft → const int
- kDefaultMarginRight → const int
- kDefaultMarginTop → const int
- Default page margins in twips. 1 inch = 1440 twips.
- kDefaultPageHeight → const int
- Default page height in twips. US Letter height: 11 inches = 15840 twips.
- kDefaultPageWidth → const int
- Default page width in twips (1/20th of a point). US Letter width: 8.5 inches = 12240 twips.
- kDefaultSpacingAfter → const int
- Default spacing after paragraph in twips.
- kDefaultSpacingBefore → const int
- Default spacing before paragraph in twips.
- kDefaultTableBorderWidth → const int
- Default table border width in eighths of a point. 4 = 0.5pt, 8 = 1pt.
Functions
-
docx(
) → DocxDocumentBuilder - Shorthand alias for DocxDocumentBuilder.
-
escapeXmlAttribute(
String text) → String - Escapes text for use in XML attribute values.
-
escapeXmlText(
String text) → String - Escapes text content for safe XML embedding.
-
isValidNcName(
String name) → bool - Validates that a string is a valid XML NCName (non-colonized name).
-
stripInvalidXmlChars(
String text) → String - Strips invalid XML characters from a string.
Typedefs
Exceptions / Errors
- DocxException
- Base exception for all docx_ai_creator errors.
- DocxExportException
- Thrown when document export fails.
- DocxIOException
- Thrown when file operations fail.
- DocxParserException
- Thrown when parsing HTML, Markdown, or JSON fails.
- DocxValidationException
- Thrown when document structure is invalid.
- PdfParseException
- PDF parsing exception.