从 VBA (MS-Access) 填写 PDF 表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13362014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fill in a PDF form from VBA (MS-Access)
提问by dan
I want to fill a PDF form from my MS-Access 2003 .mdb project. The PDF has been created with Adobe LifeCycle Designer ES 8.2, all fields have significant names. However, the users who will run the PDf-filling functionnality don't have LifeCycle installed but only Adobe Reader 9.5 instead (might migrate to Adobe Reader X soon, I would like my code to be a little bit future proof).
我想从我的 MS-Access 2003 .mdb 项目中填写 PDF 表单。PDF 是使用 Adobe LifeCycle Designer ES 8.2 创建的,所有字段都有重要名称。但是,将运行 PDf 填充功能的用户没有安装 LifeCycle,而只安装了 Adobe Reader 9.5(可能很快会迁移到 Adobe Reader X,我希望我的代码有点面向未来)。
How can I implement this? Most threads that I've seen on the Web redirect to the official Adobe SDK documentation, which is completely a mess when you're only doing VBA.
我该如何实施?我在网上看到的大多数线程都重定向到官方 Adobe SDK 文档,当您只使用 VBA 时,这完全是一团糟。
Thank you.
谢谢你。
回答by dan
Finally managed to get something working after merging some lines of code. Here it is. It works with the Adobe Acrobat 9.0 Type Library set as reference in my VBA project.
合并了几行代码后,终于设法使某些东西工作起来。这里是。它适用于在我的 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
Note that topmostSubform[0].Page1[0]
is the default name that Adobe LiveCycle Designer gives to your main PDF document, while fieldName[0]
is the name of your field. If you have multiple fields with the same name, Adobe LiveCycle Designer automatically adds index numbers so you can easily loop through your fields.
请注意,这topmostSubform[0].Page1[0]
是 Adobe LiveCycle Designer 为您的主 PDF 文档提供的默认名称,而fieldName[0]
是您的字段名称。如果您有多个同名的字段,Adobe LiveCycle Designer 会自动添加索引号,以便您可以轻松地循环浏览您的字段。