本帖最后由 作者 于 2007-10-2 9:44:30 编辑
下面是一个追加pdf的函数, 合并也一样的 ' Append PDF files to a single PDF file ' Alvin 2/10/2007 'Thanks for the idea of johnsonm Public Function AppendPDFs(arrPdfFiles() As String, strFileName As String) As Boolean Dim AcroApp As CAcroApp Dim avCodeFile As CAcroAVDoc Dim PDDoc1 As CAcroPDDoc Dim PDDoc2 As CAcroPDDoc Dim i As Long Dim lngPage As Long Dim lngPageNum1 As Long Dim lngPageNum2 As Long Dim lngPageNum3 As Long lngPageNum1 = 0 lngPageNum2 = 0 lngPageNum3 = 0 'Start Acrobat in the background Set AcroApp = CreateObject("AcroExch.App") AcroApp.Hide Set avCodeFile = CreateObject("AcroExch.AVDoc") avCodeFile.Open strFileName, strFileName Set PDDoc1 = avCodeFile.GetPDDoc lngPageNum1 = PDDoc1.GetNumPages lngPageNum3 = 0 For i = LBound(arrPdfFiles) To UBound(arrPdfFiles) Set PDDoc1 = avCodeFile.GetPDDoc Set PDDoc2 = CreateObject("AcroExch.PDDoc") PDDoc2.Open arrPdfFiles(i) lngPage = PDDoc1.GetNumPages - 1 If lngPage < 0 Then lngPage = 0 PDDoc1.InsertPages lngPage, PDDoc2, 0, PDDoc2.GetNumPages, 0 lngPageNum3 = lngPageNum3 + PDDoc2.GetNumPages Next i PDDoc1.Save 1, strFileName lngPageNum2 = PDDoc1.GetNumPages PDDoc1.Close PDDoc2.Close avCodeFile.Close 0 'Exit Acrobat AcroApp.Exit Set AcroApp = Nothing Set avCodeFile = Nothing Set PDDoc1 = Nothing Set PDDoc2 = Nothing
If lngPageNum2 - lngPageNum1 = lngPageNum3 Then AppendPDFs = True Else AppendPDFs = False End If End Function |