I am trying to attach a database of some kind to a PDF for a seating chart. I have created a PDF of my company's floorplan with numbered textbox's overlayed on each cube in a grid pattern. I then have colored textboxes on top of the grid to represent an employee sitting there. I had a working solution(doc level scripts attached to buttons) but now would like to move to a OOP(global js code that's doc specific) approach with a database linked to the PDF itself. I have tried several methods of storing the data(json, txt, csv, xml) I am more unsure on how to access said data in the PDF programmatically. Attached is my chart code(what I have so far), and a text document with an example of my data from my xml file. I found a couple examples to follow but I am not 100% sure how to create a data object from an existing xml file then link it to a PDF document and read/write from it to update the data contained. If anyone has experience with this and can give me some pointers on best practices, that would be greatly appreciated.
*DISCLAIMER*
I am not well versed in JavaScript and have vibe coded my chart code. I plan to revise and rework my classes once I have a working solution to read/write data into the PDF.
*EXAMPLE 1*
Code: Select all
// get the file stream object of the attachment
var acrobat = this.getDataObjectContents("acrobat.xml");
// convert to a string
var cAcrobat = util.stringFromStream(acrobat, "utf-8");
// parse this and get XFAObject
var myXML = XMLData.parse(cAcrobat,false);
// change the value of grandad's income
myXML.family.grandad.personal.income.value = "300000";
// save XML document as string, cAcrobat
var cAcrobat = myXML.saveXML('pretty');
// convert to a file stream
var acrobat = util.streamFromString(cAcrobat, "utf-8");
// now "update" the attachment acrobat.xml with this file stream
this.setDataObjectContents("acrobat.xml", acrobat);
Code: Select all
function DumpDataObjectInfo(dataobj)
{
for (var i in dataobj)
console.println(dataobj.name + "[" + i + "]=" + dataobj[i]);
}
// Prompt the user for a data file to embed.
this.importDataObject("MyData");
DumpDataObjectInfo(this.getDataObject("MyData"));
// Embed Foo.xml (found in parent director for this doc).
this.importDataObject("MyData2", "../Foo.xml");
DumpDataObjectInfo(this.getDataObject("MyData2"));