Import data from Excel to PDF form using Javascript
Hello Everyone,
I need to import some data from an excel with at least 250 rows, and 7 columns.
the first try was saving the document as tab delimited and then open and import the data manually from Adobe, IT WORKS.
now i need a step more, doing it automatically with all the rows.
I've found an user which has a solution in his page: Batch-Import Excel Data into PDF Forms - KHKonsulting LLC
he used this code to explain how to do it:
// specify the filename of the data file
var fileName = "/Users/username/tmp/data.txt"; // the tab delimited text file containing the data
var outputDir = "/Users/username/tmp/"; // make sure this ends with a '/'
var err = 0;
var idx = 0;
while (err == 0) {
err = this.importTextData(fileName, idx); // imports the next record
if (err == -1)
app.alert("Error: Cannot Open File");
else if (err == -2)
app.alert("Error: Cannot Load Data");
else if (err == 1)
app.alert("Warning: Missing Data");
else if (err == 2)
app.alert("Warning: User Cancelled Row Select");
else if (err == 3)
app.alert("Warning: User Cancelled File Select");
else if (err == 0) {
this.saveAs(outputDir + this.getField("Text1").value + "_" + this.getField("Text2").value + ".pdf"); // saves the file
idx++;
}
}
i tried the same solution (changing something) to my problem.
the path to my files was:
var file = "/c/Users/usuario/Desktop/folder/data.txt";
var fileOut = "/c/Users/usuario/Desktop/folder/"
the scripts fails with the error = -2 Cannot open File
whats wrong?
thank you all and sorry if i didn't explain well.
