Skip to main content

PDF Export

PRO
Pro preview

This feature is part of FD Components Pro, which is documented as a preview and is not publicly available yet. See Editions and Availability.

FDC Pro includes a dependency-free PDF table writer that produces binary PDF bytes directly from the FDC export pipeline.

Register Pro export formats

Initialize Pro integrations once:

void main() {
FdcPro.ensureInitialized();
runApp(const App());
}

FdcPro.ensureInitialized() registers the PDF and Excel writers and is safe to call more than once.

Basic PDF export

final result = await FdcExporter.exportDataSet(
orders,
format: FdcPdfExportFormat.pdf,
options: FdcExportOptions(
scope: FdcExportScope.currentView,
),
suggestedFileName: 'orders.pdf',
);

final pdfBytes = result.bytes;

PDF is a binary format, so result.textOrNull is null and result.text throws. Use result.bytes.

Document and table options

PDF-specific behavior is configured through FdcPdfExportOptions:

final result = await FdcExporter.exportDataSet(
orders,
format: FdcPdfExportFormat.pdf,
writerOptions: const FdcPdfExportOptions(
pageSize: FdcPdfPageSize.a4,
orientation: FdcPdfOrientation.landscape,
margins: FdcPdfMargins.all(24),
minColumnWidth: 36,
maxColumnWidth: 160,
wrapText: true,
maxCellLines: 3,
),
);

Supported page sizes are A4 and US Letter. Both portrait and landscape orientation are available.

FdcPdfExportOptions(
header: const FdcPdfHeader(
title: 'Order Report',
subtitle: 'Current filtered view',
alignment: FdcPdfTitleAlignment.left,
repeatOnEveryPage: true,
),
)

The header supports:

  • title and optional subtitle,
  • left, center, or right alignment,
  • independent title/subtitle font sizes and colors,
  • spacing controls,
  • optional repetition on every page.
FdcPdfExportOptions(
footer: const FdcPdfFooter(
text: 'FD Components reporting sample',
showPageNumbers: true,
pageNumberFormat: 'Page {page} of {totalPages}',
),
)

Footer text and page numbers have independent alignment settings. The page-number template recognizes {page} and {totalPages}.

Column widths

The writer can size columns automatically within minimum and maximum limits:

FdcPdfExportOptions(
minColumnWidth: 32,
maxColumnWidth: 180,
)

Override selected columns by export key or field name:

FdcPdfExportOptions(
columnWidths: {
'order_no': 72,
'customer_name': 160,
'total': 70,
},
)

Resolution checks FdcExportColumn.key first and then fieldName.

Text wrapping

FdcPdfExportOptions(
wrapText: true,
maxCellLines: 4,
)

Wrapping is opt-in. maxCellLines bounds row growth for long cell content.

PDF style

Visual presentation is separate from document behavior:

const reportStyle = FdcPdfExportStyle(
fontSize: 9,
cellHorizontalPadding: 6,
cellVerticalPadding: 5,
showGrid: true,
outerBorderWidth: 0.5,
innerBorderWidth: 0.2,
);

FdcPdfExportStyle controls:

  • optional TrueType font,
  • table font size,
  • cell padding,
  • header and row text colors,
  • header background,
  • normal and alternating row backgrounds,
  • grid visibility and color,
  • outer and inner border widths.

Style precedence

PDF style resolution follows this order:

FdcPdfExportOptions.style
→ FdcExportStyle resolved for PDF
→ built-in FdcPdfExportStyle defaults

For grid-triggered exports, the grid passes the nearest FdcApp.exportStyle into the export pipeline.

Application-level default:

FdcApp(
exportStyle: FdcExportStyle(
pdf: const FdcPdfExportStyle(
fontSize: 9,
showGrid: false,
),
),
child: const ReportsPage(),
)

Per-export override:

FdcPdfExportOptions(
style: const FdcPdfExportStyle(
fontSize: 8,
showGrid: true,
),
)

The per-export style wins.

Custom TrueType font

const style = FdcPdfExportStyle(
font: FdcPdfFont.fromAsset(
'assets/fonts/Inter-Regular.ttf',
),
);

The font must be available through the Flutter asset bundle. Package-provided assets can specify the package name:

FdcPdfFont.fromAsset(
'assets/fonts/Report.ttf',
package: 'my_report_package',
)

Without a custom font, the writer uses PDF's built-in Helvetica font.

Grid-visible formatting

When PDF export originates from a grid in visibleColumns mode, the grid supplies:

  • visible runtime column order,
  • labels,
  • display value formatters,
  • text alignment hints.

This allows the PDF writer to preserve presentation-oriented values more closely than a plain dataset-field export.

Grid toolbar configuration

FdcGridExportButton(
visible: true,
formats: const [
FdcExportFormat.csv,
FdcPdfExportFormat.pdf,
],
writerOptions: const {
FdcPdfExportFormat.pdf: FdcPdfExportOptions(
header: FdcPdfHeader(title: 'Orders'),
orientation: FdcPdfOrientation.landscape,
footer: FdcPdfFooter(
showPageNumbers: true,
),
),
},
onExport: handleExport,
)