Hello, I am working with an automation script that compares PDF files using PDFBox. The script has been written for v1.8. We'd like to upgrade the script to v2.0. I attempted to do this myself using the migration guide but ran into issues along the way. I've attached the script above (just a function). Hoping to get some input as to what primary changes need to happen. As a side note, this is in Javascript and this is written to be used in TestComplete (full set of scripts can be found here: https://support.smartbear.com/articles/testcomplete/testing-pdf-files-with-testcomplete).
Thank you, Evan Stansel // Get the total number of pages in both documents totalPages_1 = docObj_1.getNumberOfPages(); totalPages_2 = docObj_2.getNumberOfPages(); // Check whether the documents contain the same number of the pages if (totalPages_1 != totalPages_2) { Log.Message("The documents contain different number of pages."); } else { for (i = 0; i < totalPages_1; i++) { // Call a routine that converts the specified page to an image pic_1 = convertPageToPicture(docObj_1, i, imgFile_1); pic_2 = convertPageToPicture(docObj_2, i, imgFile_2); // Compare two images if (!pic_1.Compare(pic_2, false, 5, false, 5, maskImg)) { // If the images are different... // Post image differences to the log Log.Picture(pic_1.Difference(pic_2, false, 5, false, 5, maskImg)); // Post a warning message Log.Warning("Pages " + aqConvert.IntToStr(i+1) + " are different. Documents are different."); // Break the loop break; } else { // Post a message that the pages are equal Log.Message("Pages " + aqConvert.IntToStr(i+1) + " are equal.") } // Delete the temporary image files aqFile.Delete(imgFile_1); aqFile.Delete(imgFile_2); } } } function convertPageToPicture(docObj, pageIndex, fileName) { var pageObj, imgBuffer, imgFile, imgFormat, pictureObj; // Get the desired page pageObj = getPage(docObj, pageIndex); // Convert the page to image data imgBuffer = pageObj.convertToImage(); // Create a new file to save imgFile = JavaClasses.java_io.File.newInstance(fileName); // Get the image format from the name imgFormat = aqString.SubString(fileName, aqString.GetLength(fileName)-3, 3); // Save the image to the created file JavaClasses.javax_imageio.ImageIO.write(imgBuffer, imgFormat, imgFile); // Create a Picture object pictureObj = Utils.Picture; // Load the image as a picture pictureObj.LoadFromFile(fileName); // Return the picture object return pictureObj; }