Printing from Windows 7 command line

167,456

Solution 1

The print command uses the following synatx for the /d: switch:

Specifies the printer on which you want to print the job. You can specify a local printer by specifying the port on your computer to which the printer is connected. Valid values for parallel ports are LPT1, LPT2, and LPT3. Valid values for serial ports are COM1, COM2, COM3, and COM4. You can also specify a network printer by its queue name (\ServerName\ShareName). If you do not specify a printer, the print job is sent to LPT1.

This means you can't use "CutePDF Writer" as an argument.

There are two ways that should work:

  • Assign a COM port to your printer.

    1. Open Start → Control Panel → Devices and Printers.
    2. Right-click the CutePDF Writer and select Printer Properties.
    3. In the Ports tab, assign an unused port from COM1: to COM4: to your printer.
    4. If you chose, e.g., COM3, print using the following command:

      print /d:COM3 test.txt
      
  • Share the printer.

    1. Open Start → Control Panel → Devices and Printers.
    2. Right-click the CutePDF Writer and select Printer Properties.
    3. In the Sharing tab, decide to share the printer and assign a share name to it.
    4. If you chose, e.g., CutePDF, print using the following command:

      print /d:\\%COMPUTERNAME%\CutePDF test.txt
      

Solution 2

Print Registered File Types Files that have a file type association in Windows (95/98/NT/2000) can be printed using the right mouse button

This association can be seen, e.g. for .rtf file in

"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\rtffile\shell\printto\command"

where command looks something like this:

"%ProgramFiles%\Windows NT\Accessories\WORDPAD.EXE" /pt "%1" "%2" "%3" "%4"

which means :

"wordpad.exe /pt TextFileName PrinterName [ DriverName [ PortName ] ]"

(square brackets mean optional). It can be called from cmd using powershell, shipped in Windows since Vista.

powershell -command "start -verb printto AnyFile.rtf PrinterName [ DriverName [ PortName ] ]"

Strictly:

"%windir%\System32\WindowsPowerShell\v1.0\powershell.exe" "-Command" "& {Start-Process -FilePath  'test.txt'  -ArgumentList '\"CutePDF Writer\"' -Verb 'printto' }"

It works for almost any Registered File Types with such registered verb (printto)! But printer drivers will usually shows user dialog. User dialog showing can be disabled in Bullzip Pdf printer.

Solution 3

Hi The following is easier set CutePDF as default printer if you know DOS then setting a printer as default should be no problem and then resetting to default printer setting again.

to print a text file or htm file or a bat file or any text file enter the following

  notepad /p test.txt

for other programs find the command line format for printing (in regedit or in documentation)

Solution 4

@mizipzor:

  1. The job file successfully gets into the printqueue when you follow Dennis' answer.

  2. But then the job processing gets stuck because that printer cannot consume a TEXT input file! The reasons:

    • Windows print queues are a lot more dumb in this respect (in contrast to CUPS Linux/Unix/OSX queues -- which can auto-type the incoming data and automatically convert them to what the respective printqueue reports as digestable data).
    • Your printer very likely expects PostScript data as input in order to create a PDF from it.

Hence, what you try to do with your command will not work: send a text file to a PDF-creating "printer". And it is not possible to make it work in any other "simple" way either...

Share:
167,456

Related videos on Youtube

agaragaragar
Author by

agaragaragar

Updated on September 18, 2022

Comments

  • agaragaragar
    agaragaragar almost 2 years

    I'm looking to automate some printing in Windows 7. Ideally from command line. Just as if I would've right-clicked and selected "Print".

    Tried the command:

    C:\>print /D:"CutePDF Writer" test.txt
    

    That printer is supposed to created PDF files (like the XPS printer) but haven't managed to get anything show up in the printer queue. Ideas?

    • Ishikawa Yoshi
      Ishikawa Yoshi almost 12 years
    • Ishikawa Yoshi
      Ishikawa Yoshi almost 12 years
    • martineau
      martineau almost 12 years
      Are you trying to create PDF files or print them (or both)?
    • agaragaragar
      agaragaragar almost 12 years
      @martineau I'm trying to create PDF files by using that "printer". So I guess both. But I'm not looking to get physical papers.
    • martineau
      martineau almost 12 years
      @mizipzor: OK, I understand. I think Dennis has your answer. I would assign it to LPT1 if possible, which is the default for most commands.
    • agaragaragar
      agaragaragar almost 12 years
      @martineau indeed he has, by referring properly to the printer the job was added to the printer queue. However, it couldn't complete and got stuck with an error. I assume this is because that particular printer opens a "save file" dialog for the output. Something thats probably not possible when its being started from command line.
    • martineau
      martineau almost 12 years
      @mizipzor: Good. I suspect the current problem is not because it was started from the command line, which by itself would not prevent a program from displaying a dialog. See if there's some kind of error information available for the printer in the Device and Printers control panel -- or "print" a test page there and see what happens.
    • Kurt Pfeifle
      Kurt Pfeifle over 8 years
      @mizipzor: The job gets stuck because that printer cannot consume a TEXT input file! Windows print queues are a lot more dumb in this respect (in contrast to CUPS Linux/Unix/OSX queues -- which can auto-type the incoming data and automatically convert them to what the respective printqueue reports as digestable data). Your printer very likely expects PostScript data as input in order to create a PDF from it. Hence, what you try to do with your command will not work: send a text file to a PDF-creating "printer".
  • Muath
    Muath about 9 years
    if i want to scan from printer using cmd what to do?
  • Sun
    Sun about 8 years
    You might want to convert your TXT to PDF first using a free command line program called text2pdf: eprg.org/pdfcorner/text2pdf