views:

324

answers:

1

I've searched Stackoverflow and google and found many ways how I can print stuff in C#.

The best way for me would be to populate blank white windows form with some label, textbox and picturebox elements and print it as a windows form. This way is very poor because it prints in 72 DPI, and is not flexible for multiple pages print.

Next way that I found that would be good is using iTextSharp, but there is a problem that iTextSharp only generates PDF-s, and you have to open it in PDF viewer and print from there.

I love this way of thinking where I create a paragraph, and then fill it with text and graphic, so I found this thread http://www.devarticles.com/c/a/C-Sharp/Printing-Using-C-sharp/ where it discusses how to create your own printing engine in C#, something like iTextSharp, but very lightweight...

Now that I've said that, I want to know is there any ready to use printing engine that would be like iTextSharp, made for printing, not for PDF generation? What is the best way to print something, without using reporting services like CrystalReports.

I think Crystal Reports wouldn't work for my case cause I don't want to print generic reports, but some text and graphics that I need to dynamicaly generate every time I need to print.

+1  A: 

I found that it was much easier to do printing using the printing stuff in WPF.

EDIT
XPS is the page description format that Microsoft included into .NET with .NET 3.0. It is nominally part of WPF, and is integrated with the WPF form layout model. But you can create XPS documents in memory and send them to printers, from any .NET app, including a WinForms App.

An example: http://statestreetgang.net/post/2008/03/Creating-an-XPS-document-in-memory-via-the-DOM.aspx

It is approximately equivalent to the iTextSharp capability you explored, except:

  • you can do it all in memory if you like, no need to save to a filesystem file. Of course if you want to save to a filesystem file, you can do that too.
  • you don't need an external viewer in order to start the print.
Cheeso
I am using WinForms for my app. Can I combine the two? I've never worked in WPF
Hybryd
yes. You can create an XPS document from a WinForms app.
Cheeso
Can you give me any direction where to start from?
Hybryd
ya, I updated the answer with some additional info.
Cheeso
Thank you very much! I will look into it
Hybryd