Printing in C#

  • Thread starter Thread starter ywchan
  • Start date Start date
Y

ywchan

Hi, all
I have the following questions about printing in C#

1. How to print a document (e.g. MS Word, Excel, PDF) through C#? I have use
PrintDocument and set the DocumentName to the file path (e.g.
@"C:\Test.doc"). But I can't print out the content in the document...Why?
So how can it print the document?

2. How to convert a document to raw print file (i.e. the same output as
"print to file") by using C# code? Any idea / any classes I can use?

3. How to convert a document to pdf file by using C#?

Thanks.
 
1. To print a office document, you need office to first interpret the file.
Use the Word, Excel, etc.. api, and call PrintDocument from that office
object model. When you do this you must also have a default print device
setup.

2. To print to a raw print file (binary) simply call the PrintDocument
method from the office object model of your choice, one of the parameters is
PrintToFile, flag this as true (box true as a object) and then specify the
file name. Note: You still MUST have a default print device, because RAW is
only as RAW as it's destination format. If you have an HP in PS mode it
won't look good on a PLC Epson.

3. To convert a office document to pdf, you can use Crystal Reports to
import the doc an then save it as pdf. Which I wouldn't suggest. The most
straight forward way I guess would be to use ActivePDF @ ActivePDF.com, they
have a great object for a couple hundred bucks will do the conversion of
your documents quickly.

Hope this helps.

Nick Harris, MCP, CNA, MCSD
Director of Software Services
http://www.VizSoft.net
 
Back
Top