Solved

RichEdit printing customization

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

910 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

24 Experts available now in Live!

Get 1:1 Help Now