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

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post 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.
Last edited by Sergey Tkachenko on Thu Oct 04, 2007 10:09 am, edited 2 times in total.
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
Last edited by Sergey Tkachenko on Thu Sep 08, 2005 7:48 pm, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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;
Last edited by Sergey Tkachenko on Thu Sep 08, 2005 7:48 pm, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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
Last edited by Sergey Tkachenko on Sat Aug 19, 2006 1:46 pm, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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);
Benoit B.

Post 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 ?
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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();
Benoit B.

Post by Benoit B. »

Thanks for your help.
Now it works ! :D
YannickM
Posts: 5
Joined: Tue Jul 03, 2007 2:04 pm

Post by YannickM »

Is there a way to have pages in different orientations in the print preview aswell ?
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
YannickM
Posts: 5
Joined: Tue Jul 03, 2007 2:04 pm

Post 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 ?
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, I do not understand your question.
Do you format 2 different TRichViews, one in portrait and one in landscape orientation?
YannickM
Posts: 5
Joined: Tue Jul 03, 2007 2:04 pm

Post 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 ?
Sergey Tkachenko
Site Admin
Posts: 17521
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

No, I suggest to format parts of documents having different orientation in different RichViews
Post Reply