TeeTree includes comprehensive printing support with multi-page capability, print preview, page borders, and full printer integration. The TTreePage class manages page layout and dimensions.
Printing features are built into the core TeeTree.pas unit. The TreeEd.pas editor provides a complete print preview implementation.
with Tree1.Page dobegin // Go to specific page Page := 1; // First page // Navigate pages if Page < Count then Page := Page + 1; // Next page if Page > 1 then Page := Page - 1; // Previous page // Refresh page layout Refresh;end;
with Tree1 dobegin // Use printer page size Page.UsePrinter := True; // Show page borders during design Page.Border.Visible := True; Page.Border.Print := False; // Don't print borders // Tree will automatically calculate page count // based on node positions and page sizeend;
2
Calculate Page Bounds
The tree automatically calculates pages:
procedure CalculatePageBounds; // From TeeTree.pasvar tmpBounds: TRect; PageWidth, PageHeight: Integer;begin tmpBounds := GetNodesRect; // Get bounds of all nodes if Page.UsePrinter then begin PageWidth := Printer.PageWidth; PageHeight := Printer.PageHeight; end else begin PageWidth := Page.Width; PageHeight := Page.Height; end; // Calculate number of pages needed Page.FCount := CalculatePageCount(tmpBounds, PageWidth, PageHeight);end;
3
Print All Pages
Print entire multi-page tree:
procedure PrintAllPages;var i: Integer;begin for i := 1 to Tree1.Page.Count do begin Tree1.Page.Page := i; Tree1.Print; // Print current page end; // Reset to first page Tree1.Page.Page := 1;end;
uses Printers;procedure ConfigurePrinter;begin with Printer do begin // Set orientation Orientation := poLandscape; // or poPortrait // Get page dimensions (in device units) ShowMessage(Format( 'Page size: %d x %d pixels', [PageWidth, PageHeight] )); // Select printer if PrintDialog1.Execute then begin PrinterIndex := PrintDialog1.PrinterIndex; end; end;end;
The editor includes a page navigation control:From TreeEd.pas (line 1071):
PageNavigatorClass := TTreePageNavigator;
You can use the navigator in your own preview:
var Navigator: TTreePageNavigator;begin Navigator := TTreePageNavigator.Create(Self); Navigator.Parent := Panel1; Navigator.Tree := Tree1; // User can now navigate pages with navigator buttonsend;
procedure TTeeScrollBar.SetPageSize(Value: Integer);begin if FPageSize <> Value then begin FPageSize := Value; // Update scrollbar page size for smoother scrolling ScrollInfo.nPage := Value; end;end;
procedure TForm1.Tree1AfterDraw(Sender: TObject);begin if Tree1.Printing then begin // Skip drawing interactive elements when printing Exit; end; // Draw selection handles, etc. (screen only) DrawSelectionHandles;end;
From TeeTree.pas (line 10608):
if Selected and (not Tree.Printing) thenbegin // Don't draw selection handles when printingend;
procedure TForm1.ButtonPrintClick(Sender: TObject);begin if PrintDialog1.Execute then begin // User confirmed print settings Tree1.Print; end;end;
procedure TForm1.ButtonPageSetupClick(Sender: TObject);begin if PageSetupDialog1.Execute then begin // User changed margins, orientation, etc. Tree1.Page.Refresh; Tree1.Invalidate; end;end;
procedure TForm1.PrintWithProgress;var i: Integer;begin ProgressBar1.Max := Tree1.Page.Count; ProgressBar1.Position := 0; Printer.BeginDoc; try for i := 1 to Tree1.Page.Count do begin Tree1.Page.Page := i; Tree1.Print; // Print current page ProgressBar1.Position := i; Application.ProcessMessages; if i < Tree1.Page.Count then Printer.NewPage; end; finally Printer.EndDoc; Tree1.Page.Page := 1; end;end;