Dr.K
08-18-2008, 01:29 PM
I have a huge batch of PDF files that need to be sorted and collated together into specific orders. The main code uses lots of SQL, but the PDF grunt work is done by this function:
Function AppendPDFPages(pathPDF1 As String, pathPDF2 As String) As Boolean
Dim PDDoc1 As Object
Dim PDDoc2 As Object
Set PDDoc1 = CreateObject("AcroExch.PDDoc")
Set PDDoc2 = CreateObject("AcroExch.PDDoc")
AppendPDFPages = PDDoc1.Open(pathPDF1)
If AppendPDFPages = False Then GoTo EndOfFunc
AppendPDFPages = PDDoc2.Open(pathPDF2)
If AppendPDFPages = False Then GoTo EndOfFunc
AppendPDFPages = PDDoc1.InsertPages((PDDoc1.GetNumPages() - 1), _
PDDoc2, 0, PDDoc2.GetNumPages(), False)
If AppendPDFPages = False Then GoTo EndOfFunc
AppendPDFPages = PDDoc1.Save(1, pathPDF1)
EndOfFunc:
PDDoc1.Close
Set PDDoc1 = Nothing
PDDoc2.Close
Set PDDoc2 = Nothing
End Function
This appends whole documents only. (ALL pages from PDF2 and appended to the end of PDF1)
The function returns FALSE if there was an error in the process.
I'm posting this mostly as a code a example, but I have to ask: is there a better way to do this?
Function AppendPDFPages(pathPDF1 As String, pathPDF2 As String) As Boolean
Dim PDDoc1 As Object
Dim PDDoc2 As Object
Set PDDoc1 = CreateObject("AcroExch.PDDoc")
Set PDDoc2 = CreateObject("AcroExch.PDDoc")
AppendPDFPages = PDDoc1.Open(pathPDF1)
If AppendPDFPages = False Then GoTo EndOfFunc
AppendPDFPages = PDDoc2.Open(pathPDF2)
If AppendPDFPages = False Then GoTo EndOfFunc
AppendPDFPages = PDDoc1.InsertPages((PDDoc1.GetNumPages() - 1), _
PDDoc2, 0, PDDoc2.GetNumPages(), False)
If AppendPDFPages = False Then GoTo EndOfFunc
AppendPDFPages = PDDoc1.Save(1, pathPDF1)
EndOfFunc:
PDDoc1.Close
Set PDDoc1 = Nothing
PDDoc2.Close
Set PDDoc2 = Nothing
End Function
This appends whole documents only. (ALL pages from PDF2 and appended to the end of PDF1)
The function returns FALSE if there was an error in the process.
I'm posting this mostly as a code a example, but I have to ask: is there a better way to do this?