We are using Aspose pdf latest version in .net code as below for PDF compare
Code.png (70.6 KB)
Expected as if text is added it should show in green or blue color and if deleted if should strike out in red as below image
Strike Image.png (48.6 KB)
Attaching both input pdfs for compare to this topic
Input2-AsposePDF.pdf (594.1 KB)
Input1-AsposePDF.pdf (499.0 KB)
Thanks
             
            
              
              
              
            
            
                
                
              
           
          
            
            
              @anurag.mudrakol
To compare two PDF documents and generate a report highlighting added and deleted text with specific colors (green or blue for added text and red for deleted text), you can use the Aspose.PDF library in .NET. Below is a sample code snippet that demonstrates how to achieve this:
using Aspose.Pdf;
using Aspose.Pdf.Text;
// Load the two PDF documents
Document pdf1 = new Document("Input1-AsposePDF.pdf");
Document pdf2 = new Document("Input2-AsposePDF.pdf");
// Create a TextAbsorber to extract text from the first document
TextAbsorber textAbsorber1 = new TextAbsorber();
pdf1.Pages.Accept(textAbsorber1);
string text1 = textAbsorber1.Text;
// Create a TextAbsorber to extract text from the second document
TextAbsorber textAbsorber2 = new TextAbsorber();
pdf2.Pages.Accept(textAbsorber2);
string text2 = textAbsorber2.Text;
// Compare the texts and generate a report
var differences = CompareTexts(text1, text2);
// Highlight differences in the PDF
foreach (var difference in differences)
{
    // Logic to highlight added and deleted text
    // Use Aspose.Pdf features to apply colors and strikethroughs
    if (difference.IsAdded)
    {
        // Highlight added text in green or blue
    }
    else if (difference.IsDeleted)
    {
        // Highlight deleted text in red
    }
}
// Save the comparison report
pdf1.Save("ComparisonReport.pdf");
In the above code, you will need to implement the CompareTexts method to identify added and deleted text. You can use string comparison techniques or libraries to find differences.
For highlighting, you can use the TextFragment class to apply formatting such as color and strikethrough.
This should help you create a comparison report as per your requirements.
             
            
              
              
              
            
            
                
                
              
           
          
            
            
              Thanks for update, We are comparing two PDFs and generating new output PDF which contains difference could you please provide code snip for strike out difference for newly created output PDF…
             
            
              
              
              
            
            
                
                
              
           
          
            
            
              @anurag.mudrakol
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFNET-60924
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.