Board index » delphi » Print Canvas and Print Preview

Print Canvas and Print Preview

Hi, everyone:

I am new to delphi, so if I ask some stupid question, please forgive me:

I have a app to print out kinds of tables, I use lines as follows:

Printer.Canvas.Rectangle(x0, y0, x1, y1);
Printer.Canvas.Textout(....)

It work without any problem, but how can I use this canvas to make a
preview function? Can I  copy that Pinter.canvas to Form canvas or some
other kind of canvas in order I can see the print result before I print
it?

Would you please some detail code about it? Thanks a lot!

 

Re:Print Canvas and Print Preview


Joseph,
  It seems to me that you are putting the cart before the horse, so to
speak. I would think that it would make more sense to manipulate a canvas,
making whatever edits and or tables that you wish, and then send that to
the printer. Two things happen this way.. first you are not commiting
anything to the printer until such time as you have got exactly what you
want, and second, it affords you an oppurtunity to VIEW it prior to
printing. A simple way to do this would be to create an offscreen canvas
and use it as you are the printer canvas now...
                                        Good Luck!
                                                Dave

Joseph <jose...@ticketmaster.ca> wrote in article
<34C7E8EF.69453...@ticketmaster.ca>...

Quote
> Hi, everyone:

> I am new to delphi, so if I ask some stupid question, please forgive me:

> I have a app to print out kinds of tables, I use lines as follows:

> Printer.Canvas.Rectangle(x0, y0, x1, y1);
> Printer.Canvas.Textout(....)

> It work without any problem, but how can I use this canvas to make a
> preview function? Can I  copy that Pinter.canvas to Form canvas or some
> other kind of canvas in order I can see the print result before I print
> it?

> Would you please some detail code about it? Thanks a lot!

Re:Print Canvas and Print Preview


On 27 Jan 1998 10:05:47 GMT, "Dave Parsons" <dpars...@erols.com>
wrote:

Quote
>Joseph,
>  It seems to me that you are putting the cart before the horse, so to
>speak. I would think that it would make more sense to manipulate a canvas,
>making whatever edits and or tables that you wish, and then send that to
>the printer. Two things happen this way.. first you are not commiting
>anything to the printer until such time as you have got exactly what you
>want, and second, it affords you an oppurtunity to VIEW it prior to
>printing. A simple way to do this would be to create an offscreen canvas
>and use it as you are the printer canvas now...
>                                    Good Luck!
>                                            Dave

Here is what I done, and it works for me :-)

I used a Device Context in my printing routine (this DC can be
assigned to the printer, or any canvas) and all the graphic routines
were done using the windows GDI calls where the DC is passed as the
first parameter.

When outputting to the screen/printer the Y co-ordinate however is
inversed, so normally I have a variable called inverse and set it to
+0 or -0 and multiply every y co-ordinate by it, ie...

MoveTo(OutputDC,X,Y*Inversed);
LineTo(OutputDC,x+100,(Y+100)*inversed);

You can use origin stuff, but it confuses me a little, and found this
easiest to use.

Obviously when you preview it on screen, you might want to show it
smaller, so you should multiply all x and y co-ordinates by a scaling
factor... however, I did find the SETMAPMODE function very useful, to
set the co-ordinates to .01 mm per logical unit, for example

SetMapMode(OutputDC,MM_LOMETRIC);
MoveTo(OutputDC,100,100);

This moves you to 10cm x 10cm from the top left of the printer.

I think this is the information you are after.  Obviously your
DRAW_PAGE routine (or whatever you call it) should wither take a DC
parameter or a little if/case statment to assign the DC to the device
you want to output to and set the scaling factor and origin.

Need more info, or example?  Email me R...@LINUX.COMPD.COM

Other Threads