Is it possible to send a file to a printer with a

2019-02-26 16:24发布

How can I use a batch file to send a text file or a .doc or similar, to a printer plugged into the computer through a USB port?

2条回答
老娘就宠你
2楼-- · 2019-02-26 17:13

Also to get the printer name:

wmic printer get name /value | findstr Name

It will list all printers like:

Name=PDF
Name=Microsoft XPS Document Writer
Name=Fax

And if you know part of the name, you may include it in a variable dynamically with FOR.

@echo off

for /f "tokens=2 delims==" %%a in (
    'wmic printer get name /value ^| findstr PartOfThePrinterName'
) do (
    set "printer_name=%%a"
)

REM Also you can remove the FOR command if you want to set the variable as static.
REM ie. "set printer_name=MyPrinterName"

print filename.txt /D:"%printer_name%"

exit /b 0

note the double quotes and no white space after /D: to be sure it get the right printer.

Another method is to set the default printer and print the document through the notepad.

RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%printer_name%"
start /min notepad /P filename.txt
查看更多
Evening l夕情丶
3楼-- · 2019-02-26 17:20

You can use the PRINT command like below to print ASCII files. Use print /? in command prompt to know more about the command. Here, /D is the switch fr device name since by default it's LPT1.

PRINT filename.txt /D:<printer_name>

Also, see this Article for much more information on printing PDF's etc.

查看更多
登录 后发表回答