Combine PDF

Hi guys,
I had written a windows program using Bernardo Monsalve‘ dbReport and now I need to add another page to print duplex on the back. Does anyone know how to add it? or if I make two PDFs, how to combine them?

I am using dbreport class to use the designer.

You can combine two PDFs using pdftk. It is free and you can call it with a shell.

you can also use MBS Xojo DynaPDF Plugin to do a lot with PDF including merging them.

or cpdf command line version. very similar to PDFtk

Thanks guys,
I am trying to use pdftk but for some reason, I can’t figure this out and I get no errors. For example, I have two files TEST.PDF and TEST1.PDF and I want to combine them to TEST.PDF. In this code, I get “TEST.PDF TEST1.PDF cat output TEST.PDF” on the msgbox. I even specified a new file name as the output file. Any help will be appreciated.

Static pdftk as String = path.child(“pdftk.exe”).ShellPath

Dim s as New Shell

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

Dim finalf as String
finalf = file.DisplayName + " " + fpdf.DisplayName + " cat output " + file.DisplayName

msgbox finalf

s.Execute(pdftk, finalf)

Use System.DebugLog to be sure of what is in all these display name, and at last, do the same for finalf

Do not use MsgBox for debug (boring and subject to bug your project).

You can visualize the DebugLog whilme the program runs… in the IDE.

Thank Emile, I used System.Debuglog and I see this for finalf:

9:28:45 AM : test.pdf TEST1.pdf cat output newfile.pdf

test.pdf and test1.pdf DO get created and I can see them in the folder. If I use the graphical PDFTK, they do combine

You need the full path to the PDF’s with quotes around it and I would also use a different filename for the output:

finalf = chr(34) + file1.NativePath + chr(34) + " " + chr(34) + file2.NativePath + chr(34) + " cat output " + chr(34) + file3.NativePath + chr(34)

nothing: I see this:
11:14:08 AM : “C:\Users\ariss\OneDrive\Projects\ISS Service Contracts\R4\DebugISS Service Contracts\Ship Forms\test.pdf” “C:\Users\ariss\OneDrive\Projects\ISS Service Contracts\R4\DebugISS Service Contracts\Ship Forms\TEST1.pdf” cat output “C:\Users\ariss\OneDrive\Projects\ISS Service Contracts\R4\DebugISS Service Contracts\Ship Forms\FINAL.PDF”

Do you think this is the correct syntax: s.Execute(pdftk, finalf)
I think it is but maybe I am missing something

Looking into it more. If I call up the command prompt and get to the directory where I have the PDFs and the pdftk executable and run this:
pdftk.exe A=test.pdf B=TEST1.pdf cat A1 B1 output FINAL.PDF
it works. In my debug I have finalf reading this (just with the names, no path. Even though I also tried it with paths)
12:03:58 PM : A=test.pdf B=TEST1.pdf cat A1 B1 output FINAL.PDF

The following code works assuming you have two pdfs named pdf1.pdf and pdf2.pdf located in c:\data\test.

var f1 as New FolderItem("C:\data\test\pdf1.pdf")
var f2 as New FolderItem("C:\data\test\pdf2.pdf")
var fOutput as New FolderItem("c:\data\test\output.pdf")

var arsCommand() as String

arsCommand.AddRow chr(34) + "C:\Program Files (x86)\PDFtk\bin\pdftk.exe" +chr(34)
arsCommand.AddRow chr(34) + f1.NativePath  + chr(34)
arsCommand.AddRow chr(34) + f2.NativePath  + chr(34)
arsCommand.AddRow "cat output"
arsCommand.AddRow chr(34) + fOutput.NativePath  + chr(34)

var sCommand as String = String.FromArray(arsCommand," ")

var oPDFTk as New Shell
oPDFTk.TimeOut = 15 * 60 * 1000   '15 minutes


I really appreciate your help Brandon. I am not sure what I was missing before but I followed your last code and change folders to my current program and it work. Thank you for all your help. I bet it had to do with the syntax getting to pdftk