Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Print to File in C#

Posted on 2013-06-27
7
Medium Priority
?
1,284 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 30

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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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 1000 total points
ID: 39287233
Download the XPS viewer.
0
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 1000 total points
ID: 39288694
0

Featured Post

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

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

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

722 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