Exequiel Posted July 3, 2018 Share Posted July 3, 2018 Hey, I'm new to autoit and I was hoping I could get some help ironing out these issues... I'm trying to screencapture a couple of tabs of the internet explorer and paste them to a word file for future use... I've nailed the mechanism for one tab, and i'm basically trying to convert it for multiple tabs. The screencapture loop is working, but it's not saving to my script directoy… I was hoping someone with more experience in autoit could point out where I've gone wrong... Also, in the section "add the pictures to the end of the document", I want to grab all the pictures that were saved and paste them to the word file. Again, the mechanism works for one but i'm stocked on how to convert it to multiple pictures... #include <ScreenCapture.au3> #include <Word.au3> ;Prepare screen for capturing (i.e. focus internetexplorer and fullscreen it) WinActivate("[Class:IEFrame]") sleep(1000) Send("{F11}") ;loop ScreenCapture of each Internet Explorer Tab $counter = inputbox("Screenshoots", "how many tabs are open to screenshoot?", "") If $counter = "" Then Exit For $I = 1 to $counter sleep(1500) $hBmp = _ScreenCapture_Capture("") _ScreenCapture_SaveImage(@ScriptDir & $i & ".PNG", $hBmp) ; <-- it's not saving to my directoy :/ $i = $i + 1 sleep(500) WinActivate("[Class:IEFrame]") Send("^{TAB}") ; it's the HotKey to switch the InternetExplorer tab Next ; Create Word application object Local $oWord = _Word_Create() _Word_DocSave($oDoc, @ScriptDir & "\test.docx") ; Add the pictures to the end of the document Local $oRange = _Word_DocRangeSet($oDoc, -2) _Word_DocPictureAdd($oDoc, @ScriptDir & "\test1.PNG", Default, Default, $oRange) ; <-- how do I convert it to grab all the PNG pictures that were saved??? ; Export document with default values in PDF Local $sFileName = @ScriptDir & "\Test1.pdf" _Word_DocExport($oDoc, $sFileName) ; Quit _Word_Quit($oWord) Thanks a lot for help Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 3, 2018 Share Posted July 3, 2018 (edited) Good evening @Exequiel You didn't insert the "/" in your path when you save the image... Take a look here: _ScreenCapture_SaveImage(@ScriptDir & $i & ".PNG", $hBmp) ; <-- it's not saving to my directoy :/ Becomes: _ScreenCapture_SaveImage(@ScriptDir & "\" & $i & ".PNG", $hBmp) ; It should saves the file now :) AND, you don't need to increase the $i, so you can remove the part: $i = $i + 1 'cause the Next does the job for you Let us know Best Regards. Edited July 3, 2018 by FrancescoDiMuro Exequiel 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Exequiel Posted July 3, 2018 Author Share Posted July 3, 2018 it worked Thx!!!! ; Script Start - Add your code below here #include <ScreenCapture.au3> #include <Word.au3> ;Prepare screen for capturing (i.e. focus internetexplorer and fullscreen it) WinActivate("[Class:IEFrame]") sleep(1000) Send("{F11}") ;loop ScreenCapture of each Internet Explorer Tab $counter = inputbox("Screenshoots", "how many tabs are open to screenshoot?", "") If $counter = "" Then Exit For $I = 1 to $counter sleep(1000) $hBmp = _ScreenCapture_Capture("") _ScreenCapture_SaveImage(@ScriptDir & "\" & $I & ".PNG", $hBmp) sleep(500) WinActivate("[Class:IEFrame]") Send("^{TAB}") ; it's the HotKey to switch the InternetExplorer tab Next Do you have a clue how to get the Word file to paste the multiples saved images?? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 3, 2018 Share Posted July 3, 2018 Do you have to paste multiple images to a Word document? Best Regards. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Exequiel Posted July 3, 2018 Author Share Posted July 3, 2018 Yeah, for example; if I have 3 tabs open, I was hoping to paste them into a Word file and have it saved as a pdf for future ref… Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 3, 2018 Share Posted July 3, 2018 (edited) For each group of tabs, you should create a Word document, in which you paste your screenshots It shouldn't be so difficult If I'd suggest to you: Create the Word object and document first; When you take the screenshot(s) in the For...Next loop, go for the _Word_DocPictureAdd() in there, and you should be ok. Best Regards. Edited July 3, 2018 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Exequiel Posted July 3, 2018 Author Share Posted July 3, 2018 I've simplified an aspect of the code just to understand how to apply your suggestion... Could you please indicate how you what do it in this scenario? #include <ScreenCapture.au3> #include <Word.au3> ; Create application object Local $oWord = _Word_Create() ; Open test document Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\test2.docx", Default, Default, True) $oIE = ObjCreate ( 'InternetExplorer.Application' ) $oIE.Visible = 1 $oIE.Navigate ( "https://www.google.com" ) sleep(2000) Local $hBmp ; Capture full screen $hBmp = _ScreenCapture_Capture("") _ScreenCapture_SaveImage(@ScriptDir & "\test1.PNG", $hBmp) ; Add a picture to the end of the document Local $oRange = _Word_DocRangeSet($oDoc, -2) _Word_DocPictureAdd($oDoc, @ScriptDir &"\test1.PNG", Default, Default, $oRange) ;<-- instead of pasting the saved file, how could I paste the $hBmp directly?? Link to comment Share on other sites More sharing options...
Exequiel Posted July 3, 2018 Author Share Posted July 3, 2018 btw, From the saved file I can do it ; Add the pictures to the end of the document For $I = 1 to $counter Local $oRange = _Word_DocRangeSet($oDoc, -2) _Word_DocPictureAdd($oDoc, @ScriptDir & "\" & $I & ".PNG", Default, Default, $oRange) sleep(1000) Next Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 3, 2018 Share Posted July 3, 2018 @Exequiel You could simplify a couple of things... For example, you could store the path where you save the .bmp file in avariable, in order to use the same variable to add the picture to the Word document Then, you could use _IE* functions to manipulate IE things... Did you manage to do what you were trying to do? Best Regards. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Exequiel Posted July 3, 2018 Author Share Posted July 3, 2018 Yeah, I managed to do it with your help expandcollapse popup#include <ScreenCapture.au3> #include <Word.au3> ;Prepare screen for capturing (i.e. focus internetexplorer and fullscreen it) WinActivate("[Class:IEFrame]") sleep(500) Send("{F11}") ;loop ScreenCapture of each Internet Explorer Tab $counter = inputbox("Screenshoots", "how many tabs are open to screenshoot?", "") If $counter = "" Then Exit For $I = 1 to $counter sleep(500) $hBmp = _ScreenCapture_Capture("") _ScreenCapture_SaveImage(@ScriptDir & "\temp\" & $I & ".PNG", $hBmp) sleep(500) WinActivate("[Class:IEFrame]") Send("^{TAB}") Next WinActivate("[Class:IEFrame]") sleep(500) Send("{F11}") ;Create application object Local $oWord = _Word_Create() ;Open temp document Local $oDoc = _Word_DocOpen($oWord, @ScriptDir & "\temp\temp.docx", Default, Default, True) ;Add the pictures to the end of the document For $I = 1 to $counter Local $oRange = _Word_DocRangeSet($oDoc, -2) _Word_DocPictureAdd($oDoc, @ScriptDir & "\temp\" & $I & ".PNG", Default, Default, $oRange) sleep(500) Next ;Export document with default values in PDF Local $sFileName = @ScriptDir & "\SavedPics.pdf" _Word_DocExport($oDoc, $sFileName) ;Quit _Word_Quit($oWord) ShellExecute(@ScriptDir & "\SavedPics.pdf") I could simplify bit, but for the moment it will do If you're feeling adventurous, is there a way to paste below the previous screenshot since right now it`s pasting in a new blank page every pick.. I've attached a picture as an exemple of the pdf output. Thx for all SavedPics.pdf Link to comment Share on other sites More sharing options...
Exequiel Posted July 3, 2018 Author Share Posted July 3, 2018 eeeee, wtf… its treating my pdf as a virus when I try to download it and view it (I like to make sure things look right)… -------------- Basically; Page 1: At the top, there`s a little text saying daily pics Page2: first screenshot Page 3: 2nd screenshot etc... ------------- There are big gaps between each page (especially the first page since I only have 1 line of text at the top). Is there a way to paste "after the last line of text/image" and not at the beginning of the next page? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted July 3, 2018 Share Posted July 3, 2018 @Exequiel I think you have to play a bit with _Word_DocRangeSet() Take a look at the example in the Help file ( very well documented ). Let us know! Best Regards. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Subz Posted July 4, 2018 Share Posted July 4, 2018 You can use something like: $oWordDoc.Bookmarks("\EndOfDoc").Range.InsertFile(...) 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