Issue with Comparing PDF Files Using Aspose Library

Hi Team,

I am encountering an error while comparing two PDF files using the Aspose Library. However, comparing DOCX files works fine without any issues.

The error message is as follows:
Exception in thread “main” com.aspose.words.UnsupportedFileFormatException: PDF format is not supported on this platform. Use .NET Standard or .NET 4.6.1 or greater version of Aspose.Words for loading PDF documents.
I am currently using the following JAR file: “aspose-words-24.9-jdk17.jar”

Code:

public class DocumentComparisonAspose {

	public static void main(String[] args) throws Exception {
		// Load the original and revised documents
		Document original = new Document("./src/main/resources/doc_v1.pdf");
		Document revised = new Document("./src/main/resources/doc_v2_pdf.pdf");

		// Perform comparison
		compareDocuments(original, revised);
	}

	public static void compareDocuments(Document original, Document revised) throws Exception {
		// Specify the author of changes
		String author = "User";

		// Compare documents
		//original.compare(revised, author, new java.util.Date());
		
		CompareOptions options = new CompareOptions();
		options.setIgnoreFormatting(true); // Ignore formatting changes
		options.setIgnoreCaseChanges(true); // Ignore case changes
		options.setIgnoreTables(true); // Ignore table differences

        
		original.compare(revised, "AuthorName", new java.util.Date(), options);
		
		RevisionOptions revisionOptions = original.getLayoutOptions().getRevisionOptions();
        revisionOptions.setInsertedTextColor(RevisionColor.DARK_YELLOW); // Color for insertions
        revisionOptions.setDeletedTextColor(RevisionColor.RED);          // Color for deletions
        revisionOptions.setRevisedPropertiesColor(RevisionColor.DARK_YELLOW); 
		// Customize revision display options (e.g., color coding)
        

		// Save the comparison result
		original.save("OutputAspose.pdf");
		System.out.println("Comparison completed. Result saved.");
	}

}
Error:
Exception in thread "main" com.aspose.words.UnsupportedFileFormatException: Pdf format is not supported on this platform. Use .NET Standard or .NET 4.6.1 or greater version of Aspose.Words for loading Pdf documents.
	at com.aspose.words.zzYK1.zzW8u(Unknown Source)
	at com.aspose.words.Document.zzYQ9(Unknown Source)
	at com.aspose.words.Document.zzZy(Unknown Source)
	at com.aspose.words.Document.<init>(Unknown Source)
	at com.aspose.words.Document.<init>(Unknown Source)
	at com.standalone.my_Aspose.DocumentComparisonAspose.main(DocumentComparisonAspose.java:9)

@munish.singla Unfortunately loading PDF documents is not supported in java version of Aspose.Words. This feature is supported in .NET and Python versions. Implementation of this feature WORDSJAVA-2511 in java has been postponed and is not yet scheduled for development.

Hi @alexey.noskov
What other formats are supported by Aspose.Words in Java? Does it support formats like .ppt and .excel?
Additionally, which formats are supported by Aspose.Words in Python apart from .pdf and .docx?

Which version of Aspose.Words would you recommend for implementation in ServiceNow? Should we use Java, Python, or .NET? Which platform receives more frequent updates and advanced features?

@munish.singla You can find a list of supported document formats in our documentation.
for java:
https://docs.aspose.com/words/java/supported-document-formats/
and for Python:
https://docs.aspose.com/words/python-net/supported-document-formats/

All Aspose.Words versions are updated regularly. We publish releases each month. The main Aspose.Words version is .NET. The code then is ported to Java to build a Java version. Python version is a wrapper of a special .NET version build.

Hi @alexey.noskov

As you mentioned the main version is .NET and later you port to Java. So why can’t you port pdf to pdf comparison for Java? In ServiceNow, we need Java APIs for comparison and support for both the feature .pdf and .docx at least.

@munish.singla Unfortunately, PDF document loading module is not auto-portable now. So at the moment Java version does not have this feature.

Hi @alexey.noskov

We can internally build a Python API for PDF-to-PDF comparison, right?
Could you provide an example of how this can be done?
It will use the same .jar file, correct?

Also, we need a single license for the code, whether it’s in Java, .NET, or Python, right? It’s our choice which API we want to use, correct?

@munish.singla

No, it is not right. Aspose.Words for .NET, Aspose.Words for Java and Aspose.Words for Python are different products and require different licenses.

You can find the code for document comparison in Python here:
https://docs.aspose.com/words/python-net/compare-documents/