activities
latest
false
重要 :
このコンテンツの一部は機械翻訳によって処理されており、完全な翻訳を保証するものではありません。 新しいコンテンツの翻訳は、およそ 1 ~ 2 週間で公開されます。
UiPath logo, featuring letters U and I in white

ワークフローのアクティビティ

最終更新日時 2026年2月17日

PDF ドキュメントを比較

以下の比較の種類を含む複数の比較オプションを使用して、2 つのドキュメントの等価性を検証します。

  • 単語の比較。
  • 行の比較
  • 文字を char 変数として比較します。
    注:

    サポートされているドキュメントの種類は PDF です。

定義

名前空間: UiPath.Testing.API

アセンブリ: UiPath.Testing.Activities.API (UiPath UiPath.Testing.Activities.Api.dll)

ComparePdfDocuments(string, string, ComparisonType, CompareDocumentsOptions)

ComparisonResult ComparePdfDocuments(
    string baselinePath,
    string targetPath,
    [ComparisonType comparisonType],
    [CompareDocumentsOptions opts])
ComparisonResult ComparePdfDocuments(
    string baselinePath,
    string targetPath,
    [ComparisonType comparisonType],
    [CompareDocumentsOptions opts])

baselinePath string : 比較の参照として使用するベース ドキュメントのパスです。

targetPath 文字列 : ベース ドキュメントと比較するドキュメントのパスです。

comparisonType ComparisonType (任意): ドキュメントを比較するときに使用する比較の種類です。次のオプションが利用できます。

  • ComparisonType.Char: ドキュメントのすべての文字 (char) を比較します。
  • ComparisonType.Line: ドキュメントのすべての行を比較します。
  • ComparisonType.Word: ドキュメントのすべての単語を比較します。

opts CompareDocumentsOptions : この操作に使用する特定の比較オプション。CompareDocumentsOptions型のオブジェクトを作成するには、TestingOptions.CompareDocuments クラスを使用します。

戻り値

ComparisonResult

比較操作の結果です。ComparisonResult 変数に格納されます。

1. PDF を文字単位で比較する:

この例では、2 つの PDF ファイル (光熱費と水道料金の請求書) を比較しています。比較は文字レベルで行われます。firstBill 変数と secondBill 変数は、これらの PDF ファイルのパスを表します。WithIgnoreWildcardRule メソッドおよび WithIgnoreRegexRule メソッドで、それぞれワイルドカード ルールと正規表現ルールを使用して、比較時に特定のパターンを無視するよう指定することができます。たとえば、ワイルドカード ルール 2022 と正規表現ルール \d{1,2}/\d{1,2}/\d{4} では、比較時に日付が MM/DD/YYYY 形式であると仮定して、日付が無視されます。2 つの請求書でそれぞれ日付が異なる可能性があり、請求書の構造とは無関係であるためです。

比較が完了すると、WithGenerateHtml メソッドによって比較の HTML レポートが作成され、見つかった差分は Log メソッドを使用してログに記録されます。

var firstBill = @"C:\bills\2024.10\pdfs for compare\electricity_bill.pdf";
var secondBill = @"C:\bills\2024.10\pdfs for compare\water_bill.pdf";

var identicalCharCompareResult = testing.VerifyDocumentsEquivalence(
    firstBill, secondBill, 
    ComparisonType.Character, 
    TestingOptions.CompareDocuments()
        .WithGenerateHtml(@".\HtmlCompareResults\PDFCharCompare.html")
        .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
        .WithIgnoreRegexRule("RegexRule", @"\d{1,2}/\d{1,2}/\d{4}", true)
);

Log("pdf compare by char " + identicalCharCompareResult.AreEquivalent.ToString(),LogLevel.Error);
var firstBill = @"C:\bills\2024.10\pdfs for compare\electricity_bill.pdf";
var secondBill = @"C:\bills\2024.10\pdfs for compare\water_bill.pdf";

var identicalCharCompareResult = testing.VerifyDocumentsEquivalence(
    firstBill, secondBill, 
    ComparisonType.Character, 
    TestingOptions.CompareDocuments()
        .WithGenerateHtml(@".\HtmlCompareResults\PDFCharCompare.html")
        .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
        .WithIgnoreRegexRule("RegexRule", @"\d{1,2}/\d{1,2}/\d{4}", true)
);

Log("pdf compare by char " + identicalCharCompareResult.AreEquivalent.ToString(),LogLevel.Error);

2. PDF を単語単位で比較する:

