Solved

Print to File in C#

Posted on 2013-06-27
7
1,013 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
Comment Utility
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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
Comment Utility
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 74

Assisted Solution

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

Accepted Solution

by:
anarki_jimbel earned 250 total points
Comment Utility
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual Studio installation 5 32
Problem to picture file 3 37
C# SQL BULK INSERT CLASS 5 33
Change data in datatable 8 14
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now