Printer.BeginDoc;
RVPrint.StartAt := 0;
RVPrint.TransparentBackground := True;
RVPrint.AssignSource(RichView1);
RVPrint.FormatPages(rvdoALL);
RVPrint.ContinuousPrint;
RVPrint.StartAt := RVPrint.EndAt;
{ // not necessary in the latest verison of TRichView
if RVPrint.rv.Height-RVPrint.StartAt<some safe value then
begin
Printer.NewPage;
RVPrint.StartAt := 0;
end;
}
RVPrint.AssignSource(RichView2);
RVPrint.FormatPages(rvdoALL);
RVPrint.ContinuousPrint;
Printer.EndDoc;
This code uses undocumented properties StartAt and EndAt. I think they are self explanatory. It also uses ContinuousPrint method. It's like Print method, but does not start and end a printing job.
Last edited by Sergey Tkachenko on Thu Oct 04, 2007 10:09 am, edited 2 times in total.
procedure PrintSomePages(const Title: String;
RVPrint: TRVPrint; const Pages: array of Integer);
var i: Integer;
begin
Printer.Title := Title;
Printer.BeginDoc;
for i := Low(Pages) to High(Pages) do begin
if i<>Low(Pages) then
Printer.NewPage;
RVPrint.DrawPage(Pages[i], Printer.Canvas,False);
end;
Printer.EndDoc;
end;
Update: in TRichView 17, new optional parameters were added in TRVPrint.PrintPages: PageSet and Ascending. They allow printing all/odd/even pages in normal and reverse directions. The code below still works, but is not needed any more.
procedure PrintOddOrEvenPages(const Title: String;
RVPrint: TRVPrint; Odd: Boolean);
var i: Integer;
begin
Printer.Title := Title;
Printer.BeginDoc;
for i := 1 to RVPrint.PagesCount do
if (Odd and (i mod 2=1)) or (not Odd and (i mod 2=0)) then begin
if i>2 then
Printer.NewPage;
RVPrint.DrawPage(i, Printer.Canvas,False);
end;
Printer.EndDoc;
end;
Updates:
2018-Apr-9: changes for compatibility with TRichView 17
Last edited by Sergey Tkachenko on Sat Aug 19, 2006 1:46 pm, edited 1 time in total.
Set RVPrint.TransparentBackground = True. Background color will not be painted.
Call RVPrint.rv.BackgroundBitmap := nil after calling RVPrint.AssignSource. Background bitmap will not be printed.
Assuming that you have 2 documents in 2 RVPrints, one formatted in portrait and one in landscape orientation, you can display preview with different orientations. RVPrintPreview displays only one page at once, so assing the proper RVPrint to RVPrintPreview.RVPrint property when moving to another page. You also need to assign the proper value to Printer.Orientation when switching pages.
I am working with 1 document, and with your suggestion to use 2 RVPrints, I succeeded in mixing portrait and landscape in the print preview.
The only problem I am having now however, is since the RichViewEdit box only allows a document to have an orientation, and not each page independantly, that all the pages have the same size (the same number of lines of text). I cannot detect pagenumbers correctly.
No, I have 1 TRichView and I am trying to get portrait and landscape orientation mixed on a page-to-page basis throughout the document. Similar to what you can do in a text editor like Word.