How do you print any printable file in Windows 10 by command line?

How do you print any printable file in Windows 10 by command line?

How do you print any printable file by command-line in Windows 10?

Images, PDF, text, word documents and such.

This question refers too all files you can print by right-clicking and selecting print from the menu that opens up.

Print option

答案1

PowerShell can print any file, using the same action as the Print verb defined for the file-type.

The PowerShell command to use is Start-Process, and the idea is simply to invoke the file itself with the Print verb.

The syntax is very simple:

Start-Process "path-to-file" -Verb print

I tested it with a PDF file, and the file printed correctly.

A more elaborate example is to be found in the documentation:

Example 2: Print a text file

This example starts a process that prints the C:\PS-Test\MyFile.txt file.

Start-Process -FilePath "myfile.txt" -WorkingDirectory "C:\PS-Test" -Verb Print

答案2

A few file extension specific solutions:

To print an image file:

mspaint /p some_file.png

This prints pdf files:
Print pdf files with command line

相关内容