General discussion

Locked

Command Line Printing

By umakanth ·
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.

11 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Command Line Printing

by Hasse MCSE/Brainbench In reply to Command Line Printing

Hi!

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.

/Hasse

Collapse -

Command Line Printing

by umakanth In reply to Command Line Printing

Poster rated this answer

Collapse -

Command Line Printing

by Duong beo In reply to Command Line Printing

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.

Duong beo

Collapse -

Command Line Printing

by umakanth In reply to Command Line Printing

Poster rated this answer

Collapse -

Command Line Printing

by Hard Hat Harry In reply to Command Line Printing

Convert programs to postscript then use :
PRINT document.PS > LPT1:

Collapse -

Command Line Printing

by umakanth In reply to Command Line Printing

Poster rated this answer

Collapse -

Command Line Printing

by waynefz In reply to Command Line Printing

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).

Collapse -

Command Line Printing

by umakanth In reply to Command Line Printing

Poster rated this answer

Collapse -

Command Line Printing

by tysonmathews In reply to Command Line Printing

much easier this way.

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.

Collapse -

Command Line Printing

by umakanth In reply to Command Line Printing

Poster rated this answer

Back to Windows Forum
11 total posts (Page 1 of 2)   01 | 02   Next

Operating Systems Forums