Solved

Print to File in C#

Posted on 2013-06-27
7
1,076 Views
Last Modified: 2013-07-09
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
0
Comment
Question by:Mr_Fulano
  • 3
  • 2
  • 2
7 Comments
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 39283282
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
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39283284
Try setting the PrintFileName property to your file name.

e.g.

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

Open in new window

0
 

Author Comment

by:Mr_Fulano
ID: 39287176
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?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39287193
Print to file prints Postscript files. It does not print text files. See: http://windows.microsoft.com/en-us/windows-vista/print-to-file
0
 

Author Comment

by:Mr_Fulano
ID: 39287199
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?
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 250 total points
ID: 39287233
Download the XPS viewer.
0
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 250 total points
ID: 39288694
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question