Exporting to PDF and printing
For sharing a schedule outside the app, drop a TTMSFNCGanttChartPDFIO (PDF) or
TTMSFNCGanttChartPrintIO (printer) component, point its GanttChart property at
your chart, and configure the export options. Mode selects whether the task
list, the timeline, or both are output; TaskListColumns defines the exported
columns independently of the on-screen columns; and FitToPage, RepeatHeaders,
and the page orientation control layout. Both components share the same option
shape, so the two flows are nearly identical.
procedure TForm1.ExportToPDF;
begin
PDFIO.GanttChart := TMSFNCGanttChart1;
{ Export both the task list and the timeline. }
PDFIO.GanttChartPDFExportOptions.Mode := emBoth;
{ Choose which columns appear in the exported task list. }
PDFIO.GanttChartPDFExportOptions.TaskListColumns.Clear;
PDFIO.GanttChartPDFExportOptions.TaskListColumns.AddColumn('taskname', 'Task', 160, 120);
PDFIO.GanttChartPDFExportOptions.TaskListColumns.AddColumn('startdate', 'Start', 80, 60);
PDFIO.GanttChartPDFExportOptions.TaskListColumns.AddColumn('duration', 'Duration', 80, 60);
{ Scale to a single page and repeat the header on every page. }
PDFIO.GanttChartPDFExportOptions.FitToPage := True;
PDFIO.GanttChartPDFExportOptions.RepeatHeaders := True;
PDFIO.Options.PageOrientation := poLandscape;
PDFIO.Options.OpenInPDFReader := True;
PDFIO.Save('gantt-export.pdf');
end;
void __fastcall TForm1::ExportToPDF()
{
PDFIO->GanttChart = TMSFNCGanttChart1;
// Export both the task list and the timeline.
PDFIO->GanttChartPDFExportOptions->Mode = emBoth;
// Choose which columns appear in the exported task list.
PDFIO->GanttChartPDFExportOptions->TaskListColumns->Clear();
PDFIO->GanttChartPDFExportOptions->TaskListColumns->AddColumn("taskname", "Task", 160, 120);
PDFIO->GanttChartPDFExportOptions->TaskListColumns->AddColumn("startdate", "Start", 80, 60);
PDFIO->GanttChartPDFExportOptions->TaskListColumns->AddColumn("duration", "Duration", 80, 60);
// Scale to a single page and repeat the header on every page.
PDFIO->GanttChartPDFExportOptions->FitToPage = true;
PDFIO->GanttChartPDFExportOptions->RepeatHeaders = true;
PDFIO->Options->PageOrientation = poLandscape;
PDFIO->Options->OpenInPDFReader = true;
PDFIO->Save("gantt-export.pdf");
}
Layout and column options
The GanttChartPDFExportOptions (PDF) and GanttChartPrintExportOptions (print)
objects share these members:
| Member | Purpose |
|---|---|
Mode |
emTaskList, emTimeline, or emBoth. |
TaskListColumns |
Columns to print; build with AddColumn(name, header, width, minWidth). |
FitToPage |
Scale the output to fit a single page. |
RepeatHeaders |
Repeat the header row on every page. |
TimelineUnitWidth / TimelineGroupHeight |
Override timeline sizing for the export. |
ItemHeight |
Bar height in the export. |
UseCustomTaskListAppearance / UseCustomTimeLineAppearance |
Use export-specific appearance instead of the on-screen one. |
The columns you export are independent of the on-screen task list, so a print layout can show different (or fewer) columns than the UI.
PDF-specific and print-specific settings
The IO component's Options carries the output settings. For PDF, set
Options.PageOrientation and Options.OpenInPDFReader, then call Save(filename).
For printing, set Options.PageOrientation and call Print (typically after a
TPrintDialog).
procedure TForm1.PrintChart;
begin
PrintIO.GanttChart := TMSFNCGanttChart1;
PrintIO.GanttChartPrintExportOptions.Mode := emBoth;
PrintIO.GanttChartPrintExportOptions.TaskListColumns.Clear;
PrintIO.GanttChartPrintExportOptions.TaskListColumns.AddColumn('taskname', 'Task', 160, 120);
PrintIO.GanttChartPrintExportOptions.TaskListColumns.AddColumn('duration', 'Duration', 80, 60);
PrintIO.GanttChartPrintExportOptions.FitToPage := True;
PrintIO.GanttChartPrintExportOptions.RepeatHeaders := True;
PrintIO.Options.PageOrientation := TPrinterOrientation.poLandscape;
PrintIO.Print;
end;
void __fastcall TForm1::PrintChart()
{
PrintIO->GanttChart = TMSFNCGanttChart1;
PrintIO->GanttChartPrintExportOptions->Mode = emBoth;
PrintIO->GanttChartPrintExportOptions->TaskListColumns->Clear();
PrintIO->GanttChartPrintExportOptions->TaskListColumns->AddColumn("taskname", "Task", 160, 120);
PrintIO->GanttChartPrintExportOptions->TaskListColumns->AddColumn("duration", "Duration", 80, 60);
PrintIO->GanttChartPrintExportOptions->FitToPage = true;
PrintIO->GanttChartPrintExportOptions->RepeatHeaders = true;
PrintIO->Options->PageOrientation = TPrinterOrientation::poLandscape;
PrintIO->Print();
}
Composing into a larger report
For full control, the chart can render itself into your own canvas with
ExportView, or draw the task-list and timeline parts separately via
DrawExportTaskList and DrawExportTimeline — useful when composing a Gantt view
into a larger report.
Putting it together
Because both components share the option shape, one routine can drive the same layout to a PDF file and to the printer:
procedure TForm1.ExportAndPrint;
begin
{ Layout and column options, applied to the PDF exporter. }
PDFIO.GanttChart := TMSFNCGanttChart1;
PDFIO.GanttChartPDFExportOptions.Mode := emBoth;
PDFIO.GanttChartPDFExportOptions.TaskListColumns.Clear;
PDFIO.GanttChartPDFExportOptions.TaskListColumns.AddColumn('taskname', 'Task', 160, 120);
PDFIO.GanttChartPDFExportOptions.TaskListColumns.AddColumn('duration', 'Duration', 80, 60);
PDFIO.GanttChartPDFExportOptions.FitToPage := True;
{ PDF-specific settings. }
PDFIO.Options.PageOrientation := poLandscape;
PDFIO.Save('gantt-export.pdf');
{ Composing into a larger report: the same chart printed with matching options. }
PrintIO.GanttChart := TMSFNCGanttChart1;
PrintIO.GanttChartPrintExportOptions.Mode := emBoth;
PrintIO.GanttChartPrintExportOptions.FitToPage := True;
PrintIO.Options.PageOrientation := TPrinterOrientation.poLandscape;
PrintIO.Print;
end;
void __fastcall TForm1::ExportAndPrint()
{
// Layout and column options, applied to the PDF exporter.
PDFIO->GanttChart = TMSFNCGanttChart1;
PDFIO->GanttChartPDFExportOptions->Mode = emBoth;
PDFIO->GanttChartPDFExportOptions->TaskListColumns->Clear();
PDFIO->GanttChartPDFExportOptions->TaskListColumns->AddColumn("taskname", "Task", 160, 120);
PDFIO->GanttChartPDFExportOptions->TaskListColumns->AddColumn("duration", "Duration", 80, 60);
PDFIO->GanttChartPDFExportOptions->FitToPage = true;
// PDF-specific settings.
PDFIO->Options->PageOrientation = poLandscape;
PDFIO->Save("gantt-export.pdf");
// Composing into a larger report: the same chart printed with matching options.
PrintIO->GanttChart = TMSFNCGanttChart1;
PrintIO->GanttChartPrintExportOptions->Mode = emBoth;
PrintIO->GanttChartPrintExportOptions->FitToPage = true;
PrintIO->Options->PageOrientation = TPrinterOrientation::poLandscape;
PrintIO->Print();
}
See also
- Persisting tasks (JSON and CSV) — save the underlying data.
TTMSFNCGanttChartPDFIO·TTMSFNCGanttChartPrintIO