Results 1 to 10 of 10
  1. #1
    kris_java is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default Compare 2 pdf files

    Hi everyone,

    How to compare 2 pdf files using java.....


    thank u,
    kris

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Is that a byte by byte comparison for equal or not equal?
    Read byte by byte and compare the two bytes.

  3. #3
    kris_java is offline Member
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default

    Hi everybody,

    thank u very much for your feedback i got a solution for it.

    thank you,
    Kris

  4. #4
    sudhishmathew is offline Member
    Join Date
    Mar 2011
    Location
    Bangalore, India
    Posts
    3
    Rep Power
    0

    Default Your Suggestions

    Hi Kris,

    Please give some ideas on how comparing PDF's using Java can be achieved. We have a requirement of comparing PDF's and identify the following,

    1) Changed lines
    2) Deleted lines
    3) New lines
    4) Retain the existing lines

    Thanks and Regards,
    Sudhish.

  5. #5
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Smile

    Hi Sudhish,

    You can use any open source pdf reader (like PDFBox) to read the contents of two pdf documents.

    Once you get the contents out of pdf, it would be your logic as to how do you compare those contents, maybe line-by-line or block-by-block.

  6. #6
    sudhishmathew is offline Member
    Join Date
    Mar 2011
    Location
    Bangalore, India
    Posts
    3
    Rep Power
    0

    Default

    Hi lovelesh,

    Thanks a lot for the suggestion, I am currently evaluating PDFBox and have the following queries,

    1) Have you used PDFBox
    2) How can one get Line number information of a PDF using PDFBox

    Best Regards,
    Sudhish.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    I bet that PDFbox comes with documentation ... read it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    sudhishmathew is offline Member
    Join Date
    Mar 2011
    Location
    Bangalore, India
    Posts
    3
    Rep Power
    0

    Default

    Below is what i am trying, which unfortunately does not work as intended. "tokens" List does not have any "NextLine" operator. Any ideas on improving this,

    PDDocument document = PDDocument.load(fileName);
    List<PDPage> allPages = document.getDocumentCatalog()
    .getAllPages();
    for (PDPage pdPage : allPages) {
    PDFStreamParser parser = new PDFStreamParser(pdPage
    .getContents());
    List<Object> tokens = parser.getTokens();
    for (Object token : tokens) {
    if (token instanceof PDFOperator) {
    PDFOperator op = (PDFOperator) token;
    //T* = org.apache.pdfbox.util.operator.NextLine
    if (op.getOperation().equals("T*")){

    }
    }
    }
    }
    Last edited by sudhishmathew; 04-12-2011 at 04:03 AM.

  9. #9
    lovelesh is offline Senior Member
    Join Date
    Nov 2010
    Location
    Delhi
    Posts
    135
    Blog Entries
    1
    Rep Power
    0

    Smile

    Please go through this example code.
    PDF Text Parser: Converting PDF to Text in Java using PDFBox

    You will need to fine tune it as per your requirement.

  10. #10
    maheshmaka is offline Member
    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Default Re: Compare 2 pdf files

    Quote Originally Posted by kris_java View Post
    Hi everybody,

    thank u very much for your feedback i got a solution for it.

    thank you,
    Kris
    Can please provide me the solution for this.


    Thanks
    Mahesh.M

Similar Threads

  1. compare arrays
    By innspiron in forum New To Java
    Replies: 4
    Last Post: 04-16-2010, 10:22 PM
  2. Compare 2 large files
    By bezudar in forum Advanced Java
    Replies: 3
    Last Post: 11-23-2008, 02:18 AM
  3. How to Compare two Dates
    By Java Tip in forum java.util
    Replies: 1
    Last Post: 06-24-2008, 07:05 AM
  4. Compare lists
    By JavaNoob in forum New To Java
    Replies: 2
    Last Post: 08-08-2007, 03:11 PM
  5. Compare 2 XML
    By Peter in forum XML
    Replies: 1
    Last Post: 07-05-2007, 02:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •