用户故事: 作为用户,我希望能够将文档(通常为pdf)附加到pdf表单,因此我可以证明我已为某个订单项进行了必要的活动。
我通过以下javascript代码实现了这一目标,这些代码以pdf形式链接到按钮上的鼠标上移事件:
// JavaScript source code
// Initialize attachment number
attachment_num = 1;
// Initial location of file attachment icon
// The x value is incremented below
var oFAP = { x_init: 72, x: 72, y: 72 }; // Below lower-left corner of the page
if (app.viewerVersion < 11) {
if (app.viewerType === "Reader") {
app.alert({
cMsg: "You must user Reader version 11 or later to attach files to this form.",
cTitle: "Attach File Error",
nIcon: 3,
nType: 0
});
}
// Prompt user to import a file
app.alert({
cMsg: "Click the OK/Open button after selecting the file from your system that you want to attach.",
cTitle: "Attach File",
nIcon: 3,
nType: 0
});
try {
var rc = this.importDataObject("Attachment" + attachment_num);
if (rc) {
attachment_num += 1;
app.alert({
cMsg: "Attachment successful.\r\rOpen the Attachments panel to access the attached file(s).",
cTitle: "Attachment Successful",
nIcon: 3,
nType: 0
});
} else {
app.alert({
cMsg: "Attachment cancelled.",
cTitle: "Attachment Cancelled",
nIcon: 3,
nType: 0
});
}
} catch (e) {
app.alert({
cMsg: "Could not attach file.",
cTitle: "Could not attach file",
nIcon: 3,
nType: 0
});
}
} else {
try {
var annot = addAnnot({
page: event.target.page,
type: "FileAttachment",
author: "Form user",
name: "File Attachment",
point: [oFAP.x, oFAP.y],
contents: "File attachment on: " + util.printd("yyyy/mm/dd HH:MM:ss", new Date()),
attachIcon: "Paperclip"
});
annot.cAttachmentPath; // Prompt user to select a file to attach
oFAP.x += 18; // Increment the x location for the icon
} catch (e) {
app.alert({
cMsg: "Could not attach file.\r\rPlease report this error.",
cTitle: "File attachment error",
nIcon: 3,
nType: 0
});
}
}
这很好,我可以在附件侧栏中看到附件的文档。到目前为止没有问题!
用户故事(续):作为用户,我想附加表单的输出(以XML格式,但XFDF是可以接受的),以及我通过电子邮件上传到pdf的附件。
这是我遇到问题的地方。我可以使用以下代码将表单详细信息导出到电子邮件中(同样,附加到按钮上的鼠标向上事件):
var url = "mailto:testemail@xyz.com?subject=My Subject&body=Here is my form data.";
this.submitForm({cURL: url, cSubmitAs: "XFDF"})
我在Adobe论坛或StackOverflow上找不到如何将附件文档添加到电子邮件中。我认为逻辑是“复制“附件列表”中的所有附件,并将其添加为电子邮件附件”,但我确实对如何做到这一点感到困惑。我确实尝试了以下代码,但我认为这更多与提交到Web服务器而不是电子邮件有关:
var oParent = event.target;
// Get the list of attachments:
var oDataObjects = oParent.dataObjects;
if (oDataObjects == null)
app.alert("This form has no attachments!");
else {
// Create the root node for the global submit:
var oSubmitData = oParent.xfa.dataSets.createNode(
"dataGroup",
"globalSubmitRootNode"
);
// Iterate through all the attachments:
var nChildren = oDataObjects.length;
for (var iChild = 0; iChild < nChildren; i++) {
// Open the next attachment:
var oNextChild = oParent.openDataObject(
oDataObjects[iChild].name
);
// Transfer its data to the XML collection:
oSubmitData.nodes.append(
oNextChild.xfa.data.nodes.item(0)
);
//close the attachment
oNextChild.closeDoc();
}
// Submit the XML data collection to the server
oParent.submitForm({
cURL: "mailto:testemail@qoppa.com?subject=My Subject&body=Here is my form data.",
cSubmitAs: "XML",
oXML: oSubmitData
});
}
如果有人能够提供一些见解,使我可以将所附的文档从PDF表单转移到this.submitform
声明所创建的电子邮件中,我将万分感谢!
非常感谢!