Skip to main content
Participating Frequently
January 30, 2025
Question

Export PDF form error message of missing data using javascript

  • January 30, 2025
  • 3 replies
  • 1750 views

Hello all,

I have a pdf form that using javascript imports data from a txt file , populates the form and then exports each form as a PDF, then gets the next line of data , exports again etc etc . Now when i go to use it i get a missing data error even though i havent changed anything . Please help, code below 

 

// specify the filename of the data file
var fileName = "/C/Docs/Book.txt"; // the tab delimited text file containing the data
var outputDir = "/C/Jobcard/";    // 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 == -3)
// We are not reporting this error because it does
// indicate the end of our data table: We've exhausted
// all rows in the data file and therefore are done with
// processing the file. Time to exit this loop. 
// app.alert("Error: Invalid Row");
else if (err == 1)
app.alert("Warning: User Cancelled File Select");
else if (err == 2)
app.alert("Warning: User Cancelled Row Select");
     else if (err == 3)
app.alert("Warning: Missing Data");
else if (err == 0) {
event.target.display = display.hidden;
this.saveAs(outputDir + this.getField("Activity ID").value + "_" + this.getField("Order No").value + ".pdf").this.removeField("JobCard");
    // saves the file
idx++;
}
}

 

 

 

 

3 replies

dean_6492Author
Participating Frequently
January 31, 2025

Thanks again for your patience heres the first line (of many) in the txt data file :

Supplier               Activity ID            Order No           Activity Description
DEERING            TOSMWL081         S554900            30 M main engine heat exchanger service

All headings above match the PDF form Name of the text field but stops after loading this information 

Thom Parker
Community Expert
Community Expert
January 31, 2025

Did you check the console window (Ctrl-J) for errors?

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
dean_6492Author
Participating Frequently
January 31, 2025

Yes i used to use that , but work "upgraded" so i dont have pro anymore only  Standard 2024

Thom Parker
Community Expert
Community Expert
January 31, 2025

So 3 is returned when there is a column on the form that does not match a field name. The data is still imported, but it's letting you know that some data did not get imported. 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Thom Parker
Community Expert
Community Expert
January 31, 2025

There is probably something wrong with your data file. . 

 

However, there is an error in your code. 

On the saveAs line:

this.saveAs(...).this.removeField("JobCard");

 

The saveAs function return "undefined" so adding .this.removeField("JobCard"); is an error 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
dean_6492Author
Participating Frequently
January 31, 2025

Thanks Thom , removing it doesnt change anything , the issue is the form grabs the first line of the txt file and populates the form without issue , txt file has 5 lines only for testing , stops after the first line and still fails to create the PDF in the required folder . When working i use to be able to populate 200 pdfs in one click