Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create a custom print preview contol like thing in which I shall change the print document and want to see the dynamicaly rendered image of the document i.e. changed document that will be printed if sent to printer.
But I donot have any idea about how to render the document to image list (1 image/page).

I have searched for ready made solutions & found this.

http://stackoverflow.com/questions/10868623/converting-print-page-graphics-to-bitmap-c-sharp

Thanks in advance.

What I have tried:

Nothing special. I have no idea how to render printdocument object to bitmap :(
Posted
Updated 19-Oct-16 2:24am

1 solution

Its actually quite simple to do. Your "Print" routines have a Graphics object that you normally print to. When sending the output to the printer, this Graphics object is created from the printer's device context - thus sending the output to the printer.

If you create a bitmap with a white background and the same size as your printer page, you can then create a Graphics object from that bitmap. If you pass that Graphics object to the print routines, then they will print onto your bitmap instead of the printer. Create a new bitmap for each printer page, resize them to fit into your preview window, and there you go - all done.
 
Share this answer
 
Comments
Rajib13 19-Oct-16 8:39am    
Midi_Mick I am not realy a pro in c#, so would you please be able to write a tiny snippet inside a method createBMP(PrintDocument doc) method that takes the print document (that I send to printer) and returns a bmp list.
Sorry if I am asking for something more than enough. :) Thank you in advance.
Midi_Mick 19-Oct-16 8:49am    
Not really - a bit too much work involved. However, a quick search of CP for "PrintDocument" gave me these 2 pages (plus more) that have all the info you need to do this:
http://www.codeproject.com/Articles/16720/Basic-Text-and-Image-Printing
http://www.codeproject.com/Articles/9907/Output-graphics-files-using-your-printing-code
Rajib13 19-Oct-16 9:02am    
Thanks. Let me check these & I will accept your answer. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900