Search this blog ...

Wednesday, December 29, 2010

Additional Batch PDFill AutoIt Scripts

Merge all JPG image files in the source directory to a single PDF file in the output directory:

; Script by Matt Shannon - Dec 2010

$srcDirectory = 'C:\Documents and Settings\Administrator\Desktop\source'
$destDirectory = 'C:\Documents and Settings\Administrator\Desktop\output'

; change current directory to src directory
FileChangeDir($srcDirectory)
$search = FileFindFirstFile("*.jpg") 

If $search = -1 Then
  MsgBox(0, "Error", "No files/directories matched the search pattern")
  Exit
EndIf

RunPDFill()

$dest = ''

While 1
  $file = FileFindNextFile($search)
  If @error Then ExitLoop
  ; MsgBox(4096, "File:", $file)

  $dest = StringReplace($file, ".jpg", -1, 0) & ".pdf"

  AddImg($srcDirectory, $file)
 
WEnd

; Close the search handle
FileClose($search)

SaveToPDF($destDirectory, $dest)


Func RunPDFill()

  Run('C:\Program Files\PlotSoft\PDFill\PDFill_PDF_Tools.exe', "", @SW_MAXIMIZE)
  WinWaitActive("[REGEXPTITLE:PDFill PDF Tools 7.0.*]")

  ControlClick("[REGEXPTITLE:PDFill PDF Tools 7.0.*]", "", "[CLASS:Button; TEXT: 9. Convert Images to PDF]")
  WinWaitActive("[TITLE:Free PDF Tools: Convert images to PDF]")

  ; set paper size output to A4
  ControlClick("[TITLE:Free PDF Tools: Convert images to PDF]", "", "[CLASS:ComboBox; INSTANCE:1]")
  Send("A{ENTER}")

  ; set margins to 0
  ControlClick("[TITLE:Free PDF Tools: Convert images to PDF]", "", "[CLASS:Edit; INSTANCE:3]")
  Send("{HOME}{SHIFTDOWN}{END}{SHIFTUP}{DEL}0")

  ControlClick("[TITLE:Free PDF Tools: Convert images to PDF]", "", "[CLASS:Edit; INSTANCE:4]")
  Send("{HOME}{SHIFTDOWN}{END}{SHIFTUP}{DEL}0")

  ControlClick("[TITLE:Free PDF Tools: Convert images to PDF]", "", "[CLASS:Edit; INSTANCE:5]")
  Send("{HOME}{SHIFTDOWN}{END}{SHIFTUP}{DEL}0")

  ControlClick("[TITLE:Free PDF Tools: Convert images to PDF]", "", "[CLASS:Edit; INSTANCE:6]")
  Send("{HOME}{SHIFTDOWN}{END}{SHIFTUP}{DEL}0")

EndFunc


