在SO和其他地方有很多关于使用非Adobe产品以编程方式组合PDF文件的建议。
没有办法(相当容易)使用我的付费副本Adobe Acrobat Standard(而不是Reader)以编程方式将两个或多个PDF文件合并到一个新的PDF文件中(我知道它可以通过组合手动完成 - >多个文件)?
更喜欢命令(例如,复制file1.pdf file2.pdf combined.pdf),但愿意诉诸VBA。
感谢您的任何想法!
答案 0 :(得分:0)
Acrobat没有VBA。 VBA是一个微软的东西(显然很快就会从我读过的内容中消失[编辑:罢工;显然它在Office 2010中仍然存在且很好]。)
Acrobat SDK将允许您自动化Acrobat并执行您想要做的事情,但对于胆小的人来说它不。使用您在其他地方阅读的免费解决方案可能更容易(短期,无论如何)。
答案 1 :(得分:0)
Sub MergePDFs(nDocs As Integer, BaseFileName As String)
Dim AcroApp As Acrobat.CAcroApp
Dim iDoc As Integer
Dim BaseDocument As Acrobat.CAcroPDDoc
Dim PartDocument As Acrobat.CAcroPDDoc
Dim numPages As Integer
Set AcroApp = CreateObject("AcroExch.App")
Set BaseDocument = CreateObject("AcroExch.PDDoc")
Set PartDocument = CreateObject("AcroExch.PDDoc")
BaseDocument.Open (ActiveWorkbook.Path & "\" & BaseFileName & "_" & 1 & ".pdf")
For iDoc = 2 To nDocs
PartDocument.Open (ActiveWorkbook.Path & "\" & BaseFileName & "_" & iDoc & ".pdf")
numPages = BaseDocument.GetNumPages()
' Insert the pages of Part after the end of Base
If BaseDocument.InsertPages(numPages - 1, PartDocument, 0, PartDocument.GetNumPages(), True) = False Then
MsgBox "Cannot insert pages"
End If
PartDocument.Close
Next iDoc
If BaseDocument.Save(PDSaveFull, ActiveWorkbook.Path & "\" & BaseFileName & ".pdf") = False Then
MsgBox "Cannot save the modified document"
Else
' Remove intermediate documents
For iDoc = 1 To nDocs
Kill ActiveWorkbook.Path & "\" & BaseFileName & "_" & iDoc & ".pdf"
Next iDoc
End If
BaseDocument.Close
AcroApp.Exit
Set AcroApp = Nothing
Set BaseDocument = Nothing
Set PartDocument = Nothing
End Sub