Board index » delphi » Printing mixed text and graphics

Printing mixed text and graphics

A question for printing experts:-

Does anyone know if there's there a way of mixing *fast* text printing
and graphics on the same page, as most word processors seem to be able
to do?

You can print text fast with, for example:-

    var
      PrintText: TextFile;
    ........
    AssignPrn(PrintText);  
    Rewrite(PrintText);    
    Writeln(PrintText, <text string>);
    CloseFile(PrintText);

or graphics with:-

   with Printer do
     begin
       BeginDoc;
      <do pretty things on Printer.Canvas>;
       EndDoc;
     end;

Obviously you can mix text with graphics by writing text to the canvas
in the second example, but this then prints it *as* graphics - i.e.
slowly.  What I'd like is a way of printing text fast, then graphics, on
one page.  As it is, you can't mix the above two methods without
exceptions occurring everywhere, and both CloseFile(PrintText) and
EndDoc send a form feed to the printer. Any other ideas?

One other possible approach:  you can also print text fast using the
Print method of TRichText, the Rich text memo. I noticed someone else in
this NG has asked how to put graphics into TRichText (so far
unanswered). I've been trying to do that too, with no luck so far.

Any ideas received gratefully.

----------------
Chris Bazalgette

 

Re:Printing mixed text and graphics


Im Artikel <4AnEiEAmYzx0E...@cbaz.demon.co.uk>, Christopher Bazalgette
<ch...@cbaz.demon.co.uk> schreibt:

Quote
>sible ap

I'm printing a picture with a RichText formular. The picture is not included in
the RTF document.

I'm using the RichText example in '..\borland\delphi 2.0\demos\richedit\..'
directory.

In the unit REMain I use the procedure TMainForm.FilePrint

procedure TMainForm.FilePrint(Sender: TObject);
begin
  if PrintDialog.Execute then
    RichEdit1.Print(FFileName);  //<- I replaced this line with the procedure
TCustomRichEdit.Print in unit ComCtrls
end;

I replaced 'Caption' with 'FFileName' .

In the section
      ...
      try
        repeat
          chrg.cpMin := LastChar;
          LastChar := SendMessage(RichEdit.Handle, EM_FORMATRANGE, 1,
Longint(@Range));

          // <-  here I inserted my printing method

          if (LastChar < MaxLen) and (LastChar <> -1)
          then begin
               NewPage;
               Inc (Pages);
               end;
        until (LastChar >= MaxLen) or (LastChar = -1);
        EndDoc;
      finally
        SendMessage(RichEdit.Handle, EM_FORMATRANGE, 0, 0);  // flush buffer
        SetMapMode(hdc, OldMap);       // restore previous map mode
      end;
    ...

I inserted a printing method with the final call

Printer.Canvas.StretchDraw(ImgRect, Picture.Graphic);

If you don't want to print your Image on every page you can restrict it by
using 'Pages' variable.
This solution is probably not very elegant, but it works. I don't know if the
text printing is faster. I didn't tryed it out.

By using RichEdit I still have the problem to wrap the text around the picture.
I already asked in comp.lang.pascal.delphi.components.misc if anyone have an
idea to get the position of text.

Hope it helps you.

   Rick

Other Threads