I want to print Windows documents from the command line. For example, I want to develop a program that has two buttons. An "OPEN" button and a "PRINT" button. The "OPEN" button of course would allow me to select some file (eg a MSWord document). When I press PRINT I should be able to generate the command line to print and then print the file.
Whenever we right-click on a document (.doc, .txt etc) the menu also displays the "Print" option. I basically want to be able to call the print function of the application associated with the document.
PLEASE NOTE THAT I DO NOT WANT TO DISPLAY THE FILE SELECTED. I ONLY WANT TO PRINT ANY FILE GIVEN IT'S NAME.
This conversation is currently closed to new comments.
The easy answer is this isn't possible to do with DOS/Windows systems.
The only way you can get anything out to a printer in an easy way is by capturing the printer to LPT1, LPT2.....
Then if it's just a plain text file you can just do 'copy myfile.txt LPT1:'
Now the text file will be printed.
If you want to do the same thing with a word file you'll first have to make a program convert the file from word or whatever into the raw format accepted by your printer.
You could also make all documents into postscript and get a postscript able printer or convert all documents to HP:s PCL5.
First, to open the need file you have the command eg: Winword C:\Temp\Test.doc However be sure you have the command PATH=....... point to the directory contain winword.exe file (of course you need winword installed in that computer).
Unfortunately, you can only print the file (word, excel, ....etc.) if and only if the programming language you are using support OLE or at least DDE as printing is exclusively managed by the softwares themselves. So, I don't think you are able to print it from a DOS application.
If it's a static document (that is not going to be changed) I imagine this would work.
From Word "Print" it selecting the "Print to File" option which offers a ".prn" fiel extension. This would put it into the raw format acceptable to the printer.
Then the "copy filename.prn lpt1:" should work (provided it's sent to the same type of printer as you had selected when you "printed" it to file).
create a batch file called printer paste this in it. ________________ copy '%1' LPT1 _________________
I do not rmemebr thou if it is needed to have the ' around the %1 or not though. try with and with out. NOTE: LPT1 list is under the chance that your printer is installed on LPT1 if not then try LPT2 etc.
now place this file in your folder named send to. Now all you have to do is right click on the file to print and select printer and bing bang boom it sends the file to your printer. for any and all files.
If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.
Command Line Printing
Whenever we right-click on a document (.doc, .txt etc) the menu also displays the "Print" option. I basically want to be able to call the print function of the application associated with the document.
PLEASE NOTE THAT I DO NOT WANT TO DISPLAY THE FILE SELECTED. I ONLY WANT TO PRINT ANY FILE GIVEN IT'S NAME.