Merging PDFs with pdftk

I have some code to merge PDF that I am pretty sure used to work, but now pdftk crashes hard… Can any body see an issue with this code?
(BTW I use join.py on the Mac for this)

[code]Sub MergePDFFiles(destination as FolderItem, PDFs() as folderitem)
#If TargetWin32
Static pdftk as String = ResourceFolder.Child(“pdftk.exe”).ShellPath

dim cmdArr() as String
dim ub as Integer =PDFs.Ubound, i as Integer
reDim cmdArr(ub + 3)

for i = 0 to ub
  cmdArr(i) = PDFs(i).ShellPath
Next
cmdArr(ub +1) = "cat"
cmdArr(ub +2) = "output"
cmdArr(ub +3) = destination.ShellPath  

Dim s as New Shell

If s.ErrorCode <> 0 Then
  MsgBox("Error code: " + Str(s.ErrorCode))
  Return
End If

s.Execute(pdftk, Join(cmdArr, " " ))

#endif

End Sub
[/code]

Changing to this does not work either:

[code]Sub MergePDFFiles(destination as FolderItem, PDFs() as folderitem)
#If TargetWin32
Static pdftk as String = ResourceFolder.Child(“pdftk.exe”).ShellPath

dim cmdArr() as String
dim ub as Integer =PDFs.Ubound, i as Integer
reDim cmdArr(ub + 3)

for i = 0 to ub
  cmdArr(i) = PDFs(i).ShellPath
Next
cmdArr(ub +1) = "cat"
cmdArr(ub +2) = "output"
cmdArr(ub +3) = "-"   

Dim s as New Shell

If s.ErrorCode <> 0 Then
  MsgBox("Error code: " + Str(s.ErrorCode))
  Return
End If

Dim Stream as BinaryStream =  BinaryStream.Create(destination)

s.Execute(pdftk, Join(cmdArr, " " ))
Stream.Write S.Result
Stream.Close

#endif

End Sub
[/code]

Karen…

What version of PDFtk are you using? I was having problems late last year and contacted the author, he sent me a newer unreleased version that fixed the problem… So you might want to get an update.

I have also had problems merging very large PDFs… a problem that has yet to be solved.

[quote=263731:@James Meyer]Karen…

What version of PDFtk are you using? I was having problems late last year and contacted the author, he sent me a newer unreleased version that fixed the problem… So you might want to get an update.
[/quote]

As far as I can tell I am using the most recent from the website included with pdftk server… I guess I’ll need to contact the author.

My PDf’s are all on or two pages though I may be concatenating up to about 20 of them… but in my testing it was today it was crashing with only a few.

Thanks,

  • Karen

What happens when you run pdftk.exe manually. Does it crash than ?

What happens if you extend the shell default time-out ( 2 sec.) on windows to longer: s.timeout = 10000 // 10 seconds

Info: http://documentation.xojo.com/index.php/Shell.TimeOut