【发布时间】:2018-12-02 15:27:18
【问题描述】:
我使用 acrobat xi pro 和 vba 来合并我的 pdf 文件。
我有一个代码,它使用此处找到的 acrobat api 将 pdf 页面附加在一起: https://wwwimages2.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/iac_api_reference.pdf
但是我试图自动为页面编号,或者添加我自定义保存的页眉和页脚设置并应用于所有页面。
这是我的代码:
Dim acroExchangeApp As Object
Set app = CreateObject("Acroexch.app")
Dim filePaths As Collection 'Paths for PDFS to append
Set filePaths = New Collection
Dim fileRows As Collection 'Row numbers PDFs to append
Set fileRows = New Collection
Dim sourceDoc As Object
Dim primaryDoc As Object ' PrimaryDoc is what we append too
Dim insertPoint As Long ' PDFs will be appended after this page in the primary Doc
Dim startPage As Long ' First desired page of appended PDF
Dim endPage As Long ' Last desired page of appended PDF
Dim colIndex As Long '
Dim numPages As Long
Dim acroDoc As Object
Set acroDoc = New AcroPDDoc
Set primaryDoc = CreateObject("AcroExch.PDDoc")
OK = primaryDoc.Open(filePaths(1))
Debug.Print "PRIMARY DOC OPENED & PDDOC SET: " & OK
For colIndex = 2 To filePaths.count
query_start_time = time()
start_memory = GetWorkingMemoryUsage
numPages = primaryDoc.GetNumPages() - 1
Set sourceDoc = CreateObject("AcroExch.PDDoc")
OK = sourceDoc.Open(filePaths(colIndex))
Debug.Print "(" & colIndex & ") SOURCE DOC OPENED & PDDOC SET: " & OK
numberOfPagesToInsert = sourceDoc.GetNumPages
'inserts pages
acroDoc.Open source_file_name
insertPoint = acroDoc.GetNumPages - 1
If endPage > 1 Then
OK = primaryDoc.InsertPages(insertPoint, sourceDoc, startPage, endPage - startPage, False)
Debug.Print "(" & colIndex & ") " & endPage - startPage & " PAGES INSERTED SUCCESSFULLY: " & OK
Else
OK = primaryDoc.InsertPages(insertPoint, sourceDoc, startPage, endPage - startPage + 1, False)
Debug.Print "(" & colIndex & ") " & endPage - startPage + 1 & " PAGES INSERTED SUCCESSFULLY: " & OK
End If
Set sourceDoc = Nothing
Next colIndex
OK = primaryDoc.Save(PDSaveFull, filePaths(1))
Debug.Print "PRIMARYDOC SAVED PROPERLY: " & OK
Set primaryDoc = Nothing
app.Exit
Set app = Nothing
有人可以帮忙吗?
【问题讨论】:
-
问题是什么?
-
@HackSlash 抱歉,您能帮我在每个 pdf 中自动插入页脚吗?
-
通过一些快速的在线研究,Acrobat 的 API 中似乎没有一种方法可以做到这一点。但是,如果您想看看是否有帮助,似乎确实有 possible workaround。
-
@K.Dᴀᴠɪs 谢谢你,我会调查的。