Solved

RichEdit printing customization

Posted on 1998-05-21
4
317 Views
Last Modified: 2013-11-22
Source code sample needed:

Can anyone point me to a sorce code sample which demonstrates how to customize the RichEdit printing to add my own headers and footers to it?

Thanks,
Sanjay
0
Comment
Question by:skanade
  • 2
4 Comments
 

Expert Comment

by:jhunt
ID: 1347245
Why don't you use Quickreport to print your RichEdit. It very flexible and the only limiet is your imagination !

John
0
 
LVL 1

Accepted Solution

by:
ssite earned 100 total points
ID: 1347246
The idea and solution is simple. I hope you have some basic experience in component writing,
In the vcl source directory you'll find a file called comctrls.pas. look for a function :
TCustomRichEdit.Print

This is the one that does the printing.

What I would do is use the PageRect property of the TRichEdit to set it to the area which you want to let the richedit print its normal printing, and then you have some blank space for you.

To print on this blank space, you need to add a simple call to a function or event that passes on the canvas for the printer, and then you can do what you need.

Here's the function. Create a new component derived from TRichEdit, add a new event and a new function called PrintCustom. Use the code from Print and add the call to the event like I did here (in 2 places) :

procedure TCustomRichEdit.Print(const Caption: string);
var
  Range: TFormatRange;
  LastChar, MaxLen, LogX, LogY, OldMap: Integer;
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;
    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;
    end;
    rcPage := rc;
    LastChar := 0;
    MaxLen := GetTextLen;
    chrg.cpMax := -1;
    // ensure printer DC is in text map mode
    OldMap := SetMapMode(hdc, MM_TEXT);
    SendMessage(Handle, EM_FORMATRANGE, 0, 0);    // flush buffer
    try
      // call you r event here (first page)
      MyPrintEvent(Canvas); // the canvas is Printer.Canvas
      repeat
        chrg.cpMin := LastChar;
        LastChar := SendMessage(Self.Handle, EM_FORMATRANGE, 1, Longint(@Range));
        if (LastChar < MaxLen) and (LastChar <> -1) then
        begin
          NewPage;
          // now for the new page
          MyPrintEvent(Canvas); // the canvas is Printer.Canvas
       end;
      until (LastChar >= MaxLen) or (LastChar = -1);
      EndDoc;
    finally
      SendMessage(Handle, EM_FORMATRANGE, 0, 0);  // flush buffer
      SetMapMode(hdc, OldMap);       // restore previous map mode
    end;
  end;
end;


Hope it helps.

0
 

Author Comment

by:skanade
ID: 1347247
John,

>>Why don't you use Quickreport to print your RichEdit.

Thanks! I thought QuickReport is only useful for databases and not for individual controls. I tried it but it doesn't work and the online help is hopelessly poor and missing for QRRichEdit component altogether. I tried putting the QRRichEdit on a detail band and connecting it to my RichEdit but it doesn't work. I tried it by itself without a band but it doesn't print full. Then I tried AutoStrech and it gives a GPF. Is there any better document somewhere?

Sanjay
0
 

Author Comment

by:skanade
ID: 1347248
ssite,

Thanks! This is exactly what I needed.

Sanjay
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

786 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