Link to home
Start Free TrialLog in
Avatar of Mr_Fulano
Mr_FulanoFlag for United States of America

asked on

Print to File in C#

Hi, I'm using C#.NET 2010. I am using the PrintDialog Object and would like to print to a file rather than to the printer. When I select the "Print to File" checkbox, I can't find where it's creating the new file. Where does the Print to File option go?

I have it printing to the printer, but am struggling with "print to file" part.

I only have an option to give the file a name not to select a path. How can I select the path?

An example would be very helpful.

Thank you,
Fulano
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

You need to set thepath:

        printD.PrinterSettings.PrintToFile = true;
        printD.PrinterSettings.PrintFileName = @"c:\temp\test.txt";

See the solution here:

http://stackoverflow.com/questions/9675494/vb-net-printdialog-print-to-file
Try setting the PrintFileName property to your file name.

e.g.

printDialog1.PrinterSettings.PrintFileName = @"C:\Users\Kenneth\Desktop\test.ps";

Open in new window

Avatar of Mr_Fulano

ASKER

I was able to get it to print to a file, but the text comes out garbled. It seems you need to have a printer set up that allows for plain text printing and even that does not produce an exact representation of you original file.

Any thoughts on that?
Print to file prints Postscript files. It does not print text files. See: http://windows.microsoft.com/en-us/windows-vista/print-to-file
Hi Kaufmed, I understand that now after a lot of struggling with the file. The print to file produces an XPS file format. So, the magic questions become, how do you read that and how you print that?

It does me no good to have a file version of my document that I cannot read or print.

I tried MS Word, MS WordPad, Adobe Reader X, Internet Explorer,  and of course NotePad. but none of those will work. So, what is the magic application that Microsoft uses for this?
SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial