从VBA(MS-Access)填写PDF表单

7
我希望从我的MS-Access 2003 .mdb项目中填写PDF表格。该PDF使用Adobe LifeCycle Designer ES 8.2创建,所有字段都有显著名称。然而,运行填写PDf功能的用户没有安装LifeCycle,而只安装了Adobe Reader 9.5(可能很快迁移到Adobe Reader X),我希望我的代码能够有一点未来性。

我该如何实现这一点?大多数在网络上看到的线程都会重定向到官方的Adobe SDK文档,但对于仅使用VBA的用户来说,这完全是一场灾难。

谢谢。

1个回答

8

在合并一些代码行后,终于成功让某些东西运作起来了。这就是它的样子。需要在我的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 会自动添加索引号,以便您可以轻松循环遍历您的字段。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接