jimfx Posted January 18, 2009 Share Posted January 18, 2009 Hi All,I am NOOB and I made an AutoIT script to automate printing a PDF file (2x) on a different printer. It works but it looks a bit clumsy. I'll show a part of the script (don't laugh plz)Opt("WinTitleMatchMode", 2) WinWaitActive("Adobe Reader") ; print commandSend ("!b")Send ("r")WinWaitActive("Print",""); when pressing 5 times the down arrow key, the appropiate printer will be selected, (Xerox Phaser 3130 PCL 6 on Ne00:) then press 5x the TAB key to go to;the number of copies to printSend("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}{TAB}{TAB}{TAB}{TAB}{TAB}")sleep (500)Send("2"); press 7x TAB and hit ENTER to continueSend("{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{TAB}{ENTER}")etc.Can somebody please help me with a more robust script. When the order of printers changes, the whole procedure fails. I hope there is a better way to change printer and number of printed copies.Many thanks in advance!Jim Link to comment Share on other sites More sharing options...
martin Posted January 18, 2009 Share Posted January 18, 2009 (edited) You could use the AutoItInfo tool to find out what the instances are of the combobox for the printer list is, and the edit for the numnber of copies. Then, instead of using tab to get to the correct control use ControlFocus. Instead of using the down arror to get to the printer, which as you say is unreliable, either Send the printer name to select it, or use ControlCommand. Here is something very similar I did for printing files in a CAD program to pdf which might help. (The way I did it might not be the best either but it worked fine which is where I loose interest.) expandcollapse popup;script to print all the drawings in the CAD program to pdf While 1 $outPath = "C:\CAD\" & $Customer & "\pdfs\"; WinActivate("TurboCAD") $TCTitle = WinGetTitle("TurboCAD Professional") $drawing = _StringBetween($TCTitle, "[", ".tcw");the drawing displayed has it's file name in the title If Not IsArray($drawing) Then Exit;no drawings left to print? Send("!fp");select print If WinWaitActive("Print", "", 5) = 0 Then Exit ControlFocus("Print", "", "ComboBox1");select the printer list combo Send("CutePDF Writer");this is the printer I want Send("!1");fit on 1 page;only relevant for some printers? Send("{ENTER}");start printing ;ConsoleWrite("Will wait for Save As" & @CRLF) If WinWait("Save As", "", 5) = 0 Then Exit;something went wrong Sleep(200) ControlFocus("Save As", "", "Edit1") Sleep(200) Send($outPath & $drawing[0] & ".pdf");write the filename and path Send("{ENTER}");start it saving Sleep(400) $wtext = WinGetText("Save As") If StringInStr($wtext, "already exists") Then Sleep(1000) Send("{Y");ENTER}");yes overwrite EndIf Sleep(2000) WinActivate("TurboCAD");back to CAD Send("!fc");close that file because it's printed and we'll do the next Sleep(500) $count = 0 ;check the last pdf was actually created While Not FileExists($outPath & $drawing[0] & ".pdf") Sleep(300) $count += 1 If $count > 20 Then MsgBox(262144, "Error", "Failed to create file" & _ $outPath & $drawing[0] & ".pdf") Exit;oh dear! EndIf WEnd WEnd EDIT: Oh, welcome to the AutoIt forums Edited January 18, 2009 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...
ReFran Posted January 18, 2009 Share Posted January 18, 2009 (edited) You could use Adobe's command line options ( /h / t ) to print to different printersand send the command 2 times.http://www.adobe.com/devnet/acrobat/pdfs/A...faq.pdf#page=24Best regards, Reinhard Edited January 18, 2009 by ReFran Link to comment Share on other sites More sharing options...
water Posted January 19, 2009 Share Posted January 19, 2009 (edited) To select the printer I use the following code (where $Window holds the Title of the Acrobat Reader "Print" Window:$RC = ControlCommand($Window,"",1139,"SelectString",$Printer) If @error Then MsgBox(4096, @ScriptName,"Printer '" & $Printer & "' is not defined") $RC = WinWaitActive($Window,"") $RC = Send("{ESC}") _ClosePDF("") SetError(2) Return EndIf ; Rotate and center the printout $RC = ControlCommand($Window,"",563,"Check","") ; Set number of copies $RC = ControlSetText($Window,"",1154,$copies) ; Press "OK" Button $RC = ControlClick($Window,"",1) Edited January 19, 2009 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Manjish Posted January 19, 2009 Share Posted January 19, 2009 (edited) I have a very simple solution to this..I personally don't like mouse clicks and key sends, coz it can be real messy if there's any user input. and the beauty of any script is to make it run in the background, providing the user to do whatever he wants to do, and without disturbing him in any way.Hence i suggest u use this. Works fine for me. n its quite easy to do thru autoit too, using the @comspec macro. or just running a batch file. Edited January 19, 2009 by Manjish [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
nfaustin Posted January 19, 2009 Share Posted January 19, 2009 (edited) I also had similar automation about printing a document Try this code: WinActivate("Adobe Reader",'') Sleep(1000) send("!fp") WinWaitActive("Print",'') Sleep(100) ;============Make a loop here for multiple printer to print=========================== ControlFocus("Print","","[CLASS:ComboBox; INSTANCE:1]"); set the focus to combo box Sleep(10) ControlCommand("Print","","[CLASS:ComboBox; INSTANCE:1]","SelectString",'Printer Name'); select the printer name Sleep(10) ControlFocus("Print","","[CLASS:Edit; INSTANCE:2]"); set the focus to Copies combo box Sleep(10) ControlSetText("Print","","[CLASS:Edit; INSTANCE:2]",""); clear this default value of the Copies combo box Sleep(10) ControlCommand("Print","","[CLASS:Edit; INSTANCE:2]",EditPaste",'5'); set to 5 copies Sleep(10) ControlCommand("Print","","[CLASS:Button; TEXT:OK; INSTANCE:1]",); set the focus onOK button Sleep(10) ControlCommand("Print","","[CLASS:Button; TEXT:OK; INSTANCE:1]","Check", ""); click the OK button to print ;============End of loop here for multiple printer to print=========================== Exit You can used AutoIt window info and used the ControlCommand function. it's very helpful. let me know if this doesn't work so that I could review my programs... Edited January 19, 2009 by nfaustin [font="Palatino Linotype"][size="2"]*** The information contained in this post should be considered and certified WORKS ON MY MACHINE ***[/size][/font][font="Palatino Linotype"][size="2"] [/size][/font] Link to comment Share on other sites More sharing options...
jimfx Posted January 28, 2009 Author Share Posted January 28, 2009 Many Thanks Y'all. I have successfully made a script which can select printer and number of copies, without using TAB's or Arrow buttons. Cheers, Jim 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