【发布时间】:2018-05-11 19:15:52
【问题描述】:
我有一个包含多个 pdf 文件路径的表...现在我需要一个 VBA 代码来将所有这些文件合并到一个 pdf 文件中。 注意:-要合并的 pdfs 文件的数量会不时变化。
Sub Combine_PDFs_Demo()
Dim i As Integer 'counter for records
Dim x As Integer
Dim strNPDF As String
Dim bSuccess As Boolean
Dim DB As Database
Dim RS As Recordset
Set DB = CurrentDb
Set RS = DB.OpenRecordset("SELECT[paths] from scantemp ")
strNPDF = CurrentProject.Path & "\request_pic\" & (request_no) & ".pdf"
RS.MoveLast
DB.Recordsets.Refresh
i = RS.RecordCount
RS.MoveFirst
Dim strPDFs() As String
ReDim strPDFs(0 To i)
strPDFs(0) = RS![paths]
RS.MoveNext
For i = 1 To i - 1
strPDFs(i) = RS![paths]
bSuccess = MergePDFs(strPDFs, strNPDF)
Next i
If bSuccess = False Then MsgBox "Failed to combine all PDFs", vbCritical, "Failed to Merge PDFs"
DoCmd.SetWarnings False
DoCmd.RunSQL "delete from scantemp" 'delete all paths from table scantemp after converted it to pdf
DoCmd.SetWarnings True
RS.Close
Set RS = Nothing`enter code here`
【问题讨论】:
-
你现在有什么代码?您必须有一个检索 PDF 文件路径的循环吗?使用该循环并添加一个命令行实用程序,例如
pdftk。如果您期望有人为您编写代码,这不是一个很好的第一个问题 -
什么是MergePDFs?请描述问题:错误或不希望的结果?请缩进代码以提高可读性。
-
我为此使用了 GhostScript;效果很好。它会为您合并 PDF。
-
CreateObject("AcroExch.PDDoc")总是给我“不支持此类接口”我安装了 Adobe Acrobat DC