VB 2010 Print to File
-
Tuesday, August 07, 2012 4:27 PM
I have an application that creates a complex print document. A user recently clicked
Print to File and it didn't. So, I need some clue how to do this. I'm assuming that within
my print routine I need to test PrintDialog.PrintToFile and either send it to the printer
or open a standard File Open Dialog Box to get a file name to print to. My question is
do I then do mydoc=m_PrintDocument.ToString() and use Write statements to output
to a file? Or is there a better way to do it?
All Replies
-
Tuesday, August 07, 2012 5:19 PM
You shouldn't have to do anything. The OS should prompt for a filename when PrintDocument.Print is called.- Marked As Answer by OLD_Dog_771 Tuesday, August 07, 2012 7:01 PM
-
Tuesday, August 07, 2012 7:01 PM
John,
After some testing, your answer is correct. Thank you.
However, I think I have a better way given the group of users I'm dealing with
who wouldn't know what to do with a box asking for a file name.
If I install Microsofts XPS Document Writer on their machines and set
dlgPrint.AllowPrintToFile = FALSE so they can't check it,
and tell them to select the Microsoft XPS Document Writer as the
printer, that opens a standard File Open Dialog and the resulting
file can be viewed as it prints in Explorer. It also works with
Microsoft Office Document Image Writer the same way. (It didn't
-
Tuesday, August 07, 2012 7:57 PMYou could let them check it and then detect that it has been checked when the PrintDialog closes. You would then select the XPS writer as the printer. This still shows a dialog asking for a filename, but the dialog is more common and can be navigated with the mouse.