この例では、先ほどの例と同じ PDF ファイル (光熱費と水道料金の請求書) を比較しています。比較は単語レベルで行われます。firstBill 変数と secondBill 変数は、これらの PDF ファイルのパスを表します。WithIgnoreWildcardRule メソッドおよび WithIgnoreRegexRule メソッドで、それぞれワイルドカード ルールと正規表現ルールを使用して、比較時に特定のパターンを無視するよう指定することができます。たとえば、ワイルドカード ルール 2022 では、比較時に日付が MM/DD/YYYY 形式であると仮定し、日付が無視されます。2 つの請求書でそれぞれ日付が異なる可能性があり、請求書の構造とは無関係であるためです。正規表現ルール [$]\d+\.\d{2} では、通貨値が $XX.XX のような形式であると仮定して無視されます。

比較が完了すると、WithGenerateHtml メソッドによって比較の HTML レポートが作成され、見つかった差分は Log メソッドを使用してログに記録されます。

var firstBill = @"C:\bills\2024.10\pdfs for compare\electricity_bill.pdf";
var secondBill = @"C:\bills\2024.10\pdfs for compare\water_bill.pdf";

var differentWordCompareResult = testing.VerifyDocumentsEquivalence(
    firstBill, secondBill, 
    ComparisonType.Word, 
    TestingOptions.CompareDocuments()
        .WithGenerateHtml(@".\HtmlCompareResults\PDFWordCompareDiff.html")
        .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
        .WithIgnoreRegexRule("RegexRule", @"[$]\d+\.\d{2}", true)
);

Log("pdf compare by Word " + differentWordCompareResult.AreEquivalent.ToString(), LogLevel.Error);
var firstBill = @"C:\bills\2024.10\pdfs for compare\electricity_bill.pdf";
var secondBill = @"C:\bills\2024.10\pdfs for compare\water_bill.pdf";

var differentWordCompareResult = testing.VerifyDocumentsEquivalence(
    firstBill, secondBill, 
    ComparisonType.Word, 
    TestingOptions.CompareDocuments()
        .WithGenerateHtml(@".\HtmlCompareResults\PDFWordCompareDiff.html")
        .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
        .WithIgnoreRegexRule("RegexRule", @"[$]\d+\.\d{2}", true)
);

Log("pdf compare by Word " + differentWordCompareResult.AreEquivalent.ToString(), LogLevel.Error);

3. PDF を行単位で比較する:

この例では、前の例と同様に、2 つの PDF ファイル (光熱費と水道料金の請求書) を比較しています。この場合、比較は行単位で行われます。firstBill 変数と secondBill 変数は、これらの PDF ファイルのパスを表します。WithIgnoreWildcardRule メソッドおよび WithIgnoreRegexRule メソッドで、それぞれワイルドカード ルールと正規表現ルールを使用して、比較時に特定のパターンを無視するよう指定することができます。

たとえば、ワイルドカード ルール 2022 では、比較時に日付 (MM/DD/YYYY 形式であると仮定) が無視されます。2 つの請求書でそれぞれ日付が異なる可能性があり、請求書の構造とは無関係であるためです。正規表現ルール [$]\d+\.\d{2} では、通貨値が $XX.XX のような形式であると仮定して無視されます。

比較が完了すると、WithGenerateHtml メソッドによって比較の HTML レポートが作成され、見つかった差分は Log メソッドを使用してログに記録されます。

var firstBill = @"C:\bills\2024.10\pdfs for compare\electricity_bill.pdf";
var secondBill = @"C:\bills\2024.10\pdfs for compare\water_bill.pdf";

var largeLineCompareResult = testing.VerifyDocumentsEquivalence(
    firstBill, secondBill, 
    ComparisonType.Line, 
    TestingOptions.CompareDocuments()
        .WithGeneratePdf(@".\PDFCompareResults",@".\PDFCompareResults")
        .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
        .WithIgnoreRegexRule("RegexRule", @"[$]\d+\.\d{2}", true)
);

Log("Pdf compare by line " + largeLineCompareResult.AreEquivalent.ToString(), LogLevel.Error);
var firstBill = @"C:\bills\2024.10\pdfs for compare\electricity_bill.pdf";
var secondBill = @"C:\bills\2024.10\pdfs for compare\water_bill.pdf";

var largeLineCompareResult = testing.VerifyDocumentsEquivalence(
    firstBill, secondBill, 
    ComparisonType.Line, 
    TestingOptions.CompareDocuments()
        .WithGeneratePdf(@".\PDFCompareResults",@".\PDFCompareResults")
        .WithIgnoreWildcardRule("WildcardRule", "*2022*", true)
        .WithIgnoreRegexRule("RegexRule", @"[$]\d+\.\d{2}", true)
);

Log("Pdf compare by line " + largeLineCompareResult.AreEquivalent.ToString(), LogLevel.Error);

いずれの場合も、AreEquivalent プロパティはドキュメントが同一かどうかを返します。

このページは役に立ちましたか?

サポートを受ける
RPA について学ぶ - オートメーション コース
UiPath コミュニティ フォーラム
Uipath Logo
信頼とセキュリティ
© 2005-2026 UiPath. All rights reserved.