【发布时间】:2017-02-27 00:27:12
【问题描述】:
我遇到了一个问题 - 我需要将自定义图章(注释类型)添加到多个 .pdf 文件中。我可以通过 Actions for Acrobat X Pro 进行操作,但我的客户没有该许可证,他们仍然需要这样做。文件列表存储在 Excel 电子表格中,因此理想情况下我正在寻找 VBA 解决方案。我想出了以下代码:
Option Explicit
Sub code1()
Dim app As Acrobat.AcroApp
Dim pdDoc As Acrobat.CAcroPDDoc
Dim page As Acrobat.CAcroPDPage
Dim recter(3) As Integer 'Array defining the rectangle of the stamp - in real code wil be calculated, simplified for ease of reading
Dim jso As Object
Dim annot As Object
Dim props As Object
Set pdDoc = Nothing
Set app = CreateObject("AcroExch.App")
Set pdDoc = CreateObject("AcroExch.PDDoc")
recter(0) = 100
recter(1) = 100
recter(2) = 350
recter(3) = 350
pdDoc.Open ("C:\Users\maxim_s\Desktop\Code_1\test1.pdf")
Set jso = pdDoc.GetJSObject
If Not jso Is Nothing Then
Set page = pdDoc.AcquirePage(0)
Set annot = jso.AddAnnot
Set props = annot.getprops
props.page = 0
props.Type = "Stamp"
props.AP = "#eIXuM60ZXCv0sI-vxFqvlD" 'this line throws an error. The string is correct name of the stamp I want to add
props.rect = recter
annot.setProps props
If pdDoc.Save(PDSaveFull, "C:\Users\maxim_s\Desktop\Code_1\test123.pdf") = False Then
MsgBox "fail"
pdDoc.Close
Else
MsgBox "success"
pdDoc.Close
End If
End If
End Sub
问题出在setprops 和getprops 程序上——似乎在创建注释时(jso.AddAnnot)它不拥有AP 属性,这是我标记的名称想补充。如果我先设置属性Type= "Stamp",然后尝试指定AP,结果是添加了一个默认图章,并且它的AP 被重命名为我的自定义图章AP。另请注意,如果我启动 acrobat 并使用下面的代码,则会添加正确的标记:
this.addAnnot({page:0,type:"Stamp",rect:[100,100,350,350],AP:"#eIXuM60ZXCv0sI-vxFqvlD"})
如果有办法从 PDDoc 对象内部的 VBA 执行此 Javascript,那将解决问题,但到目前为止我失败了。
【问题讨论】:
-
嗨,我也不知道该怎么做。但是如何使用 VBA 插入一个以您的图章/符号作为内容的文本框。将文件打印/导出为 PDF,然后隐藏/清除文本框?
标签: javascript vba pdf acrobat acrobat-sdk