Mr_Phil Posted September 27, 2006 Share Posted September 27, 2006 I have a script which takes two command line arguments: a web address and a file name. The plan is that the script will open a web browser containing the required URL and dump it, in PDF format, into the given filename. I'm using Adobe Distiller (V5) and FireFox. Problem 1: The solution is not generic. In the code I have hardcoded the title of the page I'm printing so that I can wait for it. Is there a better way of doing this? The only thing I can think of is to send the title as a third parameter, but thats less intuitive and user friendly. Problem 2: On my test machine, when I run the script, sometimes it works perfectly. Other times, it seems to 'get ahead of itself' and sends the keypresses before the windows have properly loaded and so it just sits there. I have a 'wait for window' thing going on - can any of you point out where I'm going wrong? Problem 3: Sometimes none of the windows has focus so the script pauses waiting. If I manually click the right window, the script takes over again. I've added a couple of alt-tabs to try to correct this and its made it better, but still an issue. Problem 4: When I uploaded the whole thing to the live server it gets as far as 'preparing to print', then hangs. Even if I do this by hand I get the same error. I've installed all the latest Microsoft Updates and the V5 Adobe patch. This is surely not a AutoIT issue, but if anyone has any insights I'd be grateful. Heres my code: ; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win XP ; Author: Phil based on script by Jonathan Bennett (jon@hiddensoft.com) ; ; Script Function: ; Open firefox. ; Open webpage specified in param1 ; Save as PDF as filename param2 (print via acrobat distiller) ; Quit Firefox and Adobe Reader ; Run Browser Run("C:\Program Files\Mozilla Firefox\firefox.exe " & $CmdLine[1]) ; Wait for the firefox become active - I'm working with a website that has XXX as its title WinWaitActive("XXX - Mozilla Firefox") ; Now that the Firefox window is active, order the print Send("!F") ;print menu Send("P") ;print option Send("a") ;select distiller Send("{ENTER}") ;go! ;send("!{tab}") ;just to make sure the print box has focus. (it should be the only thing active) ;send("!{tab}") ;send("!{tab}") WinWaitActive("Save PDF File As") Send($CmdLine[2]) ;take filename from the second command line parameter Send("{ENTER}") ;Make that PDF Send("y") ;overwrite if necessary ;tidy up WinWaitActive("Adobe Acrobat - ["&$CmdLine[2]&"]") send("!Fx") WinWaitActive("Management Perspectives - Mozilla Firefox") send("!Fx") ; Finished! Link to comment Share on other sites More sharing options...
nfwu Posted September 27, 2006 Share Posted September 27, 2006 (edited) Ah! The perfect support request! lol. Been a long time since I've seen one that actually tells people in detail what is going on - Very helpful in getting a reply. Onto the problem: expandcollapse popup; ; AutoIt Version: 3.0 ; Language: English ; Platform: Win XP ; Author: Phil based on script by Jonathan Bennett (jon@hiddensoft.com) ; ; Script Function: ; Open firefox. ; Open webpage specified in param1 ; Save as PDF as filename param2 (print via acrobat distiller) ; Quit Firefox and Adobe Reader ; Run Browser Run("C:\Program Files\Mozilla Firefox\firefox.exe " & $CmdLine[1]) ; Wait for the firefox become active - I'm working with a website that has XXX as its title Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced _wwa("- Mozilla Firefox") Opt("WinTitleMatchMode", 1) ; Now that the Firefox window is active, order the print _sendwait("!F") ;print menu _sendwait("P") ;print option _sendwait("a") ;select distiller _sendwait("{ENTER}") ;go! ;send("!{tab}") ;just to make sure the print box has focus. (it should be the only thing active) ;send("!{tab}") ;send("!{tab}") _wwa("Save PDF File As") _sendwait($CmdLine[2]) ;take filename from the second command line parameter _sendwait("{ENTER}") ;Make that PDF _sendwait("y") ;overwrite if necessary ;tidy up _wwa("Adobe Acrobat - ["&$CmdLine[2]&"]") _sendwait("!Fx") _wwa("Management Perspectives - Mozilla Firefox") _sendwait("!Fx") ; Finished! Func _wwa($title, $text="") WinWait($title, $text) WinActivate($title, $text) WinWaitActive($title, $text) EndFunc Func _sendwait($text) Send($text) Sleep(100) EndFunc Can't help out on problem 4 though. #) Edited September 27, 2006 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode() 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