Hi,
I am trying to compare two pdf using
private static void ComparingEntireDocuments()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentCompare();
// Open PDF documents
using (var document1 = new Aspose.Pdf.Document(dataDir + "ComparingEntireDocuments1.pdf"))
{
using (var document2 = new Aspose.Pdf.Document(dataDir + "ComparingEntireDocuments2.pdf"))
{
// Compare
Aspose.Pdf.Comparison.SideBySidePdfComparer.Compare(
document1,
document2,
dataDir + "ComparingEntireDocuments_out.pdf",
new Aspose.Pdf.Comparison.SideBySideComparisonOptions
{
AdditionalChangeMarks = true,
ComparisonMode = Aspose.Pdf.Comparison.ComparisonMode.IgnoreSpaces
});
}
}
}
but i am getting an error saying The type or namespace name ‘Comparison’ does not exist in the namespace ‘Aspose.Pdf’ (are you missing an assembly reference?). i am using aspose pdf version 24.1.0, can you please advise?
thanks,
@randomuser123
It looks like you’re encountering an issue with the Comparison
namespace in Aspose.Pdf. The error message indicates that the Comparison
class is not recognized, which could be due to a couple of reasons.
Diagnosis & Next Steps:
-
Check Version Compatibility: Ensure that the version of Aspose.Pdf you are using (24.1.0) supports the Comparison
namespace. This feature may have been introduced in a later version. I recommend upgrading to the latest version of Aspose.Pdf to access all the latest features and fixes.
-
Add Reference: Make sure that you have added the correct assembly reference in your project. If you’re using Visual Studio, you can do this by right-clicking on your project in the Solution Explorer, selecting “Add Reference,” and ensuring that the Aspose.Pdf assembly is included.
-
Using Directive: Ensure that you have the appropriate using
directive at the top of your code file:
using Aspose.Pdf.Comparison;
-
Alternative Comparison Method: If the Comparison
class is not available, consider using the GraphicalPdfComparer
class, which is designed for comparing PDF documents graphically. You can find more information about it in the Aspose documentation.
Here’s a minimal example of how to use GraphicalPdfComparer
:
using Aspose.Pdf;
using Aspose.Pdf.Comparison;
private static void ComparePdfDocuments()
{
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentCompare();
using (var document1 = new Document(dataDir + "ComparingEntireDocuments1.pdf"))
using (var document2 = new Document(dataDir + "ComparingEntireDocuments2.pdf"))
{
var comparer = new GraphicalPdfComparer();
comparer.CompareDocumentsToPdf(document1, document2, dataDir + "ComparisonResult.pdf");
}
}
Please try these steps and let me know if they resolve your issue or if you have any further questions!
@randomuser123
It seems that the reason you facing this issue is that Aspose.Pdf.Comparison was added in later versions. At least the error doesn’t occur in latest versions and present on version 24.1