如何在动态 PDF 表单 (LiveCycle) 中将 XML 加载到数据集中?

发布于 2024-11-27 00:54:44 字数 1726 浏览 2 评论 0原文

我需要预先填写动态 PDF 的字段,以便我的用户可以对其进行编辑并提交回来。

我正在使用 Adob​​e ColdFusion CFPDFFORM 标签,它可以将 XML 数据加载到 PDF 中并制作新的填充 PDF。不幸的是,它还清除了 标签,它完全清空了它!因此,所有绑定到数据集的下拉列表都不起作用。这是绑定其中一个的代码:

<bindItems ref="xfa.datasets.LOVFile.LOV.PreferenceLanguageList.PreferenceLanguage[*]" labelRef="$" valueRef="lic"/>

由于我无法控制 CFPDFFORM 标签的工作方式,因此我想出了一种解决方法。使用 LiveCycle Designer 进行编码,我将 中的所有数据存储到变量中,并将其加载到 form::initialize 处的数据集。

这似乎可以很好地加载数据集,就像 cfpdform 弄乱它们之前的情况一样。在 loadXML() 调用之后,我可以读取数据集并获得与原始 PDF 相同的结果,其数据集标记充满 XML 数据。

form1::initialize - (JavaScript, client)
//xfa.host.messageBox("loading xml to datasets");
xfa.datasets.nodes.namedItem("LOVFile").loadXML(LOVFile_var.value,0,1);
Page1.Header.debug.rawValue = xfa.datasets.LOVFile.LOV.PreferenceLanguageList.resolveNode("PreferenceLanguage[2]").value;

问题是下拉列表仍然不起作用,它们没有可显示的项目。不知何故,他们对数据集的绑定调用不会刷新?

loadXML() 之后我还应该做些什么吗? bindItems 的 LiveCycle 参考说“列表项和引用数据之间的链接处于活动状态。对数据的任何更改都会导致列表项立即更新。

任何帮助或指出正确的方向将不胜感激。

更新:

使用azathoth的答案,我可以使用新加载的数据集中的数据(在loadXml()调用之后)将项目添加到下拉列表中。

var oEyeColors = xfa.datasets.LOVFile.LOV.resolveNode("EyeColorList");
var numberOfNodes = oEyeColors.nodes.length;       

var thisValue = "";

for (var i=0; i < numberOfNodes ; i++){
    thisValue  = oEyeColors.nodes.item(i).value;
    if(thisValue == null){
        thisValue = "";
    }
    xfa.resolveNode("Page1.eyeColorDropDownList").addItem(thisValue.toString());

}

这可行,但不是我正在寻找的解决方案。必须有一种 JavaScript 方法来设置下拉列表的 BindItems。

I need to pre-fill a dynamic PDF's fields so my users can edit it and submit back.

I am using Adobe ColdFusion CFPDFFORM tag that can load XML data into a PDF and make a new populated PDF. Unfortunately it also clears <xfa:datasets> tag, it completely empties it out! So all dropdownlists binded to datasets do not work. This is the code for binding one of them:

<bindItems ref="xfa.datasets.LOVFile.LOV.PreferenceLanguageList.PreferenceLanguage[*]" labelRef="$" valueRef="lic"/>

Since I have no control on how CFPDFFORM tag works, I came up with a workaround. Using LiveCycle Designer for codding, I store whatever data there is in <xfa:datasets> into a variable and load it to datasets at form::initialize.

This seems to load datasets fine, just like how they were before cfpdform messed them up. After loadXML() call , I can read the datasets and get identical results as in the original PDF with its datasets tag full of XML data.

form1::initialize - (JavaScript, client)
//xfa.host.messageBox("loading xml to datasets");
xfa.datasets.nodes.namedItem("LOVFile").loadXML(LOVFile_var.value,0,1);
Page1.Header.debug.rawValue = xfa.datasets.LOVFile.LOV.PreferenceLanguageList.resolveNode("PreferenceLanguage[2]").value;

The problem is down down lists still don't work, they have no item to show. Somehow their binding call to datasets does not refresh?

Is there anything else I should do after loadXML() ? LiveCycle reference for bindItems says "The links between the list items and the referenced data are active. Any change to the data causes an immediate update to the list items."

Any help or point to the right direction is greatly appreciated.

UPDATE:

using azathoth's answer I can add item to a dropdownlist using data from the newly loaded datasets (after loadXml() call).

var oEyeColors = xfa.datasets.LOVFile.LOV.resolveNode("EyeColorList");
var numberOfNodes = oEyeColors.nodes.length;       

var thisValue = "";

for (var i=0; i < numberOfNodes ; i++){
    thisValue  = oEyeColors.nodes.item(i).value;
    if(thisValue == null){
        thisValue = "";
    }
    xfa.resolveNode("Page1.eyeColorDropDownList").addItem(thisValue.toString());

}

This works but is not the solution I am looking for. There must be a JavaScript way to set bindItems of a dropdown.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗化ㄋ丶相逢 2024-12-04 00:54:45

我使用此代码执行您指定的操作:

xfa.datasets.loadXML(LOVFile_var.rawValue, false, false); 
xfa.datasets.saveXML();                                 
var yourXML = xfa.datasets.resolveNode("yourXMLRootNodeName");
var numberOfNodes = yourXML.nodes.length;       

for (var i=0; i < numberOfNodes ; i++)
    yourDropDown.addItem(yourXML.nodes.item(i).nodes.item(1).value); // this can change according to what you retrieve in your xml  

告诉我它是否适合您

I do what you specify with this code:

xfa.datasets.loadXML(LOVFile_var.rawValue, false, false); 
xfa.datasets.saveXML();                                 
var yourXML = xfa.datasets.resolveNode("yourXMLRootNodeName");
var numberOfNodes = yourXML.nodes.length;       

for (var i=0; i < numberOfNodes ; i++)
    yourDropDown.addItem(yourXML.nodes.item(i).nodes.item(1).value); // this can change according to what you retrieve in your xml  

Tell me if it worked for you

捂风挽笑 2024-12-04 00:54:45

也许这就是您正在寻找的?

使用 LiveCycle ES2.5 从后端数据源预填充动态 PDF 表单中的下拉列表

http://www.adobe.com/devnet/livecycle/articles/prepopulate-dropdown-lists.html

perhaps this is what you're looking for?

Pre-populating dropdown lists in dynamic PDF forms from a back-end data source using LiveCycle ES2.5

http://www.adobe.com/devnet/livecycle/articles/prepopulating-dropdown-lists.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文