【问题标题】:Merge pdf files with VBA and Foxit使用 VBA 和 Foxit 合并 pdf 文件
【发布时间】:2020-05-25 04:32:21
【问题描述】:

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

Dim phApp As PhantomPDF.Application

Dim n1 As String

Dim n2 As String

n1 = "c:\Temp\F3769-190136-GROUPE OCÉAN.pdf"

n2 = "c:\Temp\f3769-190136-GROUPE OCÉAN- facture.pdf"

Set phApp = CreateObject("PhantomPDF.Application")

Dim phCreator As PhantomPDF.Creator

Set phCreator = phApp.Creator

***'Call phCreator.CombineFiles("c:\Temp\F3769-190136-GROUPE OCÉAN.pdf|c:\Temp\f3769-190136-GROUPE OCÉAN- facture.pdf", "c:\Temp\F3769-190136-GROUPE OCÉAN.pdf", COMBINE_ADD_CONTENTS)***

Call phCreator.CombineFiles("""c:\Temp\" & n1 & "|'" & n2 & """" & ", " & """c:\Temp\F3769-190136-GROUPE OCÉAN.pdf"""" &", COMBINE_ADD_CONTENTS)

phApp.Exit

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

“参数不是可选的”

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

【问题讨论】:

    标签: vba pdf merge foxit


    【解决方案1】:

    您在调用行中的字符串定义不正确。

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

    此外,我不知道这个 phcreator.combine() 实际需要的语法 但是不能只使用:

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

    'Argument not option' 可能暗示您应该向 pHcreator 添加另一个输入,我猜这可能与 FOXIT 的组​​合功能页面设置有关。尝试在函数末尾添加一个输入变量整数?

    但它在以明文形式编写字符串时有效这一事实可能表明字符串操作不正确?

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

    【讨论】:

      【解决方案2】:

      我试过了,但得到了同样的错误信息。所以我利用了当文件名是纯文本时该函数有效的事实。我将要合并的文件复制到一个临时文件夹中并重命名它们。然后在合并功能中使用重命名的文件。它工作得很好,但福昕添加了一个目录页面,我还不知道如何删除它。这是我的解决方案:

      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:\Temp\filetomerge.pdf" 'full path of file to be merged
      
      princi = "c:\Temp\mainfile.pdf" 'full path of main file
      
      
      
      'fadd,pdf and fmain.pdf are the temporay files used in Foxit's function
      
      FileCopy addi, "c:\t2\fadd.pdf" 'temporary file to be merged in temporary folder
      
      FileCopy princi, "c:\t2\fmain.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:\t2\fmain.pdf|c:\t2\fadd.pdf", "c:\t2\fmain.pdf", COMBINE_ADD_CONTENTS)
      
      
      
      phApp.Exit
      
      
      
      'Save merged file in working folder under main file name
      
      Kill princi
      
      
      
      FileCopy "c:\t2\fmain.pdf", princi
      
      
      
      'delete temporary files
      
      Kill "c:\t2\fadd.pdf"
      
      Kill "c:\t2\fmain.pdf"
      
      End Sub
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-12
        • 2021-09-26
        • 2020-08-31
        • 2011-07-17
        • 2020-07-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多