docx_file_viewer 1.0.1 copy "docx_file_viewer: ^1.0.1" to clipboard
docx_file_viewer: ^1.0.1 copied to clipboard

A Flutter package for rendering DOCX files with native widgets. View, zoom, search, and interact with Word documents.

docx_file_viewer #

pub package Flutter License: MIT

A high-fidelity native Flutter DOCX viewer that renders Word documents using pure Flutter widgets. No WebView, no PDF conversionβ€”just native rendering for maximum performance and cross-platform compatibility.

Example

✨ Features #

Feature Description
🎯 Native Flutter Rendering Pure Flutter widgets, no WebView or PDF conversion required
πŸ“„ View Modes Continuous scroll or paged (print layout) view modes
πŸ“– Full DOCX Support Paragraphs, tables, lists, images, shapes, headers, footers
πŸ” Text Search Find and highlight text with navigation controls
πŸ”Ž Pinch-to-Zoom Smooth zoom with configurable min/max scales
βœ‚οΈ Text Selection Select and copy text from documents
🎨 Theming Light/dark themes with full customization
πŸ”€ Embedded Fonts OOXML font loading with deobfuscation support
πŸ“ Footnotes & Endnotes Interactive references with tap-to-view dialogs
πŸ–ΌοΈ Floating Images Left/right image positioning with text wrap

πŸ“¦ Installation #

Add docx_file_viewer to your pubspec.yaml:

dependencies:
  docx_file_viewer: ^1.0.1

Then run:

flutter pub get

πŸš€ Quick Start #

import 'package:docx_file_viewer/docx_file_viewer.dart';

// From file
DocxView.file(myFile)

// From bytes
DocxView.bytes(docxBytes)

// From path
DocxView.path('/path/to/document.docx')

// With configuration
DocxView(
  file: myFile,
  config: DocxViewConfig(
    enableSearch: true,
    enableZoom: true,
    pageMode: DocxPageMode.paged,
    theme: DocxViewTheme.light(),
  ),
)

πŸ“– Usage Examples #

Basic Viewer #

Scaffold(
  body: DocxView.file(
    File('document.docx'),
    config: DocxViewConfig(
      enableZoom: true,
      backgroundColor: Colors.white,
    ),
  ),
)

Paged View (Print Layout) #

DocxView(
  bytes: docxBytes,
  config: DocxViewConfig(
    pageMode: DocxPageMode.paged,  // Print-style page layout
    pageWidth: 794,                 // A4 width in pixels
    pageHeight: 1123,               // A4 height in pixels
  ),
)
Scaffold(
  body: DocxViewWithSearch(
    file: myDocxFile,
    config: DocxViewConfig(
      enableSearch: true,
      searchHighlightColor: Colors.yellow,
      currentSearchHighlightColor: Colors.orange,
    ),
  ),
)

Dark Theme #

DocxView(
  bytes: docxBytes,
  config: DocxViewConfig(
    theme: DocxViewTheme.dark(),
    backgroundColor: Color(0xFF1E1E1E),
  ),
)

Programmatic Search Control #

final searchController = DocxSearchController();

// Widget
DocxView(
  file: myFile,
  searchController: searchController,
)

// Control search programmatically
searchController.search('keyword');
searchController.nextMatch();
searchController.previousMatch();
searchController.clear();

// Listen to search changes
searchController.addListener(() {
  print('Found ${searchController.matchCount} matches');
  print('Current: ${searchController.currentMatchIndex + 1}');
});

With Callbacks #

DocxView(
  file: myFile,
  onLoaded: () {
    print('Document loaded successfully');
  },
  onError: (error) {
    print('Failed to load document: $error');
  },
)

βš™οΈ Configuration Options #

Property Type Default Description
enableSearch bool true Enable text search with highlighting
enableZoom bool true Enable pinch-to-zoom
enableSelection bool true Enable text selection
minScale double 0.5 Minimum zoom scale
maxScale double 4.0 Maximum zoom scale
pageMode DocxPageMode paged Layout mode (continuous/paged)
pageWidth double? null Fixed page width (paged mode)
pageHeight double? null Fixed page height (paged mode)
padding EdgeInsets 16.0 Document content padding
backgroundColor Color? null Viewer background color
showPageBreaks bool true Show visual page break separators
showDebugInfo bool false Show debug placeholders for unsupported elements
searchHighlightColor Color Yellow Background color for search matches
currentSearchHighlightColor Color Orange Background for current match
customFontFallbacks List<String> ['Roboto', 'Arial', 'Helvetica'] Font fallback chain
theme DocxViewTheme? Light Document rendering theme

🎨 Theming #

Create a custom theme for consistent document styling:

