Print Preview in SWT [message #375450] |
Wed, 15 October 2003 08:46 |
Eclipse User |
|
|
|
Originally posted by: v.choudhary.zensar.com
Hi Guys,
Can anyone tell me whether it is possible to implement print preview in
SWT ??
If yes, if someone can provide me some code snippet it will be very useful.
Thanks,
Vinay
|
|
|
Re: Print Preview in SWT [message #375462 is a reply to message #375450] |
Wed, 15 October 2003 18:21 |
Carolyn MacLeod Messages: 149 Registered: July 2009 |
Senior Member |
|
|
Yes, it's possible. And if you have already implemented "print" in your
application, it's not going to be too hard to add print preview. (If you
haven't yet implemented your "print" feature, then there is a lot of work to
do). What you want to do is make your "print" method take 2 arguments: a
Device and a GC. When you are printing, pass in the Printer device and a GC
that was created for printing. When you are doing a "print preview", pass in
the Display device and a GC for drawing on your "print preview" canvas. Make
sure to create all colors, fonts, and images using the correct device (and
make sure to dispose them when done). You will have to think about margins,
page breaks, and scaling, and you may want to think about whether or not the
chosen fonts exist on the printer. For an optimization, you might want to
use a set of background images, one per page, for the display drawing so
that your user can flip between the 'pages' without you having to render
them again.
Printing is a lot of work. The widgets don't do it for you - you have to do
all the drawing yourself. Once you have done the work, however, it is a
relatively simple thing to add a "print preview" feature.
The closest thing in SWT to an example of this is the StyledText widget -
have a look at the code in org.eclipse.swt.custom.StyledText. It doesn't do
a print preview specifically, but it does know how to draw itself to the
screen, and to print itself to a printer. Print preview would just be a bit
of a twist on drawing to the screen.
Good luck,
Carolyn
"Vinay Choudhary" <v.choudhary@zensar.com> wrote in message
news:bmj1hi$is9$1@eclipse.org...
> Hi Guys,
>
> Can anyone tell me whether it is possible to implement print preview in
> SWT ??
> If yes, if someone can provide me some code snippet it will be very
useful.
>
> Thanks,
> Vinay
>
|
|
|
Powered by
FUDForum. Page generated in 0.02929 seconds