Solved

Printing 2 or more pages on 1

Posted on 2000-03-31
10
181 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

822 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