Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
すべての比較ツールはAspose.PDF.Drawingライブラリで利用可能です。
PDF文書を扱う際、2つの文書の内容を比較して違いを特定する必要がある場合があります。Aspose.PDF for .NETライブラリは、この目的のために強力なツールセットを提供します。この記事では、いくつかの簡単なコードスニペットを使用してPDF文書を比較する方法を探ります。
Aspose.PDFの比較機能を使用すると、2つのPDF文書をページごとに比較できます。特定のページまたは全体の文書を比較することを選択できます。結果として得られる比較文書は、違いを強調表示し、2つのファイル間の変更を特定しやすくします。
Aspose.PDF for .NETライブラリを使用してPDF文書を比較する方法のリストは次のとおりです。
特定ページの比較 - 2つのPDF文書の最初のページを比較します。
全体文書の比較 - 2つのPDF文書の全体の内容を比較します。
PDF文書をグラフィカルに比較:
GetDifferenceメソッドを使用してPDFを比較 - 変更がマークされた個々の画像。
CompareDocumentsToPdfメソッドを使用してPDFを比較 - 変更がマークされた画像を含むPDF文書。
最初のコードスニペットは、2つのPDF文書の最初のページを比較する方法を示しています。
文書の初期化。 コードは、それぞれのファイルパス(documentPath1とdocumentPath2)を使用して2つのPDF文書を初期化することから始まります。パスは現在空の文字列として指定されていますが、実際にはこれを実際のファイルパスに置き換えます。
比較プロセス。
‘AdditionalChangeMarks = true’ - このオプションは、追加の変更マーカーが表示されることを保証します。これらのマーカーは、現在比較しているページにない場合でも、他のページに存在する可能性のある違いを強調表示します。
‘ComparisonMode = ComparisonMode.IgnoreSpaces’ - このモードは、テキスト内のスペースを無視し、単語内の変更のみに焦点を当てるように比較者に指示します。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ComparingSpecificPages()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentCompare();
// Open PDF documents
using (var document1 = new Aspose.Pdf.Document(dataDir + "ComparingSpecificPages1.pdf"))
{
using (var document2 = new Aspose.Pdf.Document(dataDir + "ComparingSpecificPages2.pdf"))
{
// Compare
Aspose.Pdf.Comparison.SideBySidePdfComparer.Compare(document1.Pages[1], document2.Pages[1], dataDir + "ComparingSpecificPages_out.pdf", new Aspose.Pdf.Comparison.SideBySideComparisonOptions
{
AdditionalChangeMarks = true,
ComparisonMode = Aspose.Pdf.Comparison.ComparisonMode.IgnoreSpaces,
DeleteColor = Color.DarkGray,
InsertColor = Color.LightYellow
});
}
}
}
2番目のコードスニペットは、2つのPDF文書の全体の内容を比較する範囲を拡大します。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
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,
DeleteColor = Color.DarkGray,
InsertColor = Color.LightYellow
});
}
}
}
これらのスニペットによって生成された比較結果は、Adobe Acrobatなどのビューワーで開くことができるPDF文書です。Adobe Acrobatで2ページ表示を使用すると、変更が並べて表示されます:
‘AdditionalChangeMarks’を’true’に設定することで、現在表示されているページに変更がない場合でも、他のページで発生する可能性のある変更のマーカーを確認できます。
Aspose.PDF for .NETは、特定のページを比較する必要がある場合でも、全体の文書を比較する必要がある場合でも、PDF文書を比較するための堅牢なツールを提供します。‘AdditionalChangeMarks’や異なる’ComparisonMode設定’などのオプションを使用することで、比較プロセスを特定のニーズに合わせて調整できます。結果の文書は、変更の明確な並べて表示を提供し、修正を追跡し、文書の正確性を確保するのを容易にします。
特にプロフェッショナルな環境で文書を共同作成する際、同じファイルの複数のバージョンを持つことがよくあります。
GraphicalPdfComparerクラスを使用してPDF文書とページを比較できます。このクラスは、ページのグラフィックコンテンツの変更を比較するのに適しています。
Aspose.PDF for .NETを使用すると、文書とページを比較し、比較結果をPDF文書または画像ファイルに出力できます。
次のクラスプロパティを設定できます:
このクラスには、さらなる処理に適した形でページ画像の違いを取得するメソッドがあります:ImagesDifference GetDifference(Page page1, Page page2)。
このメソッドは、比較される最初のページの画像と違いの配列を含むImagesDifferenceクラスのオブジェクトを返します。違いの配列と元の画像はRGB24bppピクセル形式です。
ImagesDifferenceを使用すると、異なる画像を生成し、違いの配列を元の画像に追加することで、比較される2番目のページの画像を取得できます。これを行うには、ImagesDifference.GetDestinationImageおよびImagesDifference.DifferenceToImageメソッドを使用します。
提供されたコードは、2つのPDF文書を比較し、それらの違いの視覚的表現を生成するメソッドGetDifferenceを定義しています。
このメソッドは、2つのPDFファイルの最初のページを比較し、2つのPNG画像を生成します:
このプロセスは、文書の2つのバージョン間の変更や違いを視覚的に比較するのに役立ちます。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ComparePDFWithGetDifferenceMethod()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentCompare();
// Open PDF documents
using (var document1 = new Aspose.Pdf.Document(dataDir + "ComparePDFWithGetDifferenceMethod1.pdf"))
{
using (var document2 = new Aspose.Pdf.Document(dataDir + "ComparePDFWithGetDifferenceMethod2.pdf"))
{
// Create comparer
var comparer = new Aspose.Pdf.Comparison.GraphicalPdfComparer();
// Compare
using (var imagesDifference = comparer.GetDifference(document1.Pages[1], document2.Pages[1]))
{
using (var diffImg = imagesDifference.DifferenceToImage(Aspose.Pdf.Color.Red, Aspose.Pdf.Color.White))
{
diffImg.Save(dataDir + "ComparePDFWithGetDifferenceMethodDiffPngFilePath_out.png");
}
using (var destImg = imagesDifference.GetDestinationImage())
{
destImg.Save(dataDir + "ComparePDFWithGetDifferenceMethodDestPngFilePath_out.png");
}
}
}
}
}
提供されたコードスニペットは、2つの文書を比較し、比較結果のPDFレポートを生成するCompareDocumentsToPdfメソッドを使用しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void ComparePDFWithCompareDocumentsToPdfMethod()
{
// The path to the documents directory
var dataDir = RunExamples.GetDataDir_AsposePdf_DocumentCompare();
// Open PDF documents
using (var document1 = new Aspose.Pdf.Document(dataDir + "ComparePDFWithCompareDocumentsToPdfMethod1.pdf"))
{
using (var document2 = new Aspose.Pdf.Document(dataDir + "ComparePDFWithCompareDocumentsToPdfMethod2.pdf"))
{
// Create comparer
var comparer = new Aspose.Pdf.Comparison.GraphicalPdfComparer()
{
Threshold = 3.0,
Color = Aspose.Pdf.Color.Blue,
Resolution = new Aspose.Pdf.Devices.Resolution(300)
};
// Compare
comparer.CompareDocumentsToPdf(document1, document2, dataDir + "compareDocumentsToPdf_out.pdf");
}
}
}
TextPdfComparerクラスを使用して、文書と個々のページを比較できます。このクラスは、ページごとに文書を比較するか、ページ分離なしで単一の連続コンテンツストリームとして比較することを可能にします。比較メソッドは、IStringOutputGeneratorまたはIFileOutputGeneratorインターフェースを実装する任意のクラスに渡すことができる違いの配列を返します。出力はHTML、Markdown、PDF、およびJSONでサポートされています。また、ComparisonStatisticsクラスを使用して、実行された比較操作の統計を取得できます。
| メソッド | 説明 | パラメータ | 戻り値 |
|---|---|---|---|
CompareDocumentsPageByPage(Document document1, Document document2, ComparisonOptions options) |
2つのPDF文書をページごとに比較します。 | * document1 – 最初の文書。* document2 – 2番目の文書。* options – 比較オプション(以下参照)。 |
List<List<DiffOperation>> – 各ページの違いのリスト。 |
CompareDocumentsPageByPage(Document document1, Document document2, ComparisonOptions options, string resultPdfDocumentPath) |
上記と同じですが、比較結果をPDFファイルに保存します。 | 上記と同じパラメータ + resultPdfDocumentPath – 出力ファイルのパス。 |
List<List<DiffOperation>> – 違いのリスト。 |
CompareFlatDocuments(Document document1, Document document2, ComparisonOptions options) |
2つのPDF文書を単一の連続テキストとして比較します(すべてのページを統合)。 | CompareDocumentsPageByPageと同じパラメータ。 |
List<DiffOperation> – すべての違いのリスト。 |
CompareFlatDocuments(Document document1, Document document2, ComparisonOptions options, string resultPdfDocumentPath) |
フラット文書比較で、結果をPDFファイルに保存します。 | CompareFlatDocumentsと同じパラメータ + resultPdfDocumentPath。 |
List<DiffOperation> – 違いのリスト。 |
ComparePages(Page page1, Page page2, ComparisonOptions options) |
2つの個々のページを比較します。 | * page1 – 最初のページ。* page2 – 2番目のページ。* options – 比較オプション。 |
List<DiffOperation> – ページの違いのリスト。 |
CreateComparisonStatistics(List<DiffOperation> diffs) |
単一ページの操作リストに対する比較統計を生成します。 | diffs – DiffOperationのリスト。 |
TextItemComparisonStatistics(以下参照)。 |
CreateComparisonStatistics(List<List<DiffOperation>> diffs) |
ページ間の操作リストに対する比較統計を生成します(文書レベル)。 | diffs – DiffOperationのリストのリスト。 |
DocumentComparisonStatistics(以下参照)。 |
AssemblySourcePageText(List<DiffOperation> diffs) |
元の(変更前の)ページテキストを再構築します。 | diffs – 操作のリスト。 |
string – 元のテキスト。 |
AssemblyDestinationPageText(List<DiffOperation> diffs) |
修正された(変更後の)ページテキストを再構築します。 | diffs – 操作のリスト。 |
string – 修正されたテキスト。 |
ComparisonOptions比較プロセスに影響を与えるパラメータ:
| プロパティ | 型 | 説明 |
|---|---|---|
ExtractionArea |
Rectangle |
テキストが抽出される領域。ExcludeTables、ExcludeAreas1/2とは互換性がありません。 |
ExcludeTables |
bool |
比較からテーブルを除外します。ExtractionAreaとは互換性がありません。 |
ExcludeAreas1 |
Rectangle[] |
最初の文書のために除外される領域の配列。 |
ExcludeAreas2 |
Rectangle[] |
2番目の文書のために除外される領域の配列。 |
EditOperationsOrder |
EditOperationsOrder (enum) |
挿入/削除操作の適用順序(デフォルトはDeleteFirst)。 |
DiffOperation単一の違い操作を表します。含まれるもの:
| プロパティ | 型 | 説明 |
|---|---|---|
Operation |
Operation (enum) |
操作の種類(Equal、Delete、Insert)。 |
Text |
string |
操作に関連付けられたテキスト。 |
ComparisonStatistics| クラス | 説明 |
|---|---|
TextItemComparisonStatistics |
個々のテキスト(ページ)に対する統計。総文字数、挿入数、削除数、および対応する操作を含みます。 |
DocumentComparisonStatistics (inherits from TextItemComparisonStatistics) |
文書全体に対する拡張統計で、PagesStatisticsのリスト(ページごとの統計)を含みます。 |
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.