universal_document_viewer library

Open and read PDF, Word (.docx), Excel (.xlsx), CSV, PowerPoint (.pptx) and plain text documents, with the package's own engines.

The quickest way to show any supported file is DocumentViewer:

DocumentViewer.file(path)

For your own toolbar, search field or layout, use a format's controller and view: PdfController and PdfView, WordController and WordView, SpreadsheetController and SpreadsheetView, SlidesController and SlidesView, PlainTextController and PlainTextView. DocumentThumbnails draws a preview of any of them.

This library exports everything. Each format also has a library of its own (pdf.dart, word.dart, spreadsheet.dart, slides.dart, plain_text.dart) for apps that use only one.

Classes

BoolValue
A boolean, shown as TRUE or FALSE.
BorderLine
One side's line: its style, and colour as 0xAARRGGBB (null for automatic, which is black on white paper).
CellBorders
The lines on a cell's four sides; null where there's none.
CellComment
A note on a cell (Excel's "comment"; a threaded comment shows as the thread's text, as older Excel shows it).
CellMatch
A single cell match from a SpreadsheetController's search.
CellRange
A rectangle of cells, zero-based and inclusive (A1:B2 is rows 0-1, columns 0-1).
CellStyle
The parts of a cell's formatting a reader shows.
CellValue
A cell's content.
CsvReader
Reads CSV text (RFC 4180) into a one-sheet Workbook.
DataBar
A bar across part of a cell's width, as conditional formatting draws it: fraction (0-1) of the width, in color (0xAARRGGBB).
DocumentController
What every format's controller does, so an app can build one toolbar, search bar and position display for all of them.
DocumentLocation
Where the reader is in a document: "page 3 of 12", "row 40 of 900".
DocumentSearchState
A search in a document: the query, how many times it occurs and which occurrence is current.
DocumentThumbnails
A small picture of a document's first page, for file lists: PDF page 1, a Word document's first print-layout page, PowerPoint slide 1, the top-left of a spreadsheet's first sheet, or a text file's first lines - each on white, in the page's own shape.
DocumentViewer
Shows any document the package reads, with the matching reader and a small toolbar: PDF, Word, Excel (with sheet tabs), CSV, PowerPoint or plain text.
DocumentViewerStrings
The text the package's widgets show: messages, labels, tooltips and screen-reader descriptions. English by default.
DocumentViewerStringsScope
Gives the package's widgets below it strings instead of English.
DocumentViewerTheme
Colours the package's views use for search matches, as a ThemeExtension on the app's theme.
DocxReader
Reads a .docx (WordprocessingML, ECMA-376 Part 1 §17) into a WordDocument for display.
ErrorValue
An error result such as #DIV/0! or #N/A.
FormulaValue
A formula and the result Excel saved with it (cached; null when the file has none).
ListMarker
A list item's number or bullet, already worked out (1., 2.3, iv), •), with its own formatting.
NumberFormat
An Excel number format code (ECMA-376 Part 1, §18.8.31), e.g. #,##0.00, 0%, m/d/yyyy or $#,##0_);[Red]($#,##0), and how a number looks under it.
NumberValue
A number. Dates and times are numbers too (days since the workbook's epoch, as Excel stores them); the cell's number format shows them as dates.
ParagraphFormat
A paragraph's resolved formatting. Lengths in points.
PdfController
Opens a PDF for PdfView: the document (asking passwordProvider for the password of an encrypted one), the page on screen, the layout (viewMode), zoom and search.
PdfiumDocument
An open PDF. All PDFium work happens in one shared background isolate; this object holds the document's id there and its page sizes.
A link on a page: a web address, or a page in this document.
PdfPageText
A page's text as PDFium reads it, with each character's box.
PdfPageThumbnail
A whole page as a small image (e.g. a thumbnail strip), rendered at low priority.
PdfRenderedImage
A rendered region of a page, as RGBA pixels.
PdfRenderTask
A cancellable render request. cancel drops it if it hasn't started, and result then fails with PdfCancelledException.
PdfSearchController
Text search over a PDF, page by page in the PDF worker; matches arrive as each page is searched.
PdfTextMatch
A search hit on one page: the boxes it covers, one per line.
PdfView
Shows the PDF a PdfController has opened, in its layout.
PlainTextController
Loads a plain-text document for PlainTextView: its lines, line wrap, zoom, search and the scroll position.
PlainTextView
Shows a PlainTextController's document as scrolling lines.
PositionKeys
Keys used in ReadingPosition maps, per reader.
PptxBlock
One piece of slide content, in reading order.
PptxImage
A picture placed on the slide.
PptxParagraph
A text paragraph; level is the bullet indent (0 = top level).
PptxParser
Reads a .pptx (Office Open XML) into slides of text, tables and pictures. It is a reading view, not a layout engine: positions, themes and animations are not reproduced.
PptxPresentation
A parsed deck.
PptxSlide
One slide's content.
PptxTable
A table, as rows of cell text.
RunFormat
A run's resolved formatting. Sizes in points.
SheetCell
One cell: its value, formatting and any data bar.
SheetLayout
How a sheet's rows and columns are sized, in the file's own units: column widths in characters of the default font's digit width (Excel's "8.43"), row heights in points.
SlideCard
One slide's content as a card: what SlidesView shows for each slide, and usable on its own, for example scaled down as a preview.
SlideMatch
One occurrence of a search in a presentation: the occurrenceth match (from 0) on slide slide (from 0), counting in the order SlidesView draws the slide's text - title, then paragraphs and table cells.
SlidesController
Loads a PowerPoint (.pptx) presentation for SlidesView: its slides, the one on screen, zoom and search.
SlidesView
Shows a SlidesController's presentation one slide at a time: swipe, or drive it from the controller.
SpreadsheetController
Loads an Excel workbook (.xlsx) or a CSV file for SpreadsheetView: its sheets (a CSV has one), the sheet on screen, zoom, search and scrolling.
SpreadsheetView
A spreadsheet grid built lazily (only the cells on screen exist), with the sheet's own column widths and row heights, hidden rows/columns left out, its frozen panes pinned along with the header row and row-number column, merged cells, and its text formatting. Also: a −/+ zoom pill, search highlights, row/column selection with Count/Sum/Avg and Copy, a cell's full value (with its formula, note and link) on tap. Cell borders, conditional formatting (fills, colours, data bars) and a note marker come from the file. Scrolls through the controller's verticalController/horizontalController. Serves Excel and CSV alike.
TextMatch
One occurrence of a search in a plain-text document: on line line (from 0), starting at character start.
TextValue
A text value (a shared, inline or formula string, or CSV text).
WordBlock
A block-level piece of content: a WordParagraph, a WordTable or a WordSectionBreak.
WordBookmark
A named place a link can jump to (w:bookmarkStart).
WordBorderLine
A line on one side of a cell or paragraph.
WordBreak
A break inside a paragraph (w:br, w:cr).
WordCellBorders
The four borders of a table cell; a null side has no line.
WordController
Loads a Word (.docx) document for WordView: its layout (viewMode), zoom, search, the page in view and the scroll position.
WordDocument
A Word document as read from a .docx, ready to display: styles are already resolved onto every paragraph and run, list markers are already numbered, and field codes are reduced to their shown results.
WordImage
A picture (DrawingML w:drawing or a VML picture).
WordInline
A piece of a paragraph's content: text, a tab, a break, an image, a note mark, a page field or a bookmark.
A link's target: a web address, or a bookmark in this document.
WordNoteReference
A footnote or endnote mark in the text (w:footnoteReference, w:endnoteReference).
WordPageField
A PAGE or NUMPAGES field: the page number (or count) where it's shown. fallback is the result Word saved, for views without pages.
WordPageThumbnail
Page page (1-based) of controller's print layout, scaled down to fit
WordParagraph
A paragraph (w:p): inline content with resolved formatting.
WordSection
A section's page and its headers/footers. Sizes are in points.
WordSectionBreak
Where one section ends and the next begins.
WordTab
A tab character (w:tab, w:ptab).
WordTable
A table (w:tbl) of rows on a grid of columnWidths.
WordTableCell
A table cell (w:tc).
WordTableRow
A table row (w:tr).
WordText
A stretch of text with one formatting (from a run, w:r).
WordView
A .docx, lazily built, in one of two layouts (WordController.viewMode):
Workbook
A spreadsheet as read from an .xlsx or CSV file: its sheets in workbook order, hidden ones included (a reader decides whether to show them).
Worksheet
One sheet of a Workbook: its cells, layout, merges, links and notes.
XlsxReader
Reads an .xlsx workbook (SpreadsheetML, ECMA-376 Part 1 §18) for display: sheet order and visibility, cell values (shared and inline strings, numbers, booleans, errors, formulas with their saved results), the formatting a reader shows (number format, bold, italic, solid fill with theme and indexed colours, cell borders), conditional formatting (see ConditionalRule for which rules), comments, and frozen panes.
ZipSafetyGuard
Guards against zip bombs and path traversal in Office (OOXML) files: run before handing bytes to the Word, spreadsheet and slide engines.

