Solved

Printing 2 or more pages on 1

Posted on 2000-03-31
10
186 Views
Last Modified: 2013-11-22
I would like to know how to print a content of Memo or RichEdit and how to set printer layout to print two or more pages on one page in A4 format. If you could recomend me some good components that do this or some example I would be very greateful.
0
Comment
Question by:vanja_ninkovic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 2

Expert Comment

by:NetoMan
ID: 2673407
The easiest way for me is put this field in a Qreport form. From there you can set any page format you want.

0
 
LVL 4

Expert Comment

by:Radler
ID: 2674659
A little sample:
procedure TForm1.Button1Click(Sender:TObject);

var
  I, Start, Stop: Integer;
begin
PrintDialog1.Options := [poPageNums, poSelection];
PrintDialog1.FromPage := 1;
PrintDialog1.MinPage := 1;
PrintDialog1.ToPage := PageControl1.PageCount;
PrintDialog1.MaxPage := PageControl1.PageCount;
if PrintDialog1.Execute then
  begin
  { determine the range the user wants to print }
  with PrintDialog1 do
  begin
    if PrintRange = prAllPages then

      begin
      Start := MinPage - 1;
      Stop := MaxPage - 1;
      end
    else if PrintRange = prSelection then
      begin
      Start := PageControl1.ActivePage.PageIndex;
      Stop := Start;
      end
    else  { PrintRange = prPageNums }
      begin
      Start := FromPage - 1;
      Stop := ToPage - 1;
      end;
  end;
  { now, print the pages }
  with Printer do

    begin
    BeginDoc;
    for I := Start to Stop do
      begin
      PageControl1.Pages[I].PaintTo(Handle, 10, 10);
      if I <> Stop then
        NewPage;
      end;
    EndDoc;
    end;
  end;
end;

Notes : Adds Printers at Uses clause and put a PrintDialog component too

I avoid use Quickreport, because the function
ProgWorks( Codex, Delphi(x), QR(x))=True
ProgWorks( Codex, Delphi(x+1), QR(x+1))=BrainStorm;

T++, Radler.
0
 

Author Comment

by:vanja_ninkovic
ID: 2674889
Adjusted points from 100 to 150
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:vanja_ninkovic
ID: 2674890
I dont need printing of PageControl.pages. What I was refering to is that I have one TRichEdit on a form that has a lot of text in it, when I execute RichEdit.print it prints its content on 10 A4 papers, but most of the text is on right side of A4 papers and more then half of paper is blank.My question is how to put content of 2 or more A4 papers on one A4 paper, in that way user is using all available paper space and saves the paper.It is very important that the text in RichEdit is not changed, so if you have any solution please answer.I tried QMemo component of CBSuite collection and it choice of pagelayout was great but it is ShareWare and expencive for my budget.  
and yes I would really like to avoid using QReport.
0
 
LVL 4

Expert Comment

by:Radler
ID: 2680500
--------------------------
|             |              |
|   ____   |      ___   |
|   | 1 |    |     | 2 |   |
|   |---|    |     |---|   |
|             |              |
-------------------------
|             |              |
|   ____   |     ____  |
|   | 3 |    |     | 4 |   |
|   |---|    |     |---|   |
|             |               |
--------------------------

Suppossing like this, We'll have some invitables troubles, but if is your desire, Correct ?

0
 

Author Comment

by:vanja_ninkovic
ID: 2681887
Adjusted points from 150 to 250
0
 

Author Comment

by:vanja_ninkovic
ID: 2681888
Yes, that is exactly what I need. If you could help me with some example code that does that I would be very,very greateful. Also I will increase points for this question. Thanks once more for your efort.
0
 
LVL 4

Expert Comment

by:Radler
ID: 2682052
I'll try, wait for news tomorrow.
T++, Radler.
0
 
LVL 2

Accepted Solution

by:
mullet_attack earned 250 total points
ID: 2686057
Below is a unit that sub-classes TRichedit to print in two columns on A4
by overriding the Print method.

It is quick and dirty, tidy up by adding a NumColumns property for example

Small issue , the left column wraps, but the right hand doesn't. Shouldn't be too hard to fix.

unit RicheditCols;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, Richedit, printers;

type
  TRicheditCols = class(trichedit)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    procedure Print(const Caption: string); override;
  published
    { Published declarations }
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Samples', [TRicheditCols]);
end;


procedure TRicheditCols.Print(const Caption: string);
var
  Range: TFormatRange;
  LastChar, MaxLen, LogX, LogY, OldMap: Integer;
  SaveRect: TRect;
  LeftHalf : boolean;
  L, M, R : integer; // left , middle and right edges
begin
  FillChar(Range, SizeOf(TFormatRange), 0);
  with Printer, Range do
  begin
    Title := Caption;
    BeginDoc;
    hdc := Handle;
    hdcTarget := hdc;
    LogX := GetDeviceCaps(Handle, LOGPIXELSX);
    LogY := GetDeviceCaps(Handle, LOGPIXELSY);
    if IsRectEmpty(PageRect) then
    begin
      rc.right := PageWidth * 1440 div LogX;
      rc.bottom := PageHeight * 1440 div LogY;
      l := rc.left;
      m := rc.right div 2;
      r := rc.right;
    end
    else begin
      rc.left := PageRect.Left * 1440 div LogX;
      rc.top := PageRect.Top * 1440 div LogY;
      rc.right := (PageRect.Right * 1440 div LogX);
      rc.bottom := PageRect.Bottom * 1440 div LogY;
      l := rc.left;
      m := rc.right div 2;
      r := rc.right;
    end;
    LeftHalf := true;
    rc.left := l;
    rc.right := m;

    rcPage := rc;
    SaveRect := rc;
    LastChar := 0;
    MaxLen := GetTextLen;
    chrg.cpMax := -1;

    // ensure printer DC is in text map mode
    OldMap := SetMapMode(hdc, MM_TEXT);
    SendMessage(Self.Handle, EM_FORMATRANGE, 0, 0);    // flush buffer
    try
      repeat
        rc := SaveRect;
        chrg.cpMin := LastChar;
        LastChar := SendMessage(Self.Handle, EM_FORMATRANGE, 1, Longint(@Range));
        if (LastChar < MaxLen) and (LastChar <> -1) then
          if Lefthalf then
            begin
              rc.left := m;
              rc.right := r * 2;
              lefthalf := false;
              SaveRect := rc;
            end
          else
            begin
              rc.left := l;
              rc.right := m;
              lefthalf := true;
              SaveRect := rc;
              NewPage; //only if we just printed the right-hand half
            end;

      until (LastChar >= MaxLen) or (LastChar = -1);
      EndDoc;
    finally
      SendMessage(Self.Handle, EM_FORMATRANGE, 0, 0);  // flush buffer
      SetMapMode(hdc, OldMap);       // restore previous map mode
    end;
  end;
end;

end.
0
 

Author Comment

by:vanja_ninkovic
ID: 2688121
This is the basic that I need. With a little coding and a little repairs I think this will do the trick. I will accept this answer. Thank you for this good peace of code, and also I want to thank you for your time and efort.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question