Click here to Skip to main content
14,240,969 members
Rate this:
Please Sign up or sign in to vote.
See more:
Compare 2 pdfs and need to know differences

Hi Folks,

I am building an application that would compare two pdfs and show me differences:
Here I am confused how to store data and show it to user
private bool FileCompare(string file1, string file2)
{
int file1byte;
int file2byte;
FileStream fs1;
FileStream fs2;
 
// Determine if the same file was referenced two times.
if (file1 == file2)
{
// Return true to indicate that the files are the same.
return true;
}
 
// Open the two files.
fs1 = new FileStream(file1, FileMode.Open);
fs2 = new FileStream(file2, FileMode.Open);
 
// Check the file sizes. If they are not the same, the files 
// are not the same.
if (fs1.Length != fs2.Length)
{
// Close the file
fs1.Close();
fs2.Close();
 
// Return false to indicate files are different
return false;
}
 
// Read and compare a byte from each file until either a
// non-matching set of bytes is found or until the end of
// file1 is reached.
do
{
// Read one byte from each file.
file1byte = fs1.ReadByte();
file2byte = fs2.ReadByte();
}
while ((file1byte == file2byte) && (file1byte != -1));
 
// Close the files.
fs1.Close();
fs2.Close();
 
// Return the success of the comparison. "file1byte" is 
// equal to "file2byte" at this point only if the files are 
// the same.
return ((file1byte - file2byte) == 0);
}
 
private void PdfCompare_Load(object sender, EventArgs e)
{
 
}
 
private void button1_Click(object sender, EventArgs e)
{
if (FileCompare(this.textBox1.Text, this.textBox2.Text))
{
MessageBox.Show("Files are equal.");
}
else
{
MessageBox.Show("Files are not equal.");
} 
}

}


Can you please help me on this?

Thank you!!
Posted
Updated 7-Jul-14 9:01am
v3
Comments
   
What is the problem here?
apr1234 3-Jul-14 11:15am
   
In the above code I am able to justify that pdf content is same/not. But I also want to see differences in both the Pdf files.. For example like
http://www.adobe.com/products/acrobat/file-compare-two-pdf-files.html
   
So, when you find the difference, you need to store that somewhere and after getting all difference, analyze those. But I am not sure of how to do that.
apr1234 7-Jul-14 14:58pm
   
That's fine...The content u wrote is the thing I already wrote in my question...
But it's okay I found some solution for it!!
   
Ok. Cool. :)
joshrduncan2012 3-Jul-14 9:25am
   
Please reply to Tadit's comment, otherwise, he won't get notified that you left him a message. Creating a new thread won't notify him of your reply to his comment.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,
You can try using iTextSharp library-
Create/Read Advance PDF Report using iTextSharp in C# .NET[^]
   
Comments
apr1234 7-Jul-14 13:47pm
   
Wow.. This is wonderful Article....
Thanks for the post!!
But I am looking for the comparison of the text in PDF!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100