Enums

BorderLineStyle
Excel's line styles. A reader draws the dashed and dotted ones solid; width is their weight in logical pixels.
BreakKind
What a WordBreak ends (w:br w:type).
CellVerticalAlignment
How a table cell's content sits vertically (w:vAlign).
DocumentFormat
A document type universal_document_viewer can read, and how files map to it.
DocumentLoadError
Why a document couldn't be opened.
DocumentStatus
Where a DocumentController is in its document's life.
DocumentUnit
What DocumentLocation.current and DocumentLocation.count count.
HeaderFooterKind
Which pages a header or footer is for (w:headerReference w:type).
HorizontalAlignment
A cell's horizontal alignment, from <alignment horizontal>.
LineSpacingRule
How ParagraphFormat.lineSpacing is measured (w:spacing w:lineRule).
ListMarkerSuffix
What separates a list marker from the text (w:suff).
NoteKind
Whether a note is a footnote or an endnote.
PageFieldKind
What a WordPageField shows.
ParagraphAlignment
Horizontal alignment of a paragraph's lines (w:jc) or of a table.
PdfOpenError
Why a PDF couldn't be opened.
PdfPriority
How urgently a request is served: what's on screen first.
PdfViewMode
How pages are laid out. A vertical single-page-snap mode isn't offered: horizontal already covers reading one page at a time.
SheetVisibility
Whether a sheet's tab is shown, from <sheet state> in the workbook.
UnderlineStyle
A run's underline (w:u). Word's many styles are reduced to these.
VerticalAlignment
A cell's vertical alignment, from <alignment vertical>.
VerticalTextPosition
A run's position relative to the baseline (w:vertAlign).
WordViewMode
How WordView lays a document out.
ZipSafetyResult
What ZipSafetyGuard.check found.