Func AddImg($srcdir, $srcfile)

  ; add an image
  ControlClick("[TITLE:Free PDF Tools: Convert images to PDF]", "", "[CLASS:Button; TEXT:Add an Image]")
  WinWaitActive("[TITLE:Select Image files to add into PDF]")

  ; send image location followed by enter
  ControlClick("[TITLE:Select Image files to add into PDF]", "", "[CLASS:Edit; INSTANCE:1]")
  Send($srcdir & "\" & $srcfile & "{ENTER}")

  ; wait for window to return
  WinWaitActive("[TITLE:Free PDF Tools: Convert images to PDF]")

EndFunc

Func SaveToPDF($destdir, $destfile)

  ; click save-as
  ControlClick("[TITLE:Free PDF Tools: Convert images to PDF]", "", "[CLASS:Button; TEXT:Save As ...]")
  WinWaitActive("[TITLE:Save all the images as ... ]")

  ; send pdf output location followed by enter
  ControlClick("[TITLE:Save all the images as ... ]", "", "[CLASS:Edit; INSTANCE:1]")
  Send($destdir & "\" & $destfile & "{ENTER}")

  ; wait for adobe to open - and then close it down
  WinWaitActive("[TITLE:" & $destfile & " - Adobe Reader]")
  WinClose("[TITLE:" & $destfile & " - Adobe Reader]")

  ; wait for pdf image tools to return - and then close it down
  WinWaitActive("[TITLE:Free PDF Tools: Convert images to PDF]")
  WinClose("[TITLE:Free PDF Tools: Convert images to PDF]")

  ; wait for main pdf tools to return - and then close it down
  WinWaitActive("[REGEXPTITLE:PDFill PDF Tools 7.0.*]")
  WinClose("[REGEXPTITLE:PDFill PDF Tools 7.0.*]")

EndFunc

 

Merge all PDF files in the source directory to a single PDF file in the output directory:

; Script by Matt Shannon - Dec 2010

$srcDirectory = 'C:\Documents and Settings\Administrator\Desktop\source'
$destDirectory = 'C:\Documents and Settings\Administrator\Desktop\output'

; change current directory to src directory
FileChangeDir($srcDirectory)
$search = FileFindFirstFile("*.pdf") 

If $search = -1 Then
  MsgBox(0, "Error", "No files/directories matched the search pattern")
  Exit
EndIf

RunPDFill()

$dest = ''

While 1
  $file = FileFindNextFile($search)
  If @error Then ExitLoop
  ; MsgBox(4096, "File:", $file)

  $dest = StringReplace($file, ".pdf", -1, 0) & "_merged.pdf"

  AddPdf($srcDirectory, $file)
 
WEnd

; Close the search handle
FileClose($search)

SaveToPDF($destDirectory, $dest)


Func RunPDFill()

  Run('C:\Program Files\PlotSoft\PDFill\PDFill_PDF_Tools.exe', "", @SW_MAXIMIZE)
  WinWaitActive("[REGEXPTITLE:PDFill PDF Tools 7.0.*]")

  ControlClick("[REGEXPTITLE:PDFill PDF Tools 7.0.*]", "", "[CLASS:Button; TEXT: 1. Merge PDF Files]")
  WinWaitActive("[TITLE:Free PDF Tools: Merge PDF Files]")

EndFunc


Func AddPdf($srcdir, $srcfile)

  ; Add a PDF File
  ControlClick("[TITLE:Free PDF Tools: Merge PDF Files]", "", "[CLASS:Button; TEXT:Add a PDF File]")
  WinWaitActive("[TITLE:Add PDF files to be Concated]")

  ; send image location followed by enter
  ControlClick("[TITLE:Add PDF files to be Concated]", "", "[CLASS:Edit; INSTANCE:1]")
  Send($srcdir & "\" & $srcfile & "{ENTER}")

  ; wait for window to return
  WinWaitActive("[TITLE:Free PDF Tools: Merge PDF Files]")

EndFunc

Func SaveToPDF($destdir, $destfile)

  ; click save-as
  ControlClick("[TITLE:Free PDF Tools: Merge PDF Files]", "", "[CLASS:Button; TEXT:Save As ...]")
  WinWaitActive("[TITLE:Save the concated file as ... ]")

  ; send pdf output location followed by enter
  ControlClick("[TITLE:Save the concated file as ... ]", "", "[CLASS:Edit; INSTANCE:1]")
  Send($destdir & "\" & $destfile & "{ENTER}")

  ; wait for adobe to open - and then close it down
  WinWaitActive("[TITLE:" & $destfile & " - Adobe Reader]")
  WinClose("[TITLE:" & $destfile & " - Adobe Reader]")

  ; wait for pdf image tools to return - and then close it down
  WinWaitActive("[TITLE:Free PDF Tools: Merge PDF Files]")
  WinClose("[TITLE:Free PDF Tools: Merge PDF Files]")

  ; wait for main pdf tools to return - and then close it down
  WinWaitActive("[REGEXPTITLE:PDFill PDF Tools 7.0.*]")
  WinClose("[REGEXPTITLE:PDFill PDF Tools 7.0.*]")

EndFunc

No comments:

Post a Comment