Tutorial :Text printing in landscape via notepad


I'm trying to do some text-based printing on Windows. My program makes use of windows' "notepad /p file.txt" functionality that prints a text file on the default printer.

The problem is that you cannot say that you want to print in landscape instead of portrait. In the same way, it's not possible to print to another printer.

Some background information on this: I'm printing out of a Tcl/Tk program (see The Tcl'ers wiki on text printing). I can print using the GDI, but for some reason this is too slow, and I want to offer text printing as a fast alternative as print to a text file is already available.


You can try this freeware program. It is useful.


To bring up a printer dialog for some text do something like this

set fd [open "|PrFile32.exe /-"]  set str "This is my long peice of text I want to write out to..."  puts $fd $str   flush $fd  

If you can't use an executable, Use printui.dll. You will have to enumerate the printers on the machine, then pass the string of the printer you wish to use

The following will show the print perferences dialog for a specific printer

 rundll32.exe printui.dll,PrintUIEntry /e /u /n "Adobe PDF"  

You could then call

 notepad.exe /p filename.txt  

I think the freeware route is much easier as you don't need to discover the default printer, ask the user and print the file in a nonstandard way.

EDIT I forgot to add the rundll32.exe part to bring up printer preferences


Something that could help you:


A Firefox extension that allows command-line printing. It does not seem to support passing orientation parameter, but I guess that it would be possible to add support for it.

EDIT I just re-read the extension page: it uses the default preference of the user profile, so if you set it up as having landscape printing by default, the extension should respect that setting.

Of course, this option would force your users to install both Firefox and this extension. Might not be the best choice...


After searching Google, it appears that there are no other command line options for notepad. Also, the print command doesn't appear to take alternate options for landscape printing. I had hoped that

notepad /p  

was different than

notepad /P  

(a capital 'P') but apparently not, so it looks like you are out of luck. The only suggestion I can come up with is see if there is a way to set the printing defaults from the command line, then switch them back afterwards. I have no idea if this is possible though.

Edit 1: Something that MIGHT help: http://www.robvanderwoude.com/2kprintcontrol.php.

Edit 2: Looks like this won't control the printing preferences, just the printers themselves, so you'll have to find another method.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »