在合并了几行代码后,终于设法使某些东西工作了。这里是。它适用于在我的 VBA 项目中设置为参考的 Adobe Acrobat 9.0 类型库。
Dim FileNm, gApp, avDoc, pdDoc, jso
FileNm = "c:\form.pdf" 'File location
Set gApp = CreateObject("AcroExch.app")
Set avDoc = CreateObject("AcroExch.AVDoc")
If avDoc.Open(FileNm, "") Then
Set pdDoc = avDoc.GetPDDoc()
Set jso = pdDoc.GetJSObject
jso.getField("topmostSubform[0].Page1[0].fieldName[0]").value = "myValue"
pdDoc.Save PDSaveIncremental, FileNm 'Save changes to the PDF document
pdDoc.Close
End If
'Close the PDF; the True parameter prevents the Save As dialog from showing
avDoc.Close (True)
'Some cleaning
Set gApp = Nothing
Set avDoc = Nothing
Set pdDoc = Nothing
Set jso = Nothing
请注意,这topmostSubform[0].Page1[0]
是 Adobe LiveCycle Designer 为您的主要 PDF 文档提供的默认名称,而fieldName[0]
是您的字段的名称。如果您有多个具有相同名称的字段,Adobe LiveCycle Designer 会自动添加索引号,以便您可以轻松地循环浏览您的字段。