在 SO 和其他地方有很多关于使用非 Adobe 产品以编程方式组合 PDF 文件的建议。
有没有办法(相当容易)使用我的 Adobe Acrobat Standard(不是 Reader)的付费副本以编程方式将两个或多个 PDF 文件组合成一个新的 PDF 文件(我知道它可以通过组合 -> 多个文件手动完成)?
更喜欢命令(例如,复制 file1.pdf file2.pdf combine.pdf),但愿意求助于 VBA。
感谢您的任何想法!
在 SO 和其他地方有很多关于使用非 Adobe 产品以编程方式组合 PDF 文件的建议。
有没有办法(相当容易)使用我的 Adobe Acrobat Standard(不是 Reader)的付费副本以编程方式将两个或多个 PDF 文件组合成一个新的 PDF 文件(我知道它可以通过组合 -> 多个文件手动完成)?
更喜欢命令(例如,复制 file1.pdf file2.pdf combine.pdf),但愿意求助于 VBA。
感谢您的任何想法!
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
Acrobat 没有 VBA。VBA 是微软的东西(显然很快就会从我读过的内容中消失[编辑:罢工;显然它在 Office 2010 中仍然存在并且运行良好])。
Acrobat SDK将允许您自动化 Acrobat 并做您想做的事情,但它不适合胆小的人。使用您在其他地方读到的免费解决方案之一可能更容易(无论如何是短期的)。