DocumentComparer 1.0.0
dotnet add package DocumentComparer --version 1.0.0
NuGet\Install-Package DocumentComparer -Version 1.0.0
<PackageReference Include="DocumentComparer" Version="1.0.0" />
paket add DocumentComparer --version 1.0.0
#r "nuget: DocumentComparer, 1.0.0"
// Install DocumentComparer as a Cake Addin #addin nuget:?package=DocumentComparer&version=1.0.0 // Install DocumentComparer as a Cake Tool #tool nuget:?package=DocumentComparer&version=1.0.0
DocumentComparer
A .NET Library for Comparing Text, DOCX, and PDF Files
DocumentComparer is a lightweight and flexible .NET library designed to compare text-based files (including .txt
, .docx
, and .pdf
) and return the differences in various formats such as JSON, XML, and HTML (with a GitHub-like diff view).
Features
- Compare text (
.txt
), Microsoft Word documents (.docx
), and PDF files (.pdf
). - Get the differences between two documents, including:
- Additions, deletions, and modifications.
- Start and end indices of changes.
- Output formats:
- JSON: Structured output for easy parsing.
- XML: Structured and serialized comparison results.
- HTML: GitHub-style visual representation of changes.
- Efficient line-by-line comparison with support for character-level differences.
Installation
You can install the DocumentComparer package via NuGet Package Manager Console:
Install-Package DocumentComparer
Or via .NET CLI:
dotnet add package DocumentComparer
Usage
1. Basic Document Comparison
You can compare two files of different formats, such as .txt
, .docx
, or .pdf
, and get the differences in JSON format:
using DocumentComparisonLib;
var comparer = new DocumentComparer();
string result = comparer.CompareDocuments("path/to/file1.txt", "path/to/file2.docx", "json");
Console.WriteLine(result);
2. Output Options
JSON Output (default):
var result = comparer.CompareDocuments("path/to/file1.txt", "path/to/file2.pdf", "json");
XML Output:
var result = comparer.CompareDocuments("path/to/file1.txt", "path/to/file2.pdf", "xml");
HTML Output (GitHub-style diff):
var result = comparer.CompareDocuments("path/to/file1.txt", "path/to/file2.pdf", "html");
4. Supported Formats
- Text Files (
.txt
) - Word Documents (
.docx
) - PDF Documents (
.pdf
)
Example Project
Here’s an example of how you can use the library in a .NET console application:
using DocumentComparisonLib;
class Program
{
static void Main(string[] args)
{
var comparer = new DocumentComparer();
// Comparing two documents with HTML output
string result = comparer.CompareDocuments("document1.pdf", "document2.docx", "html");
// Save the result to an HTML file
File.WriteAllText("comparison_result.html", result);
Console.WriteLine("Comparison completed and saved as comparison_result.html");
}
}
Contributing
Contributions are welcome! If you'd like to contribute to the project:
- Fork the repository.
- Create your feature branch (
git checkout -b feature/AmazingFeature
). - Commit your changes (
git commit -m 'Add some AmazingFeature'
). - Push to the branch (
git push origin feature/AmazingFeature
). - Open a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
Contact
If you have any questions or need help, feel free to contact me via GitHub or submit an issue in the repository.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- DocumentFormat.OpenXml (>= 3.1.1)
- itext7 (>= 8.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 122 | 10/19/2024 |