Extensions

PdfMatchRects on PdfTextMatch
Rect helpers for page-space search hits.

Functions

decodeTextBytes(Uint8List bytes) → String
UTF-8 first; Latin-1 (which accepts every byte) as the fallback for a non-UTF-8 file. Deliberately not full charset detection; shared by the plain-text and CSV readers.
hasUtf16Bom(Uint8List bytes) → bool
Whether bytes start with a UTF-16 byte order mark (FF FE or FE FF). UTF-16 text is full of NUL bytes, so a binary-file check should ask this first.
looksLikeBinary(Uint8List bytes) → bool
Whether bytes look like a binary file rather than text (for example a binary file renamed .txt or .csv).

Typedefs

CellAddress = ({int column, int row})
A zero-based cell position.
PdfPasswordProvider = Future<String?> Function()
Asked for a password when a PDF is encrypted; null gives up.
ReadingPosition = Map<String, Object?>
A reader's saved place in a document, as plain JSON-safe values.

Exceptions / Errors

DocxFormatException
The file isn't a readable .docx.
PdfCancelledException
A request was cancelled before it ran.
PdfEngineException
The worker went away (e.g. the native library failed to load).
PdfOpenException
Thrown when PDFium can't open a document; error says why.
PptxFormatException
Not a readable PowerPoint (.pptx) package.
XlsxFormatException
The file isn't a readable .xlsx.