erifash Posted August 1, 2005 Share Posted August 1, 2005 (edited) I have submitted this function to Jos to be included with File.au3 in the Standard UDF Library.This UDF will print a plain text file using the ShellExecute function of shell32.dll. The file type that is going to be printed must have an editor with a print option associated to it (ex: Notepad). I have included a global constants list that defines the error codes returned in @error. Thanks to ezzetabi for making the _ShellExecute function! The code helped me make this.Here's the function documentation:;=============================================================================== ; ; Function Name: _FilePrint() ; ; Description: Prints a plain text file. ; ; Syntax: _FilePrint ( $s_File [, $i_Show] ) ; ; Parameter(s): $s_File = The file to print. ; $i_Show = The state of the window. (default = @SW_HIDE) ; ; Requirement(s): External: = shell32.dll (it's already in system32). ; Internal: = None. ; ; Return Value(s): On Success: = Returns 1. ; On Failure: = Returns 0 and sets @error according to the global constants list. ; ; Author(s): erifash <erifash [at] gmail [dot] com> ; ; Note(s): Uses the ShellExecute function of shell32.dll. ; ; Example(s): ; _FilePrint("C:\file.txt") ; ;===============================================================================If you want to print a text file that has no editor associated with it, use this:FileMove("text.ext", "text.txt") _FilePrint("text.txt") FileDelete("text.txt")As always, your questions and comments are greatly appreciated! Make sure to check it out and tell me what you think!P.S.: More information on ShellExecute can be found on MSDN.EDIT: Updated code slightly. Now it hides the window as default.EDIT2: Updated code to return the error in @error.print.au3 Edited August 13, 2005 by erifash My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
erifash Posted August 1, 2005 Author Share Posted August 1, 2005 I am thinking about submitting this to the Standard UDF Library because I searched over the help file and there were no references on "how to print files with AutoIt". It works very well and I can't see any flaws. I do need someone to look over this and tell me what they think though. Any help would be greatly appreciated! My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
HardCopy Posted August 1, 2005 Share Posted August 1, 2005 I am thinking about submitting this to the Standard UDF Library because I searched over the help file and there were no references on "how to print files with AutoIt". It works very well and I can't see any flaws. I do need someone to look over this and tell me what they think though. Any help would be greatly appreciated! <{POST_SNAPBACK}>Erifash Tried it here, Text output works fine. Out of curiosity i gave it a jpg as the filename. Under windowsxp2 It loaded windows picture and fax viewer showing the image. But didnt actually print obviously. (Although i have infranaview as my default viewer).Might be cool if it could print an image too.Other than that... great job and thanks for sharing.Hardcopy Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad Link to comment Share on other sites More sharing options...
FuryCell Posted August 1, 2005 Share Posted August 1, 2005 Awesome! Just tried it on a text file and it worked perfectly. Good Job. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
erifash Posted August 1, 2005 Author Share Posted August 1, 2005 Thanks! I never thought of trying it with an image... (testing) ...Yup, seems to only do plain text. That stinks. Oh well, it will still be a nice addition to the standard UDFs. My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
Valuater Posted August 2, 2005 Share Posted August 2, 2005 Nice... Clean... and Easy Thanks erifash 8) Link to comment Share on other sites More sharing options...
erifash Posted August 2, 2005 Author Share Posted August 2, 2005 You are quite welcome! I saw a topic on the help and support forum asking if there was a way to print using AutoIt, then I got on MSDN and Google and figured out how to accomplish that. I really hope this gets added to the Standard UDF Library because it will definantly help people with their printing needs. My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
MaCgyver Posted February 9, 2006 Share Posted February 9, 2006 (edited) You are quite welcome! I saw a topic on the help and support forum asking if there was a way to print using AutoIt, then I got on MSDN and Google and figured out how to accomplish that. I really hope this gets added to the Standard UDF Library because it will definantly help people with their printing needs. I am at home and my printer is dead. However I can see that the print job was sent to my printer. I also tested by choosing to print a jpeg file. One more thing to add to this print feature if possible. If we can print in landscape. I would also like if you send me a pm on your sources to help you create this print script.Oh yeah THANKS! Edited February 9, 2006 by MaCgyver Link to comment Share on other sites More sharing options...
YoseMite Posted February 9, 2006 Share Posted February 9, 2006 (edited) Thanks, I was searching for this UDF! So he print a file with the standard printer? Edited February 9, 2006 by YoseMite Link to comment Share on other sites More sharing options...
james3mg Posted May 23, 2006 Share Posted May 23, 2006 (edited) Thanks! I never thought of trying it with an image... (testing) ...Yup, seems to only do plain text. That stinks. Oh well, it will still be a nice addition to the standard UDFs.There's another way of printing that I talk about in a few of my posts... Func _PrintFile($filetoprint) RunWait(@COMSPEC & ' /c rundll32.exe ' & @SystemDir & '\mshtml.dll,PrintHTML "' & $filetoprint,@TempDir,@SW_HIDE) EndFunc I'm usually printing files I've written into the temp directory, so I'm not sure if the reference to @TempDir near the end of the code has to actually be the directory the file is in or not, but I suspect not. This will pop up a print dialog box, allowing you to print landscape, mirror, whatever you want. The only drawback is that since it's using IE's protocols to print, you (by default, though you can turn them off) get the classic "page x of y" and date and address stamped on the top and bottom of the print. This will print anything IE can print: text, pictures, web pages, etc. Works especially well with IE7 since you can do the "shrink to fit". Just as an alternative...thought you'd like to know Edit: Sorry for resurrecting a post that had been dead for a few months (years...?) - I forgot I got here by clicking a sig link, rather than from the list of current topics :"> . I just find this print function more useful because it's easy to FileWrite() HTML codes to compose nice-looking pages, then print them out, all in the background...not to mention the ability to handle pictures So I thought it should be listed on this topic. Edited May 23, 2006 by james3mg "There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110 Link to comment Share on other sites More sharing options...
erifash Posted May 23, 2006 Author Share Posted May 23, 2006 Wow! Now all we need to do is figure out how to automate it! My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
Diana (Cda) Posted August 6, 2008 Share Posted August 6, 2008 This UDF works just great. Thanks. Makes "invisible" printing possible without having to open up files and mess with dialogue boxes. My only need is to change the vehicle that does the printing. The file I had AutoIt print came out in notepad format. I recognize the look. My file is formatted for my notepad replacement. I tried a couple of things but with no success. I have no idea where to change the editor that will be used to print the doct. Can that even be done? The syntax I'd use to shellexecute this editor would be:$SamePartition = StringLeft(@ScriptDir, 2) ShellExecute($SamePartition & "\APPS\TEXT\npad, Metapad v3.51\APP- Metapad v3.51\Metapad.exe"Wondering similar syntax could go in the UDF or intot the script invoking the UDF. Thanks! Link to comment Share on other sites More sharing options...
martin Posted August 8, 2008 Share Posted August 8, 2008 (edited) This UDF works just great. Thanks. Makes "invisible" printing possible without having to open up files and mess with dialogue boxes. My only need is to change the vehicle that does the printing. The file I had AutoIt print came out in notepad format. I recognize the look. My file is formatted for my notepad replacement. I tried a couple of things but with no success. I have no idea where to change the editor that will be used to print the doct. Can that even be done? The syntax I'd use to shellexecute this editor would be:$SamePartition = StringLeft(@ScriptDir, 2) ShellExecute($SamePartition & "\APPS\TEXT\npad, Metapad v3.51\APP- Metapad v3.51\Metapad.exe"Wondering similar syntax could go in the UDF or intot the script invoking the UDF. Thanks! All the function does is to run notepad like this notepad /p $filename so the function is equivalent to ShellExecute($Filefullpath,"","","print") which is effectively Shellexecute("notepad.exe","/p " & $Filefullpath) (ShellExecute wasn't in AutoIt when erifash wrote the function.) If you want to print from metapad you can use shellexecute($SamePartition & "\APPS\TEXT\npad, Metapad v3.51\APP- Metapad v3.51\Metapad.exe","/p " & $FileFullPath) There is the slight complication that metapad doesn't just use the default printer like notepad does, but gives you the option to select a printer. That can be worked round fairly simply. To change the application used for printing you could edit HKEY_CLASSES_ROOT\cmdfile\shell\print\command so that metapad is set instead of notepad, but I think it is better to use ShellExecute or run. Edited August 11, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Emiel Wieldraaijer Posted August 9, 2008 Share Posted August 9, 2008 I use this, it will allow you to select you printer Func PrintTextFile($PrintFile) RunWait(@ComSpec & ' /c rundll32.exe ' & @SystemDir & '\mshtml.dll,PrintHTML "' & $PrintFile, @TempDir, @SW_HIDE) EndFunc ;==>PrintTextFile Best regards,Emiel Wieldraaijer Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now