These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

adding pdf attachment wıth js

otk80
Registered: May 6 2008
Posts: 11

Having one attachment(lets say a fillable pdf template) in the attachment tab; I would like to make a copy of it; push some data to the copy and display data populated pdf.

I tried to use doc.createDataObject, doc.getDataObjectContents and doc.setDataObjectContents funtions. But it was no success. The thing is, the file attachment is created but the contents, as a stream, are not set to pdf correctly. But when i tried to create a text file with the same fuction everything is ok.

How can I achieve copying an existing attahment?

My Product Information:
Reader 7.0.5, Windows
efos
Registered: Jan 8 2009
Posts: 63
I have done something like this with XML files;

function getXML(s){var bXMLExists = falsevar sFilename = s+".xml"if(cDoc.dataObjects){for (i = 0; i < cDoc.dataObjects.length; i++){if (cDoc.dataObjects[i].name == sFilename){bXMLExists = truevar streamFile = cDoc.getDataObjectContents(sFilename)var utfFile = util.stringFromStream(streamFile,"utf-8")return cDoc.XMLData.parse(utfFile)}}}if (!bXMLExists){console.println(s+"Does not exist")cDoc.createDataObject(sFilename,"<root/>")var streamFile = cDoc.getDataObjectContents(sFilename)var utfFile = util.stringFromStream(streamFile,"utf-8")return cDoc.XMLData.parse(utfFile)}} function setXML(s){sFilename = String(s+".xml")utfFile = cDoc[s].saveXML('pretty');streamFile = util.streamFromString(utfFile, "utf-8");cDoc.setDataObjectContents(sFilename, streamFile);var newUTF = utfFile.toString().replace(/\n/g,"").replace(/\"/g,"\\\"") cDoc.addScript('set'+s,'function set'+s+'(){  '+s+' = XMLData.parse("'+newUTF+'",true)}')//cDoc.addScript("set"+s,"function set"+s+"(){  "+s+" = XMLData.parse(<b><a/></b>,true)}")}

This is a folder level script I use in concert with some other utility functions; one of which sets 'cDoc' to the current document. You'll probably want to change 'cDoc' to 'this'

var myData = getXML("myData")
sets myData to an XFA object equal to the attached XML.

setXML("myData")
converts the XML data to a string, saves it back, and creates a function 'setmyData' which sets 'myData' to the xml data. (Thus allowing you to delete the XML attachment without losing the data).

Now is this the method you are using, but doesn't work; or might this work for you?