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

Method to save persistent data within Document?

efos
Registered: Jan 8 2009
Posts: 63
Answered

I've got an XML file, structured thusly:

<root>
	<question name="PC1">
		<text>"Text1"</text>
		<textID>349</textID>
		<correctAnswer>"C"</correctAnswer>
		<remediateView></remediateView>
		<questionView></questionView>
	</question>
	<question name="PC2">
		<text>"Text2"</text>
		<textID></textID>
		<correctAnswer>"B"</correctAnswer>
		<remediateView></remediateView>
		<questionView></questionView>
	</question>
	<question name="PC3">
		<text>"Text3"</text>
		<textID></textID>
		<correctAnswer>"B"</correctAnswer>
		<remediateView></remediateView>
		<questionView></questionView>
	</question>
</root>

Lets just assume the structure is a-OK.

I want to bring this data into my PDF doc to feed data to my question remediation functions. As you can see, I already have the values for text and correctAnswer; I just need to populate the viewStates and the textID's from the finalized PDF document. I know I can get these via JS; that isn't my problem: I don't know how to make them hang around after I close the file.

I know when I embed flash files, I can attach resource files (like xml files); but how do I do I attach a resource for the doc itself? The user will not have this XML file, so it can't import at runtime, and shouldn't see it (so as an attachment is not an option unless I can protect and hide it).

So my problem is twofold: How do I get a predefined dataset into the PDF document; and how do I keep it there?

It seems like a simple proposition, but I imagine there are a lot of simple things I don't know about Acrobat. Maybe I'm looking too hard? I've had my face mashed against my monitor on the overall objective too long, so I really hope so.

efos
Registered: Jan 8 2009
Posts: 63
function getXML(s){var bXMLExists = falsevar sFilename = s+".xml"if(dataObjects){for (i = 0; i < dataObjects.length; i++){if (dataObjects[i].name == sFilename){bXMLExists = truevar streamFile = getDataObjectContents(sFilename)var utfFile = util.stringFromStream(streamFile,"utf-8")return XMLData.parse(utfFile)}}}if (!bXMLExists){createDataObject(sFilename,"<root/>")var streamFile = getDataObjectContents(sFilename)var utfFile = util.stringFromStream(streamFile,"utf-8")return XMLData.parse(utfFile)}} function setXML(v,s){var sFilename = s+".xml"var utfFile = v.saveXML('pretty');streamFile = util.streamFromString(utfFile, "utf-8");setDataObjectContents(sFilename, streamFile);var newUTF = utfFile.toString()while(newUTF.search(/\n/) != -1)newUTF = newUTF.replace(/\n/,"")}addScript("set"+s,"var xmlQuestions = XMLData.parse('"+newUTF+"',false)")}

getXML will reference the attached document, or create it if it doesn't exist, and return it as an XMLData object.

setXML takes that XMLData object and stuffs it back into the attached document so you can manually edit it; and strips out the line breaks and stores the data in a variable that you can call at runtime after you've deleted the attachment so the end user can't see it.

Works great for my purposes. I need to incorporate a lot of external data to make this type of document function, some of it developer generated at another stage in the process, some of it gathered from the PDF itself via js during the development process. With this I've been able to consolidate the rather kludgey process into a few simple script assisted steps.