使用标准 Acrobat 以编程方式合并 PDF 文件?

发布于 2024-08-06 16:04:38 字数 253 浏览 4 评论 0原文

SO 和其他地方有很多关于使用非 Adob​​e 产品以编程方式组合 PDF 文件的建议。

有没有办法(相当容易地)使用我的 Adob​​e Acrobat Standard(不是 Reader)的付费副本以编程方式将两个或多个 PDF 文件合并为一个新的 PDF 文件(我知道可以通过合并 -> 多个文件手动完成) ?

更喜欢命令(例如,复制 file1.pdf file2.pdf合并.pdf),但愿意诉诸VBA。

感谢您的任何想法!

There are lots of suggestions on SO and elsewhere for using non-Adobe products to programmatically combine PDF files.

Is there no way to (fairly easily) use my paid copy of Adobe Acrobat Standard (not Reader) to programmatically combine two or more PDF files into a new PDF file (I know it can be done manually with combine -> multiple files)?

Would prefer a command (e.g., copy file1.pdf file2.pdf combined.pdf), but would be willing to resort to VBA.

Thanks for any ideas!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

差↓一点笑了 2024-08-13 16:04:38
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
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
So尛奶瓶 2024-08-13 16:04:38

Acrobat 没有 VBA。 VBA 是 Microsoft 的东西(并且显然很快就会从我读到的内容中消失[编辑:删除该内容;显然它在 Office 2010 中仍然存在并且运行良好])。

Acrobat SDK 将允许您自动化 Acrobat 并执行您想做的事情,但它适合胆小的人。使用您在其他地方读到的免费解决方案之一可能会更容易(无论如何是短期的)。

There is no VBA for Acrobat. VBA is a Microsoft thing (and is apparently going away soon from what I've read [edit: strike that; apparently it's still alive and well in Office 2010]).

The Acrobat SDK will allow you to automate Acrobat and do what you want to do, but it's not for the faint of heart. It may be easier (short-term, anyway) to use one of the free solutions you've read about elsewhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文