DocxViewTheme(
  backgroundColor: Colors.white,
  defaultTextStyle: TextStyle(fontSize: 14, color: Colors.black87, height: 1.5),
  headingStyles: {
    1: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
    2: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
    3: TextStyle(fontSize: 20, fontWeight: FontWeight.w600),
    4: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
    5: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
    6: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
  },
  codeBlockBackground: Color(0xFFF5F5F5),
  codeTextStyle: TextStyle(fontFamily: 'monospace', fontSize: 13),
  blockquoteBackground: Color(0xFFF9F9F9),
  blockquoteBorderColor: Color(0xFFCCCCCC),
  tableBorderColor: Color(0xFFDDDDDD),
  tableHeaderBackground: Color(0xFFEEEEEE),
  linkStyle: TextStyle(color: Colors.blue, decoration: TextDecoration.underline),
  bulletColor: Color(0xFF333333),
)

// Or use presets
DocxViewTheme.light()
DocxViewTheme.dark()

πŸ“‹ Supported DOCX Elements #

Element Status Notes
Text Formatting
Bold, Italic, Underline βœ… Full support
Strikethrough βœ… Single and double
Superscript/Subscript βœ…
Text Colors βœ… Including theme colors
Highlight Colors βœ… All standard colors
Font Families βœ… With fallback chain
Font Sizes βœ… Half-point precision
Paragraph Formatting
Headings (H1-H6) βœ… Mapped from outline levels
Text Alignment βœ… Left, center, right, justify
Line Spacing βœ… Single, 1.5, double, exact
Indentation βœ… Left, right, first-line, hanging
Paragraph Borders βœ… All sides with colors
Paragraph Shading βœ… Background colors
Drop Caps βœ… With text wrap
Lists
Bullet Lists βœ… Multiple bullet styles
Numbered Lists βœ… Multiple numbering formats
Nested Lists βœ… Multi-level indentation
Custom Markers βœ… Image bullets supported
Tables
Basic Tables βœ… Rows, columns, cells
Cell Merging βœ… Horizontal and vertical
Cell Borders βœ… All sides with colors
Cell Shading βœ… Background colors
Conditional Formatting βœ… First/last row/col, banding
Images & Shapes
Inline Images βœ… Embedded and linked
Floating Images βœ… Left/right positioning
Basic Shapes βœ… Rectangles, text boxes
Document Structure
Headers βœ… First page, odd/even
Footers βœ… First page, odd/even
Footnotes βœ… Interactive with dialog
Endnotes βœ… Interactive with dialog
Page Breaks βœ… Visual separators
Section Breaks βœ… Page size changes
Links
Hyperlinks βœ… External URL support
Bookmarks πŸ”„ Partial support
Other
Embedded Fonts βœ… OOXML deobfuscation
Style Inheritance βœ… Full cascade support
Checkboxes βœ… Checked/unchecked states

πŸ”— Integration with docx_creator #

This package uses docx_creator for parsing DOCX files:

import 'package:docx_creator/docx_creator.dart';
import 'package:docx_file_viewer/docx_file_viewer.dart';

// Create a document
final doc = docx()
  .h1('My Document')
  .p('This is a paragraph with some text.')
  .table([
    ['Header 1', 'Header 2'],
    ['Cell 1', 'Cell 2'],
  ])
  .build();

// Export to bytes
final bytes = await DocxExporter().exportToBytes(doc);

// View immediately
DocxView.bytes(Uint8List.fromList(bytes))

πŸ” Search API #

The DocxSearchController provides full control over document search:

final controller = DocxSearchController();

// Properties
controller.query;              // Current search query
controller.matches;            // All found matches
controller.matchCount;         // Number of matches
controller.currentMatchIndex;  // Current match index (0-based)
controller.currentMatch;       // Current SearchMatch object
controller.isSearching;        // Whether search is active

// Methods
controller.search('text');     // Search for text
controller.nextMatch();        // Go to next match
controller.previousMatch();    // Go to previous match
controller.clear();            // Clear search
controller.getBlockText(idx);  // Get text at block index

// Listen to changes
controller.addListener(() => print('Search updated'));

πŸ“± Platform Support #

Platform Support
iOS βœ…
Android βœ…
Web βœ…
macOS βœ…
Windows βœ…
Linux βœ…

🀝 Contributing #

Contributions are welcome! Please read our contributing guidelines and submit pull requests to our repository.

πŸ“„ License #

MIT License - see LICENSE for details.

11
likes
160
points
877
downloads
screenshot

Publisher

verified publisheralihassan143cool.blogspot.com

Weekly Downloads

A Flutter package for rendering DOCX files with native widgets. View, zoom, search, and interact with Word documents.

Homepage
Repository (GitHub)
View/report issues

Topics

#docx #word #viewer #document #office

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

docx_creator, flutter, url_launcher

More

Packages that depend on docx_file_viewer