[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: 13388
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 » Thu Sep 08, 2005 7:40 pm

:?: 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: 13388
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Sep 08, 2005 7:42 pm

:?: 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: 13388
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Sep 08, 2005 7:45 pm

:?: 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: 13388
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Sep 08, 2005 7:47 pm

:?: 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.rv.DrawPage(Pages[i], Printer.Canvas,False,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?

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.rv.DrawPage(i, Printer.Canvas,False,False); 
    end; 
  Printer.EndDoc; 
end;
Last edited by Sergey Tkachenko on Sat Aug 19, 2006 1:46 pm, edited 1 time in total.

Sergey Tkachenko
Site Admin
Posts: 13388
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Sep 08, 2005 7:50 pm

:?: 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: 13388
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Sep 08, 2005 7:56 pm

:?: 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. » Tue Nov 08, 2005 4:09 pm

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: 13388
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Tue Nov 08, 2005 4:44 pm

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. » Wed Nov 09, 2005 8:22 am

Thanks for your help.
Now it works ! :D

YannickM
Posts: 5
Joined: Tue Jul 03, 2007 2:04 pm

Post by YannickM » Tue Jul 03, 2007 2:06 pm

Is there a way to have pages in different orientations in the print preview aswell ?

Sergey Tkachenko
Site Admin
Posts: 13388
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Tue Jul 03, 2007 3:28 pm

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 » Wed Jul 04, 2007 6:55 am

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: 13388
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Jul 05, 2007 1:56 pm

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 » Mon Jul 09, 2007 6:37 am

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: 13388
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Mon Jul 09, 2007 10:34 am

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

Post Reply