Hi, I have scripts which compare PDF files which have been working for awhile, but have suddenly stopped. The script converts each page in a PDF into images which it then compares. I've noticed that this script is now converting all PDFs into blank images. I have upgraded Java recently, but I see the same behavior after reverting my Java version. I've tried Java 8, Java 17 SDK, and Microsoft OpenJDK 17.
I've provided the code being used to compare the PDFs to the bottom of this email. As a side note, I've attempted to upgrade PDFBox to the latest version in the past but I've gotten stuck on some of the migration steps. I could definitely use some advice in how to convert this script to work with the latest .jar files. I also want to mention that I'm not a developer myself. I inherited this code and I am tasked with getting it working again. I can follow most javascript enough for scripting but I am very much a novice. Thank you to anyone that can help me here. Evan ========================CODE======================= function ComparePDFs(baseline, output, maskImg) { try { var docObj_1, docObj_2, totalPages_1, totalPages_2, result; totalPages_1 = getTotalPages(baseline); totalPages_2 = getTotalPages(output); for (i = 0; i < totalPages_1; i++) { pic_1 = convertPageToPicture(baseline, i); pic_2 = convertPageToPicture(output, i); // 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_2, "Output Picture", "The output was found at: " + output + "."); Log.Picture(pic_1, "Baseline Picture", "The baseline can be found at " + baseline + "."); Log.Picture(pic_1.Difference(pic_2, false, 5, false, 5, maskImg), "Comparison Result Image", "The baseline can be found at: " + baseline + "."); // Post an error message Log.Error("The PDFs are NOT equal."); delete pic_1; delete pic_2; break; } // Post a message that the pages are equal Log.Picture(pic_2, "Output Picture", "The output was found at: " + output + "."); Log.Picture(pic_1, "Baseline Picture", "The baseline can be found at " + baseline + "."); Log.Picture(pic_1.Difference(pic_2, false, 5, false, 5, maskImg), "Comparison Result Image", "The baseline can be found at: " + baseline + "."); Log.Checkpoint("The PDF Pages are equal.", "The baseline can be found at: " + baseline + "."); } } catch(e) { Log.Error(e); Log.Error("There was an error comparing the PDFs."); } } function getTotalPages(pdfFile) { var docObj = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_3(pdfFile); totalPages = docObj.getNumberOfPages(); docObj.close(); return totalPages; } function convertPageToPicture(pdfFile, pageIndex) { var pageObj, imgBuffer, imgFile, imgFormat, pictureObj, fileName; fileName = "C:\\Users\\" + Sys.UserName + "\\AppData\\Local\\Temp\\tempImage.jpg"; // Get the desired page pageObj = getPage(pdfFile, pageIndex); try { imgBuffer = pageObj.convertToImage(); } catch(e) { Log.Error(e); Log.Error("Unable to convert the file " + pdfFile + " into an image. ABORT!"); } if (pageObj.getResources() != null) { pageObj.getResources().Clear(); } // 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 try { JavaClasses.javax_imageio.ImageIO.write(imgBuffer, "jpg", imgFile); } catch(e) { Log.Error(e); Log.Error("Unable to write the file to " + fileName + "."); } // Create a Picture object pictureObj = Utils.Picture; // Load the image as a picture pictureObj.LoadFromFile(fileName); aqFileSystem.DeleteFile(fileName); imgBuffer.Flush(); return pictureObj; } ComparePDFs(pdf1.pdf, pdf2.pdf); =================================================