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 the key of a registry:
"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\rtffile\shell\printto\command"
where the 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). That mean you can use this information form the registry key to call the actual app directly from cmd
according to this pattern.
Or you can call it indirectly through this association from using powershell, shipped in Windows since Vista:
powershell "-Command" "& {Start-Process -FilePath 'test.txt' -ArgumentList '\"Microsoft Print to PDF\"' -Verb 'printto' }"
Concise form of it (powershell -command "start -verb printto AnyFile.rtf PrinterName [ DriverName [ PortName ] ]"
) or running it from powershell prompt doesn’t work on my pc for unknown reason.
It works for almost any Registered File Types with such registered verb (printto)!
UPD: To List Installed Printers wmic printer list brief
UPD: there is also a print verb. It doesn’t accept any arguments the except file. So almost all the above is true if you replace printto with print and drop additional printer arguments.
But printer drivers will usually shows user dialog. User dialog showing can be disabled in Bullzip Pdf printer.
Is there a way to run a file through a print driver without opening the application?
Ex: run a .docx file, without opening word, and save it to file?
Tom V
1,49818 silver badges24 bronze badges
asked May 1, 2010 at 6:59
2
Since it is a .docx
-file Microsoft Word is probably the best program to do the task.
I would have a look at the [command line arguments] to Word:
Have a look at the following switches:
/q
, /n
, /mFilePrintDefault
and /mFileExit
(/q
and /n
explained in the page above, and /mXxxx
refers to macros. Have a look att google.)
Example:
WINWORD.EXE your_document.docx /mFilePrintDefault /mFileExit /q /n
The following page seems to explain how to convert it to PDF.
Ber
40.5k16 gold badges73 silver badges88 bronze badges
answered May 1, 2010 at 7:14
aioobeaioobe
414k113 gold badges814 silver badges827 bronze badges
2
What you are looking for is called «headless start» of the program which needs to print.
I know for sure that OpenOffice can do this.
Basically, you need to start it and invoke a macro which will do the printing. Even more, you can print to a PDF, HTML, or anything else that Oo supports.
This negates the need for install of Microsoft Word and the cost of license, because OpenOffice is free.
answered May 1, 2010 at 7:15
VancoVanco
5181 gold badge6 silver badges11 bronze badges
If
- you have problems with Macro warnings;
- you are able to modify the default printer to be PDF Printer or similar;
- and you have the ability to add or record Macros.
Add something like this to normal.dotm:
Sub CmdPrint()
'
' CmdPrint Macro
'
'
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
PrintZoomPaperHeight:=0
End Sub
Then call from the command line as detailed above, such as:
@echo off & setlocal
set ProjectFolder=%USERPROFILE%\Projects
set Project=MyTest
set DocType=docm
start winword "%ProjectFolder:\\=\%%Project%.%DocType%" /q /n /mCmdPrint mFileCloseOrExit
answered Mar 21 at 11:28
1
You might be interested in DocTo which will convert a word document to another file format, including pdf and XPS but does require Word on the machine.
For example
Docto -f "c:\docs\mydocument.docx" -o "c:\output" -t wdFormatPDF
Will output mydocument.docx to c:\output\mydocument.pdf as a pdf file.
answered Sep 21, 2015 at 11:48
Toby AllenToby Allen
11k11 gold badges74 silver badges124 bronze badges
Updated: 05/04/2019 by
The print command allows users to print a text file to a line printer, in the background.
Availability
Print is an external command that is available for the following Microsoft operating systems. Print was introduced in MS-DOS 2.0 as print.com and later was changed to print.exe in MS-DOS 5.0 and all later versions of MS-DOS and Windows.
- MS-DOS 2.0 and above
- Windows 95
- Windows 98
- Windows ME
- Windows NT
- Windows 2000
- Windows XP
- Windows Vista
- Windows 7
- Windows 8
- Windows 10
- Windows 11
Print syntax
- Windows Vista and later syntax.
- Windows XP and earlier syntax.
Windows Vista and later syntax
PRINT [/D:device] [[drive:][path]file name[...]]
/D:device | Specifies a print device. |
Windows XP and earlier syntax
print /d:device /b:size /u:ticks1 /m:ticks2 /s:ticks3 /q:size /t drive:\path\ file name /c /p
Options:
/d:device | Name of the printer device. Printer Ports: LPT1, LPT2 or LPT3. Serial Ports: COM1, COM2, COM3 or COM4. |
/b:size | Sets size (in bytes) of the internal buffer. Default=512 with a range of 512 to 16384. |
/u:ticks1 | Maximum number of clock ticks PRINT is to wait for a printer to become available. Default=1 with a range of 1 to 255. |
/m:ticks2 | Maximum number of clock ticks PRINT can take to print a character. Default=2 with a range of 1 to 255. |
/s:ticks3 | Maximum number of clock ticks allocated for background printing. Default=8 with a range of 1 to 255. |
/q:qsize | Maximum number of files allowed in print queue. Default=10 with a range of 1 to 255. |
/t | Removes files from the print queue. |
drive:\path\ file name | Location and file name of the file to be printed. |
/c | Removes files from the print queue. |
/p | Adds files to the print queue. |
Print examples
Note
The print command is only able to print ASCII text. The /d, /b, /u, /m, /s, and /q switches can only be used once. If you require a different value, the computer must be restarted.
print c:\file.txt /c /d:lpt1
Prints the file.txt file to the parallel port lpt1.
Распечатка тестовой страницы по средствам cmd + wmic + printer.
Чтобы узнать/получить список принтеров и принтер установленный по умолчанию, в cmd выполним:
wmic printer get name,default
Получим список, где принтер по умолчанию будет отмечен значениtм TRUE в поле Default. Также мы получим название принтера которое указанно в системе.
Если требуется установить принтер по умолчанию, то в командной строке (cmd) выполним:
wmic printer where name="имя принтера" call setdefaultprinter
Далее, для печати тестовой страницы через командную строку/cmd выполняем:
rundll32 printui.dll,PrintUIEntry /k /n "имя принтера"
На этом все.
In this post I will show you how to print a PDF document from the Windows command line, terminal or CMD using the executable PDFtoPrinter.exe
.
As you know, printing a PDF from the Windows terminal is not possible using the print
command (since it only prints text files), since a translator is required to read the content of the PDF and send it to the printer.
It is precisely what this utility called PDFtoPrinter.exe
does, and in this post I’ll show you how to use it.
Downloading PDFtoPrinter
I can’t upload the executable here, but you can download it from where I downloaded it. Go to the following site: http://www.columbia.edu/~em36/pdftoprinter.html
Then click download it here.
Remember to have that executable in the same directory where you are going to invoke it from the CMD, or if you want to invoke it from anywhere, add it to the PATH.
Basic PDFtoPrinter syntax
The syntax is:
PDFtoPrinter.exe file.pdf printer
You can also indicate number of pages and other options, for this I will leave a link to the documentation.
Print PDF from Windows command line
Note: for this example I’m going to print on a thermal printer but with this utility we can print any PDF document on any printer, even one that is letter size, legal, etc. (only that right now I only have a Thermal one)
For example, I have a ticket in PDF format and the tool:
The PDF document is as follows:
ticket
Now from the CMD I navigate to that directory and run the following command:
PDFtoPrinter.exe ticket.pdf POS-58
I am invoking the utility with the name of the document and the name of the printer (my printer is POS-58
):
Note: you can specify the name of the printer in quotes if you want, and also put the name of a network printer, at the end I will leave a link to some documentation.
After a few seconds it will have printed, I say it again, in my case I printed it on a thermal printer but it works for any printer.
The result after printing a PDF document from Windows CMD is as follows:
As simple as that, you can print all the documents you want and on any printer, preserving all the details.
The advantages of this
With this utility we can print from practically any language on the server side, since we only have to invoke it from the command prompt or CMD, so that we could print in the background and silently from PHP, Python, C #, Go, among others.
Note: if you want to print a ticket to a thermal printer without using PDF see this post.
References
You can find more information about this utility here. I am not related with the page or the utility in any way, I just wanter to share it and show how it is used.
I am available for hiring if you need help! I can help you with your project or homework feel free to contact me.
If you liked the post, show your appreciation by sharing it, or making a donation