def image_compare(image1, image2): differ_data = rmsdiff_2011(image1, image2) differ_data2 = rmsdiff_2011(image1, image1) if "Warning" in str(differ_data): lib.write_log("Page: [", env.current_page_of_png, "] => Warning! Message = [", differ_data, "]") else: if abs(differ_data - differ_data2) == 0: lib.write_log( "Page: [", env.current_page_of_png, "] => Same! Differ Number = [", abs(differ_data - differ_data2), "]" ) else: lib.write_log( "Page: [", env.current_page_of_png, "] => Different! Differ Number = [", abs(differ_data - differ_data2), "]", ) # print "Page: ", env.current_page_of_png, " => ", differ_data, differ_data2, abs(differ_data - differ_data2) print "Page: ", env.current_page_of_png, differ_data, differ_data2 generate_compare_image(image1, image2)
def pdfdiffer(pdf1, pdf2, result, cut, left, top, right, bottom): if not os.path.exists(result): os.makedirs(result) pdf1_pages = PdfFileReader(open(pdf1, "rb")).getNumPages() pdf2_pages = PdfFileReader(open(pdf2, "rb")).getNumPages() env.result_folder = result env.min_of_pdf_page_numbers = min(pdf1_pages, pdf2_pages) if pdf1_pages != pdf2_pages: lib.write_log("PDF Page Number is Different: [%s] VS [%s]" % (pdf1_pages, pdf2_pages)) else: lib.write_log("PDF Total Pages: [%s]" % (pdf1_pages)) p1 = Process(target=split_pdf_to_images, args=(pdf1, result, cut, left, top, right, bottom, min(pdf1_pages, pdf2_pages))) p2 = Process(target=split_pdf_to_images, args=(pdf2, result, cut, left, top, right, bottom, min(pdf1_pages, pdf2_pages))) p1.start() p2.start() p1.join() p2.join() print("finished multi process.") for i in range(env.min_of_pdf_page_numbers): env.current_page_of_png = i + 1 pdf1_name = os.path.basename(pdf1) pdf2_name = os.path.basename(pdf2) image1 = os.path.join(result, "P" + str(i+1) + "." + ".".join(pdf1_name.split(".")[:-1]) + ".png") image2 = os.path.join(result, "P" + str(i+1) + "." + ".".join(pdf2_name.split(".")[:-1]) + ".png") image_compare(image1, image2) lib.write_log("END")