将pdf文件与VBA和福昕合并



我使用Foxit Phantompdf,完整版本和ACCESS。 在我们的程序中,我们必须保存多个pdf文件,其中一些文件在保存时应该合并到单个文件中。 这是我使用的代码;

Dim phApp As PhantomPDF.Application
Dim n1 As String
Dim n2 As String
n1 = "c:TempF3769-190136-GROUPE OCÉAN.pdf"
n2 = "c:Tempf3769-190136-GROUPE OCÉAN- facture.pdf"
Set phApp = CreateObject("PhantomPDF.Application")
Dim phCreator As PhantomPDF.Creator
Set phCreator = phApp.Creator
***'Call phCreator.CombineFiles("c:TempF3769-190136-GROUPE OCÉAN.pdf|c:Tempf3769-190136-GROUPE OCÉAN- facture.pdf", "c:TempF3769-190136-GROUPE OCÉAN.pdf", COMBINE_ADD_CONTENTS)***
Call phCreator.CombineFiles("""c:Temp" & n1 & "|'" & n2 & """" & ", " & """c:TempF3769-190136-GROUPE OCÉAN.pdf"""" &", COMBINE_ADD_CONTENTS)
phApp.Exit

当我尝试使用完整的文件名(粗体(时,代码运行良好。 但是,当我尝试使用变量时,我得到一个

"参数不是可选的">

错误。 有人可以帮助我吗? 谢谢

呼叫线路中的字符串定义不正确。

您已经使用 c:\temp 定义了 n1 和 n2,并且在字符串转换中再次添加它。我不知道这是否是导致您问题的途径。

此外,我不知道这个phcreator.combine((实际需要的语法 但是,仅使用以下方法是不可能的:

call pHcreator.combine(n1 & "|" & n2, …

"参数不选项"可能意味着您应该向 pHcreator 添加另一个输入,我猜这可能与 FOXIT 的组合函数页面设置有关。也许尝试在函数末尾添加一个输入变量整数?

但是,在以明文形式编写字符串时它起作用的事实可能表明字符串操作不正确?

我不是 vba 专业人士,但对结果感兴趣,与福昕合作,也想与 vba 结合。我目前没有使用版本 9 som,我似乎不走运,只有升级它我知道我想做什么才是可能的。

我试过了,但收到同样的错误消息。所以我利用了当文件名为纯文本时该函数起作用的事实。我将要合并的文件复制到临时文件夹中并重命名它们。重命名的文件随后在合并函数中使用。它运行良好,但是福昕添加了目录页面,我还不知道如何删除它。这是我的解决方案:

Private Sub Command4_Click()
Dim addi As String 'file to be merged to main file
Dim princi As String 'main file
Dim phApp As PhantomPDF.Application

'A temporary folder, in this case c:t2, should be present
'In this example c:Temp is the working folder

addi = "c:Tempfiletomerge.pdf" 'full path of file to be merged
princi = "c:Tempmainfile.pdf" 'full path of main file

'fadd,pdf and fmain.pdf are the temporay files used in Foxit's function
FileCopy addi, "c:t2fadd.pdf" 'temporary file to be merged in temporary folder
FileCopy princi, "c:t2fmain.pdf" 'temporary main file in temporary folder

'Merge action
Set phApp = CreateObject("PhantomPDF.Application")
Dim phCreator As PhantomPDF.Creator
Set phCreator = phApp.Creator
Call phCreator.CombineFiles("c:t2fmain.pdf|c:t2fadd.pdf", "c:t2fmain.pdf", COMBINE_ADD_CONTENTS)

phApp.Exit

'Save merged file in working folder under main file name
Kill princi

FileCopy "c:t2fmain.pdf", princi

'delete temporary files
Kill "c:t2fadd.pdf"
Kill "c:t2fmain.pdf"
End Sub

上面引用的代码在福昕与10及更高版本中不起作用。新的 api 版本要简单得多。

以下是当前 API 的链接: 福昕 API 参考指南

以下示例代码用于合并文件列表。这将使用竖线分隔的文件名列表。(示例:

"C:sourcefile01.pdf|C:sourcefile02.pdf|C:sourcefile03.pdf").

您还可以让它合并命名目录中的所有文件。有关其他示例,请参阅 API 参考指南。

Private Sub pdfCombineFiles()
Dim phCreator As FoxitPhantomPDF.Creator
Set phCreator = CreateObject("FoxitExch.Creator")
Dim nCombinedCnt As Integer
Dim mergeList As String
mergeList = Range("mergeList").Value

Dim finalFile As String
finalFile = Range("finalFile").Value

nCombinedCnt = phCreator.CombineFiles(mergeList, finalFile)
MsgBox "DONE: " & nCombinedCnt & " files combined"
End Sub

最新更新