从VBA填写PDF表格(MS-Access) [英] Fill in a PDF form from VBA (MS-Access)

查看:158
本文介绍了从VBA填写PDF表格(MS-Access)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的MS-Access 2003 .mdb项目中填写PDF表单. PDF是使用Adobe LifeCycle Designer ES 8.2创建的,所有字段均具有重要名称.但是,将要运行PDf填充功能的用户未安装LifeCycle,而仅安装了Adobe Reader 9.5(可能会很快迁移到Adobe Reader X,我希望我的代码可以在将来得到证明).

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).

我该如何实现?我在网上看到的大多数线程都重定向到官方的Adobe SDK文档,当您仅执行VBA时,这完全是一团糟.

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.

谢谢.

推荐答案

最终,在合并了几行代码后,设法使某些东西工作了.这里是.它可以与在我的VBA项目中设置为参考的Adobe Acrobat 9.0类型库一起使用.

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.

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会自动添加索引号,以便您轻松浏览各个字段.

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.

这篇关于从VBA填写PDF表格(MS-Access)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