Stripping data of pdf files - used to work, now has error "Object doesn't support this action"
I have the below script (written by an engineer that left 3 months ago), that was used to strip data from a pdf file, for the purposes of verifying that the contents are as expected. It always worked without errors. A few weeks ago (the script was never changed) it stopped working, and I get an error: "Object doesn't support this action".
Stepping through the debugger, the error comes from the below line:
"
var docObj =JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_3(strFileName);
"
I have searched, and I have trouble finding any information on ".load_3". Changing it to "load" causes the same error.
The code seems to invoke a Java function, and as we all know, JAVA updates automatically.
Just wondering, has anyone had any experience with this JAVA function, or could explain why the sudden break?
The full stripping script is below:
"
// Strips and returns text from a pdf file in C:\ called rpt.pdf
function stripText()
{
try{
//var strFileName = Sys.OleObject("WScript.Shell").SpecialFolders("Desktop") + "\\rpt.pdf"; //"C:\\Users\\rnd.AU\\Desktop\\rept.pdf";
var strFileName = ProjectSuite.Variables.XCEL_PATH + "\\rpt.pdf";
Log.Message(strFileName);
// var doc=JavaClasses.
// Load the PDF file to the PDDocument object
var docObj =JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_3(strFileName);
// SUDDEN ISSUE WITH THE ABOVE LINE
// Create text stripper object
var textStripperObj = JavaClasses.org_apache_pdfbox_util.PDFTextStripper.newInstance();
// strip text from the entire document
var text = textStripperObj.getText_2(docObj);
// Voila!
Log.Message("Text from rpt.pdf stripped...");
Log.Message (text);
return(text);
}
catch (e){
Log.Error(e.description);
}
}
"
The file "pdfbox-app-1.8.8.jar" was reloaded (in case it was corrupted), and this did not solve the issue.
Issue was eventually solved.
Step 1.
Updated the JRE (Java Runtime Environment) to the latest version.
Step 2.
In the Menu Bar, select "Tools", then "Options". Go to "Engines", then "Java Bridge".
Select the latest JVM (java Virtual Machine) path. See picture "TestComplete-JAVA-Bridge-B.JPG".Step 3.
Under the Project "Properties", "java Bridge", both the "Java Classes" and the "Class Paths" were deleted, then reloaded. See picture "TestComplete-JAVA-Bridge.JPG".These two steps fixed the issue.
Test Complete does not automatically JVM path after a Java update.