Pass a single parameter, a string containing the name of the print job. This name will appear in the print manager, if the documentation is to be believed:
Use Print to print the contents of a rich edit control. The Caption parameter specifies the title that appears in the print manager and on network title pages.
You also need to set PageRect
before printing. This defines the page dimensions on the printer. You need to query the device capabilities for the chosen printer, and apply any margins. I do that with this helper function:
procedure PrintRichEdit(RichEdit: TRichEdit; const Caption: string;
const PrinterMargin: Integer);
//the units of TRichEdit.PageRect are pixels, units of PrinterMargin are mm
var
PrinterHeight, PrinterWidth: Integer;
LogPixels, PrinterTopLeft: TPoint;
PageRect: TRect;
Handle: HDC;
begin
Handle := Printer.Handle;
LogPixels := Point(GetDeviceCaps(Handle, LOGPIXELSX),
GetDeviceCaps(Handle, LOGPIXELSY));
PrinterTopLeft := Point(GetDeviceCaps(Handle, PHYSICALOFFSETX),
GetDeviceCaps(Handle, PHYSICALOFFSETY));
PrinterWidth := Printer.PageWidth;
PrinterHeight := Printer.PageHeight;
PageRect.Left := Max(0, Round(PrinterMargin*LogPixels.X/25.4)
- PrinterTopLeft.X);
PageRect.Top := Max(0, Round(PrinterMargin*LogPixels.Y/25.4)
- PrinterTopLeft.Y);
PageRect.Right := PrinterWidth-PageRect.Left;
PageRect.Bottom := PrinterHeight-PageRect.Top;
if (PageRect.Left>=PageRect.Right) or (PageRect.Top>=PageRect.Bottom) then
//the margins are too big
PageRect := Rect(0, 0, 0, 0);
RichEdit.PageRect := PageRect;
RichEdit.Print(Caption);
end;