karthikcoep Posted December 16, 2010 Share Posted December 16, 2010 I have a folder with 100 pdf documents. I need to convert these document to xps. The conventional way would be to open each document and print the file using xps printer and save the same in some folder. For this I have to repeat this 100 times. Is there a way to automate this process using autoit so that this can be done in one go. Link to comment Share on other sites More sharing options...
Zedna Posted December 16, 2010 Share Posted December 16, 2010 First look if there is commandline support for this in PDF. This would be very easy then. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
sleepydvdr Posted December 16, 2010 Share Posted December 16, 2010 I don't know if this will help you, but I modified a script to do most of the functionality you want. The only part I couldn't do was to get AutoIt to type up the name of the file. If someone wants to help out and write some code to fix this, that would be appreciated. Other than that, this script opens each pdf and brings up the print dialog (you may want to set the xps writer as your default printer when you run the script). When you are done, just do a CTRL-Q to close all the pdf documents. With this script, you need to create a folder on the desktop called pdf. Put all your pdf files in it. Or you can modify the script to your liking. expandcollapse popup_DriveListProgramFiles(@DesktopDir & "\pdf", 1) ; This is searching to one level down Func _DriveListProgramFiles($sInitialPath, $iMaxLevel = 0) Local $asFolderList[2][2] = [[1, 0], [0, 0]] Local $asFileList[1] = [0] ; Add trailing \ if required If StringRight($sInitialPath, 1) <> "\" Then $sInitialPath = $sInitialPath & "\" ; Store result $asFolderList[1][0] = $sInitialPath ; Search in listed folders While $asFolderList[0][0] > 0 ; Check if we have exceeded the level limit If $asFolderList[$asFolderList[0][0]][1] <= $iMaxLevel Then ConsoleWrite("+ Searching: " & $asFolderList[$asFolderList[0][0]][0] & @CRLF) ; Set current level $iCurrLevel = $asFolderList[$asFolderList[0][0]][1] ; Set path to search $sCurrentPath = $asFolderList[$asFolderList[0][0]][0] ; Reduce folder array count $asFolderList[0][0] -= 1 ; Get Search handle $hSearch = FileFindFirstFile($sCurrentPath & "*.*") ; If folder empty move to next in list If $hSearch = -1 Then ContinueLoop ; Search folder While 1 $sName = FileFindNextFile($hSearch) ; Check for end of folder If @error Then ExitLoop ; Check for subfolder - @extended set in 3.3.1.1 + If @extended Then ; Add to folder list ; Increase folder list count $asFolderList[0][0] += 1 ; Double folder list size if too small (fewer ReDim needed) If UBound($asFolderList) <= $asFolderList[0][0] Then ReDim $asFolderList[UBound($asFolderList) * 2][2] ; Add folder name $asFolderList[$asFolderList[0][0]][0] = $sCurrentPath & $sName & "\" ; Add folder level $asFolderList[$asFolderList[0][0]][1] = $iCurrLevel + 1 Else ; Add to file list if it is *.exe file If StringRight($sName, 4) = ".pdf" Then ; Increase file list count $asFileList[0] += 1 ; Double file list size if too small (fewer ReDim needed) If UBound($asFileList) <= $asFileList[0] Then ReDim $asFileList[UBound($asFileList) * 2] ; Add file name $asFileList[$asFileList[0]] = $sName ;$sCurrentPath & $sName ; Open file ShellExecute(@DesktopDir & "\pdf\" & $sName) Opt("WinWaitDelay",100) Opt("WinTitleMatchMode",4) Opt("WinDetectHiddenText",1) Opt("MouseCoordMode",0) WinWait($sName & " - Adobe Reader","AVInternalDocumentVi") If Not WinActive($sName & " - Adobe Reader","AVInternalDocumentVi") Then WinActivate("OA Application.pdf - Adobe Reader","AVInternalDocumentVi") WinWaitActive($sName & " - Adobe Reader","AVInternalDocumentVi") Send("{CTRLDOWN}p{CTRLUP}") WinWait("Print","Co&mments and Forms:") If Not WinActive("Print","Co&mments and Forms:") Then WinActivate("Print","Co&mments and Forms:") WinWaitActive("Print","Co&mments and Forms:") Send("{ENTER}") WinWait("Save the file as","Save as &type:") If Not WinActive("Save the file as","Save as &type:") Then WinActivate("Save the file as","Save as &type:") WinWaitActive("Save the file as","Save as &type:") ;insert a naming function here WinWait($sName & " - Adobe Reader","AVInternalDocumentVi") If Not WinActive($sName & " - Adobe Reader","AVInternalDocumentVi") Then WinActivate($sName & " - Adobe Reader","AVInternalDocumentVi") WinWaitActive($sName & " - Adobe Reader","AVInternalDocumentVi") EndIf EndIf WEnd ; Close current search FileClose($hSearch) Else ConsoleWrite("! Ignoring: " & $asFolderList[$asFolderList[0][0]][0] & @CRLF) ; Reduce folder array count $asFolderList[0][0] -= 1 EndIf WEnd ; Remove any unused return list elements from last ReDim ReDim $asFileList[$asFileList[0] + 1] ; Display results ;_ArrayDisplay($asFileList) ; Just for demo - will take a long time if you have a lot of files EndFunc #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
karthikcoep Posted December 17, 2010 Author Share Posted December 17, 2010 (edited) Thank you all for replying. @sleepydvdr I tried your code, it opens up the pdf, but then nothing happens. Maybe because I am using acrobat pro. @ Deathbringer Your code works fine. It opens the pdf, then the print dialog is open, then it asks me to save, Here then I have to manually save each of the xps and give a file name to each one of them, I would like to save the xps directly in the same folder with the same filename as the original pdf. What addition to the code shall I make... Edited December 17, 2010 by karthikcoep Link to comment Share on other sites More sharing options...
sleepydvdr Posted December 17, 2010 Share Posted December 17, 2010 Deathbringer, kudos on the nice, concise code. It worked perfectly. Karthikcoep, can you copy the files to a computer that has Adobe Reader instead of Acrobat? It will probably work for you then. #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
karthikcoep Posted December 18, 2010 Author Share Posted December 18, 2010 Thanks Everyone. Done. 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