Solved

RichEdit printing customization

Posted on 1998-05-21
4
313 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Master Detail with TADODataset 4 96
Firewall issues 6 85
delphi exception 7 58
Delphi Dbf export problem to a Visual Foxpro application 6 122
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now