docx_creator 1.0.0 copy "docx_creator: ^1.0.0" to clipboard
docx_creator: ^1.0.0 copied to clipboard

A developer-first Dart package for creating professional DOCX documents with fluent API, Markdown/HTML parsing, and comprehensive formatting.

docx_creator #

pub package License: MIT

A developer-first Dart package for creating professional DOCX documents with a fluent API, Markdown/HTML parsing, and comprehensive formatting options.


✨ Features #

  • πŸš€ Fluent API - Chain methods for clean, readable code
  • πŸ“ Full Formatting - Bold, italic, colors, superscript, and more
  • πŸ“Š Tables - Multiple styles (grid, zebra, professional)
  • πŸ“‹ Lists - Bullet and numbered with custom styling
  • 🎨 Colors - Predefined + custom hex colors
  • πŸ“„ Headers/Footers - Page numbers, styled text
  • πŸ–ΌοΈ Images - Embed images with alignment
  • πŸ”„ Parsers - Convert Markdown & HTML to DOCX
  • 🎭 Page Backgrounds - Custom background colors

πŸ“¦ Installation #

dependencies:
  docx_creator: ^1.0.0

πŸš€ Quick Start #

import 'package:docx_creator/docx_creator.dart';

void main() async {
  final doc = docx()
    .h1('My Document')
    .p('Hello, World!')
    .bullet(['Feature 1', 'Feature 2', 'Feature 3'])
    .table([
      ['Name', 'Score'],
      ['Alice', '95'],
      ['Bob', '87'],
    ])
    .build();

  await DocxExporter().exportToFile(doc, 'output.docx');
}

πŸ“– API Reference #

Document Builder #

Method Description
.h1(text) Heading level 1
.h2(text) Heading level 2
.h3(text) Heading level 3
.p(text) Paragraph
.bullet([...]) Bullet list
.numbered([...]) Numbered list
.table(data) Table from 2D array
.quote(text) Blockquote
.code(text) Code block
.hr() Horizontal rule / divider
.divider() Divider (alias for hr)
.pageBreak() Page break
.section(...) Page settings
.build() Build document

Text Styling #

DocxText('Normal text')
DocxText.bold('Bold text')
DocxText.italic('Italic text')
DocxText.underline('Underlined')
DocxText.strike('Strikethrough')
DocxText.superscript('Β²')
DocxText.subscript('n')
DocxText.code('inline code')
DocxText.link('URL', href: 'https://...')
DocxText('Custom', color: DocxColor('#4285F4'))

Colors #

// Predefined
DocxColor.red
DocxColor.blue
DocxColor.green

// Custom hex
DocxColor('#FF5722')
DocxColor('4285F4')

Tables #

.table(data, style: DocxTableStyle.grid)
.table(data, style: DocxTableStyle.zebra)
.table(data, style: DocxTableStyle.professional)
.table(data, style: DocxTableStyle.plain)

Headers & Footers #

.section(
  header: DocxHeader.text('My Document'),
  footer: DocxFooter.pageNumbers(),
  backgroundColor: DocxColor('#F5F5F5'),
)

Parsing #

// From Markdown
final nodes = DocxParser.fromMarkdown('''
# Title
This is **bold** and *italic*.
- Item 1
- Item 2
''');

// From HTML
final nodes = DocxParser.fromHtml('''
<h1>Title</h1>
<p><strong>Bold</strong> text</p>
''');

// Add to document
for (var node in nodes) {
  builder.add(node);
}

πŸ“„ Complete Example #

import 'package:docx_creator/docx_creator.dart';

void main() async {
  final doc = docx()
    .section(
      header: DocxHeader.styled('Report', color: DocxColor.blue, bold: true),
      footer: DocxFooter.pageNumbers(),
      backgroundColor: DocxColor('#FAFAFA'),
    )
    .h1('Annual Report 2024')
    .p('Executive summary with key findings.')
    
    .h2('Highlights')
    .bullet([
      'Revenue increased 25%',
      'Customer base grew 40%',
      'Launched 3 new products',
    ])
    
    .h2('Financial Summary')
    .table([
      ['Quarter', 'Revenue', 'Growth'],
      ['Q1', '\$1.2M', '+15%'],
      ['Q2', '\$1.5M', '+25%'],
      ['Q3', '\$1.8M', '+20%'],
      ['Q4', '\$2.1M', '+17%'],
    ], style: DocxTableStyle.professional)
    
    .pageBreak()
    .h1('Appendix')
    .paragraph(DocxParagraph(children: [
      DocxText('For questions, contact '),
      DocxText.link('support@company.com', href: 'mailto:support@company.com'),
    ]))
    .build();

  await DocxExporter().exportToFile(doc, 'annual_report.docx');
  print('Document created!');
}

πŸ”§ Advanced Usage #

Rich Text Paragraphs #

DocxParagraph(children: [
  DocxText('Normal '),
  DocxText.bold('bold '),
  DocxText('and '),
  DocxText('colored', color: DocxColor.red),
])

Custom Table Styling #

DocxTable.fromData(data, style: DocxTableStyle(
  border: DocxBorder.double,
  headerFill: '4472C4',
  evenRowFill: 'F5F5F5',
  cellPadding: 150,
))

Images #

DocxImage(
  bytes: imageBytes,
  extension: 'png',
  width: 400,
  height: 300,
  align: DocxAlign.center,
  altText: 'Company Logo',
)

πŸ“‹ Supported Elements #

Element Status
Paragraphs βœ…
Headings (H1-H6) βœ…
Bold/Italic/Underline βœ…
Superscript/Subscript βœ…
Colors (predefined + hex) βœ…
Bullet Lists βœ…
Numbered Lists βœ…
Tables βœ…
Images βœ…
Headers/Footers βœ…
Page Numbers βœ…
Page Breaks βœ…
Horizontal Rules βœ…
Blockquotes βœ…
Code Blocks βœ…
Hyperlinks βœ…
Page Backgrounds βœ…
Markdown Parsing βœ…
HTML Parsing βœ…

πŸ“„ License #

MIT License - see LICENSE for details.


🀝 Contributing #

Contributions are welcome! Please read our contributing guidelines before submitting PRs.


Made with ❀️ for the Dart community

2
likes
0
points
676
downloads

Publisher

verified publisheralihassan143cool.blogspot.com

Weekly Downloads

A developer-first Dart package for creating professional DOCX documents with fluent API, Markdown/HTML parsing, and comprehensive formatting.

Homepage
Repository (GitHub)
View/report issues

Topics

#docx #word #document #office #openxml

License

unknown (license)

Dependencies

archive, html, http, image, markdown, path, xml

More

Packages that depend on docx_creator