Hi
I got nerved of merging PDF files manually ... so I wrote some Functions...
You need the Autoit Beta (for COM) and Acrobat (Full). May not work with the Reader.
Run the following Code and specify a folder with pdfs. You are asked for a filename under which the merged file will be saved. After clicking OK the whole folder is merged into one PDF file.
Tested with Acrobat 6 under XP SP2
Dim $filelist[1]
; example merging files
$var= FileSelectFolder("Select folder", "","",$sourcepath) & "\"
MergeFiles($var,FileSaveDialog( "Select Filename", $var, "PDF Files (*.pdf)", 3))
; example end
func GetRotation($Targetpath)
;----------------------------------------------------
; Get the Rotation of a Page (eg. page 1)
; Ex.: msgbox(0,"Rotation",GetRotation("c:\pdft\test.pdf" ))
;----------------------------------------------------
if not FileExists($Targetpath) then
return -1
endif
$SourcePDF = ObjCreate("AcroExch.PDDoc")
if not IsObj($SourcePDF) then
return -2
endif
$b = $SourcePDF.Open($Targetpath)
$rotation = $sourcePDF.AcquirePage(0).GetRotate
$SourcePDF.close
$sourcePDF=""
return $rotation ; in Degree
EndFunc
func MergeFiles($SourcePath , $DestinationPath)
if fileexists($DestinationPath) then
FileDelete($DestinationPath)
endif
getfiles($sourcepath, "*.pdf") ; Search Files in Dir
if $filelist[0] < 2 then
Msgbox(32,"Info", "Ther are less than two files in folder")
exit
endif
for $n=2 to $filelist[0]
;msgbox(0,"Info" , $filelist[0] & " " & $filelist[$n])
ProgressOn("PDF Merge","Processing ...")
ProgressSet((($n-1)/$filelist[0]) * 100, $filelist[$n-1])
if $n=2 then
pdfmerge($sourcepath & $filelist[$n-1],$sourcepath & $filelist[$n], $DestinationPath)
else
pdfmerge($DestinationPath, $sourcepath & $filelist[$n], $DestinationPath)
endif
next
ProgressSet(100, $filelist[$filelist[0]])
sleep(800)
ProgressOff()
Endfunc
func getfiles($dir, $filter) ; search files in dir
Global $filelist[1]
$n=0
$search= FileFindFirstFile($dir & $filter)
; Check if the search was successful
If $search = -1 Then
MsgBox(0, "Error", "No files/directories matched the search pattern")
Exit
EndIf
While 1
$n=$n+1
$file = FileFindNextFile($search)
If @error Then ExitLoop
redim $filelist[$n+1]
$filelist[$n]= $file
$filelist [0] = $n
WEnd
; Close the search handle
FileClose($search)
EndFunc
func PDFMerge($File1, $File2, $Fileout)
; ---------------------------------------
; File1 first file
; File2 second file (inserted after)
; Fileout is the saving name
;
; returns 1 on success
; returns -1 Error insert Pages
; returns -2 Error Object Create
;----------------------------------------
$SourcePDF = ObjCreate("AcroExch.PDDoc")
if not IsObj($SourcePDF) then
return -2
endif
$b = $SourcePDF.Open($file1)
$TargetPDF = ObjCreate("AcroExch.PDDoc")
$b = $TargetPDF.Open($file2)
$intSourcePgs = $SourcePDF.GetNumPages
$intInsertPgs = $TargetPDF.GetNumPages
if not $SourcePDF.InsertPages($intSourcePgs-1, $TargetPDF, 0, $intInsertPgs, False) = -1 then
$SourcePDF.Close
$TargetPDF.Close
$SourcePDF=""
$TargetPDF=""
return -1
endif
$b = $SourcePDF.Save(1, $fileout)
$SourcePDF.Close
$TargetPDF.Close
$SourcePDF=""
$TargetPDF=""
return 1
endfunc
func GetPagesCount($target); count pages
$AcroPDDoc = ObjCreate("AcroExch.PDDoc")
if @error then return -1
$bPDF = $AcroPDDoc.Open($target)
if @error then return -2
$Pages= $AcroPDDoc.GetNumPages
$bPDF = $AcroPDDoc.Close
return $pages
endfunc
Feel free to improve the code...
Greetings Mozat90