Click to See Complete Forum and Search --> : Print to file


chen1207
August 23rd, 2001, 09:36 PM
How can i print to a specified file in VB?
Although i can see "print to file" checkbox in CommonDialog (showPrint) Controls, when i check it, it is not available.
How Can i do ?

Iouri
August 24th, 2001, 07:25 AM
What do you need to send to the file. If it is a text then

Open "c:\temp\temp.txt" For Output As #1 'to write to
Print #1, StringToPrint
Close #1

otherwise you can open a file in a binary mode and print to it

Iouri Boutchkine
iouri@hotsheet.com

chen1207
August 24th, 2001, 08:42 PM
Thanks for your help.
your answer is really available and simple, but i have to write a procedure to read this file and send it to printer ,and where the shoe pinches is i dont know the format and content i am going to print at all.
Actually, i am anxious to know how can i make a general *.prn file in VB, so I can directly print a *.prn file with Win32 API as follows:

OpenPrinter
StartDocPrinter
StartPagePrinter
' Open file and pump it to the printer.
WritePrinter
EndPagePrinter
EndDocPrinter
ClosePrinter

The problem may be described as how to use these above functions to access the print spooler to construct a general *.prn file?

i know a API function ReadPrinter which can retrieve data from the specified printer, but i don't know when to use this function, how to avoid transfer data in print spooler to a actual print, and so on.

i am in Beijing,China. my english is very poor, please forgive me for the mistakes in my message.

Kind regards,

G. Chen