Page 1 of 1

[How to] How to print 2 documents in one printing job, etc.

Posted: Thu Sep 08, 2005 7:40 pm
by Sergey Tkachenko
:?: How to print more than one document in one printing job?
:?: How to print two documents on one page?

Code: Select all

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.

Posted: Thu Sep 08, 2005 7:42 pm
by Sergey Tkachenko
:?: How to change paper orientation?

Change Printer.Orientation to poLandscape (or poPortrait) before calling RVPrint.FormatPages.

(Printer is defined in the Printers unit)

Posted: Thu Sep 08, 2005 7:45 pm
by Sergey Tkachenko
:?: How to mix portrait and landscape orientation?

You need to separate your document in two (or more) parts - one with portrait orientation, and one with landscape orientation.

Code: Select all

Printer.BeginDoc;
Printer.Orientation := ...;
RVPrint1.ContinuousPrint;
Printer.NewPage;
Printer.Orientation := ...;
RVPrint2.ContinuousPrint;
Printer.EndDoc;

Posted: Thu Sep 08, 2005 7:47 pm
by Sergey Tkachenko
:?: How to print the chosen pages, for example 1, 3, 4, 5, 23?

Code: Select all

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;
Test:

Code: Select all

PrintSomePages('Test', RVPrint1, [1, 3, 4, 5, 23]);
:?: How to print only odd or even pages?

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.

Code: Select all

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

Posted: Thu Sep 08, 2005 7:50 pm
by Sergey Tkachenko
:?: How to print without background?

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.

Posted: Thu Sep 08, 2005 7:56 pm
by Sergey Tkachenko
:?: How to print the selected fragment

There are no functions for printing the selection.
The only way to do it is to copy it to the separate (hidden) RichView and to print it.

Code: Select all

var Stream: TMemoryStream;
// copying the selection
Stream := TMemoryStream.Create;
try
  rvSource.SaveRVFToStream(Stream, True);
  Stream.Position := 0;
  rvHidden.LoadRVFFromStream(Stream);
finally
  Stream.Free;
end;
// printing
RVPrint1.AssignSource(RVHidden);
RVPrint1.FormatPages(rvdoAll);
RVPrint1.Print('Selection', 1, False);

Posted: Tue Nov 08, 2005 4:09 pm
by Benoit B.
Sergey Tkachenko wrote::?: How to mix portrait and landscape orientation?

You need to separate your document in two (or more) parts - one with portrait orientation, and one with landscape orientation.

Code: Select all

Printer.BeginDoc;
Printer.Orientation := ...;
RVPrint1.ContinuousPrint;
Printer.NewPage;
Printer.Orientation := ...;
RVPrint2.ContinuousPrint;
Printer.EndDoc;

How to do that with Borland C++ Builder 6 please ?

Posted: Tue Nov 08, 2005 4:44 pm
by Sergey Tkachenko
Almost exactly the same:

Code: Select all

Printer()->BeginDoc(); 
Printer()->Orientation = ...; 
RVPrint1->ContinuousPrint(); 
Printer()->NewPage(); 
Printer()->Orientation = ...; 
RVPrint2->ContinuousPrint(); 
Printer()->EndDoc();
where poPortrait or poLandscape must be used instead of ...

The code above assumes that RVPrint1 and RVPrint2 were already formatted (in the proper page orientation).
If not, the full code will be:

Code: Select all

Printer()->BeginDoc(); 
Printer()->Orientation = ...; 
RVPrint1->FormatPages(TRVDisplayOptions());
RVPrint1->ContinuousPrint(); 
Printer()->NewPage(); 
Printer()->Orientation = ...; 
RVPrint2->FormatPages(TRVDisplayOptions());
RVPrint2->ContinuousPrint(); 
Printer()->EndDoc();

Posted: Wed Nov 09, 2005 8:22 am
by Benoit B.
Thanks for your help.
Now it works ! :D

Posted: Tue Jul 03, 2007 2:06 pm
by YannickM
Is there a way to have pages in different orientations in the print preview aswell ?

Posted: Tue Jul 03, 2007 3:28 pm
by Sergey Tkachenko
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.

Posted: Wed Jul 04, 2007 6:55 am
by YannickM
Thanks for the quick response.

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.

Any ideas ?

Posted: Thu Jul 05, 2007 1:56 pm
by Sergey Tkachenko
Sorry, I do not understand your question.
Do you format 2 different TRichViews, one in portrait and one in landscape orientation?

Posted: Mon Jul 09, 2007 6:37 am
by YannickM
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.

Is this even possible ?

Posted: Mon Jul 09, 2007 10:34 am
by Sergey Tkachenko
No, I suggest to format parts of documents having different orientation in different RichViews