You could install the Generic Text Only printer driver, and set it to print to File, or set whatever printer driver you want to generate output for to print to File instead of to the printer. It might help if we knew exactly what you want to accomplish with this.
You go into PRINTERS and SETTINGS - go into the properties of the printer...
Under the PORTS tab you will see FILE: as a port. If you select FILE: then output directed at that printer will go to a file - you will get a dialog box asking for a file name and you will get a .PRN file for output. The print driver associated with that printer will "make" the .PRN file - so it's not going to be a universal file - but rather one associated with that specific printer and driver.
I would imagine you could set the "FILE:" association with an API call - I've never seen it exposed as a PRINTER object property in VB - but I could be wrong.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Actually I am creating an application which has a functionality for Printing Reports. This I am doing using the Printer object of VB. The printed reports show Page Headers (which includes Page Number also).
Now, one more functionality that I need to put into this application is 'Print to File' which print the report to a '.prt' file on the system. I was wondering if we can do this with the same Printer object which can save me some time.
This something very much like what 'szlamany' has stated. However when I try printing a normal .txt file in my system after setting the PORT as FILE: it creates a file but with some wierd contents ....
Also, with the FileSystemObjects I don't know how to insert a Page Break and check for beginning of a page to put a header.
Hope I am able to state my problem better this time.
Waiting for your help...
Thanks
Dex
Last edited by DexySeeksHelp; Oct 19th, 2005 at 11:27 PM.
I copied and made a slight addition to this example from the API Guide. My change is noted and it allows you to tell if Print To File is selected. Note that it does not use the CommonDialog control. You won't need 90% of it but I'll leave that up to you.
If what you want is a straight text file that has the report contents, you may need to use the Generic Text Only printer driver. If you use a driver for another printer, say an HP for example, you may find that you also get printer control strings embedded in the file for that printer. That may be what the "weird contents" that you were referring to consist of. Remember that sending a file to the Generic Text Only printer driver will just output the text. If you are using any formatting, like bold fonts or different font sizes or colors, none of that will appear in the file.
I'm confused as to why you are using the FSO (filesystemobject) to create a file.
You must use the PRINTER object to produce output - either to a printer or to a file (to a file by selecting FILE: as the PORT, or using what MARTINLISS posted - I'm assuming that will select FILE: as the PORT for a PRINTER object).
The GENERIC TEXT ONLY driver is just another printer driver - but one that removes formatting so that only the TEXT is in the file.
But it still isn't a .TXT (notepad-like) file.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
But my problem still lies unresolved. I can't compromise on the formatting applied in the report file and in fact the output needs to be generated as a '.prt' file.
I looked tonight, and couldn't find a generic printer in XP Home. You have to pick a printer off a list, or use an installation disk. It's not the same as it was a few years ago. I wonder if SP2 had anything to do with it. I thought I did it with XP, but it may have been W2K.
I guess I am not able to make a way out of this problem of printing to file.
And friends I badly need your help on this.
I want to use the Printer object to print the contents of a report to a '.prt' file directly. My concerns are also to maintain a partcular font-size and style too.
So I'll highly thankful if someone can suggest as to how can I execute this print to file option.
I think several of us have already told you that the method to use is:
1) Change the PRINTER to PRINT TO FILE
2) Select that PRINTER from VB
3) You will get a dialog box asking for a file name
4) This will create a .PRN file - which is a PRINT FILE associated with that printer
That is the really important part. You are using the PRINT DRIVER to create the .PRN file - so you will get all your formatting - BOLD and stuff like that.
Have you tried this yet???
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
Yes, actually I have already tried out those things.
In fact, I faced a couple of issues with that:
1. The file that gets generated has a lot of driver information and the formatting is also not maintained any more.
2. The user of this application may have just one printer installed. Then in that case I'll have to change the Printer Port to "FILE:" programmatically and then once the printing is over I'll have to change it back to the original port. Again here also I'm still looking for a method to change the PORT programmatically!
So can you please suggest something on these.
PS: The attached Print.zip has two versions of the same report. 'Printer.MDI' is the printer version of the program where 'PrintToFile' is the one generated using the 'Print To File' option (This can be viewed using wordpad or MS Word).