Skip to content

Configuration

vyuh_docx is headless, so it has no global app configuration. Configuration is local to the reader, builder, exporter, layout, and diagnostic APIs that need it.

PDF Export Configuration

dart
final exporter = PdfExporter(
  pageWidth: 612,
  pageHeight: 792,
  marginTop: 72,
  marginBottom: 72,
  marginLeft: 72,
  marginRight: 72,
  fontSize: 11,
  compressContent: true,
  watermark: 'CONTROLLED',
  watermarkColorHex: 'D9D9D9',
  watermarkOpacity: 0.18,
  creationDate: trustedIssuedAt,
  strictFonts: true,
);

exporter.registerFont('Arial', arialBytes);
final bytes = exporter.exportToBytes(document);
OptionDefaultPurpose
pageWidth612.0Default page width in points. Used when the document section does not override page geometry.
pageHeight792.0Default page height in points.
marginTop72.0Default top margin in points.
marginBottom72.0Default bottom margin in points.
marginLeft72.0Default left margin in points.
marginRight72.0Default right margin in points.
fontSize11Base font size used when the document has no more specific style.
compressContenttrueCompress PDF content streams. Disable for raw PDF debugging.
watermarknullOptional diagonal watermark across every page.
watermarkColorHexD9D9D9Watermark fill color without #.
watermarkOpacity0.18Watermark alpha from 0 to 1.
creationDatewall clockFixed PDF creation time for deterministic output.
strictFontsfalseThrow if text cannot be represented by registered fonts.
registerFontnoneRegister host-supplied font bytes by font family name.

Layout Engine Configuration

Most callers use PdfExporter, which creates PdfLayoutEngine from section data. Use the layout engine directly for diagnostics or custom rendering.

dart
final layout = PdfLayoutEngine(
  pageWidth: 612,
  pageHeight: 792,
  marginTop: 72,
  marginBottom: 72,
  marginLeft: 72,
  marginRight: 72,
).buildLayoutDocument(document.elements);

The exporter also passes section-derived configuration such as header reserve, footer reserve, columns, document grid line pitch, and default tab stop.

Reader Configuration

Readers are intentionally low ceremony:

ReaderConfiguration model
DocxReader.load(path)File path only. Reads the DOCX package and resolves relationships, styles, numbering, sections, comments, revisions, and media.
DocxReader.loadFromBytes(bytes)Byte payload only. Use this for server, browser, storage, or upload flows.
SfdtReader.read(json)SFDT JSON string.
SfdtReader.readMap(map)Already-decoded SFDT map.
HtmlParser / MarkdownParserParser object plus source content.

Builder Configuration

The builder API configures the document through fluent calls and ends with build():

dart
final document = docx()
  .h1('Procedure')
  .p('Use the approved equipment.')
  .table(rows: [
    ['Step', 'Owner'],
    ['Review', 'QA'],
  ])
  .build();

For lower-level generation, use DocxDocumentBuilder and model classes directly when a typed field is needed before a fluent helper exists.

Exporter Configuration

ExporterConfiguration
DocxExporterWrites the model to DOCX bytes or file. Configuration is mostly document-driven.
SfdtExporterWrites the model to Syncfusion JSON. Configuration is document-driven.
HtmlExporterWrites HTML output. Configuration is document-driven.
PdfExporterExposes page defaults, compression, watermark, timestamp, and font strictness.

Deterministic Review Setup

For review tests and controlled rendering, prefer:

dart
final exporter = PdfExporter(
  creationDate: DateTime.utc(2026, 6, 20),
  strictFonts: true,
  compressContent: false,
);

compressContent: false makes PDF content streams easier to inspect in tests. creationDate removes wall-clock drift. strictFonts prevents silent glyph loss.