compare two pdf files (approach) using java [closed]

两盒软妹~` 提交于 2019-12-08 12:23:07

问题


i need to write a java class that compares two pdf files and points out the differences(differences in text/position/font) using some sort of highlighting. my initial approach was use pdfbox to parse the file using pdfbox and store the extracted text using in some data structure that would help me with comparing. Is there any java library that can extract the text,preserve the formatting,help me with indexing and comparing.Can i use tika/ google's diff-match for this. tika extracts text in the form of xhtml but how can i compare two xhtml files?


回答1:


I had to compare tons of pdf files in my project. my requirement was to compare the pdf files by pixel by pixel. After a lot of googling and as i could not find anything good, I ended up creating my own pdf utility for this purpose.

Please check this blog for more details & jar download.

http://www.testautomationguru.com/introducing-pdfutil-to-compare-pdf-files-extract-resources/




回答2:


As you mentioned, pdfbox to extract its contents and then use google's diff to compare.




回答3:


Check this post on comparing PDF documents. Take note of the line;

PDF is a flexible file format in which you can do things in many different ways. So you could create 2 different PDF versions of a file using Acrobat and Ghostscript (as an example). The files would (hopefully) be identical. But the files would be different sizes and the internal structure of each would be very different




回答4:


I don't know if you were able to solve your problem. Here is my approach to solve this.

First let's convert PDFs to HTMLs using Pdf2dom and then use daisydiff to generate comparison report in HTML. If you want a PDF then convert that HTML report to PDF. But keep in mind that PDF to HTML conversion is not 100% accurate due to complexities in PDF. You can also try another approach of converting PDFs to images and compare pixel to pixel and generate a PDF report. You can try PDFcompare library. It looks promising to me. Let me know if anyone already tried this.




回答5:


Refer the below given sample code for pdf comparison.

ZPDFCompare obj = new ZPDFCompare();
obj.pdfcompare("C:\\Users\\Desktop\\expectedFile.pdf", "C:\\Users\\Desktop\\actualFile.pdf", "C:\\Users\\Desktop\\expectedFile_Diff.pdf","C:\\Users\\tarun.kumar\\Desktop\\actualFile_Diff.pdf");

zeonpad provided the free java api for pdf comparison.



来源:https://stackoverflow.com/questions/18225774/compare-two-pdf-files-approach-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!