原創|行業資訊|編輯:胡濤|2024-09-11 11:00:08.230|閱讀 81 次
概述:本文旨在演示如何在 C# 程序中使用Spire.PDF for .NET輕松比較 PDF 文檔,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
PDF 已成為跨不同平臺共享和保存文檔的標準格式,在專業和個人環境中都發揮著無處不在的作用。但是,創建高質量的 PDF 文檔需要多次檢查和修訂。在這種情況下,了解如何有效地比較 PDF 文件并找出它們的差異變得至關重要,這使文檔編輯器能夠快速識別文檔不同版本之間的差異,從而在文檔創建和審閱過程中節省大量時間。本文旨在演示如何在 C# 程序中使用Spire.PDF for .NET輕松比較 PDF 文檔。
Spire.PDF for .NET 是一款獨立 PDF 控件,用于 .NET 程序中創建、編輯和操作 PDF 文檔。使用 Spire.PDF 類庫,開發人員可以新建一個 PDF 文檔或者對現有的 PDF 文檔進行處理,且無需安裝 Adobe Acrobat。
E-iceblue 功能類庫Spire 系列文檔處理組件均由中國本土團隊研發,不依賴第三方軟件,不受其他國家的技術或法律法規限制,同時適配國產操作系統如中科方德、中標麒麟等,兼容國產文檔處理軟件 WPS(如 .wps/.et/.dps 等格式
首先,您需要將 Spire.PDF for.NET 包中包含的 DLL 文件作為引用添加到您的 .NET 項目中。 以通過安裝。
PM> Install-Package Spire.PDF
使用 Spire.PDF for .NET,開發人員可以創建PdfComparer類的實例,傳遞兩個PdfDocument對象作為參數,然后利用PdfComparer.Compare(String fileName)方法比較兩個文檔。比較結果將保存為新的 PDF 文檔,以便進一步分析或審查兩個 PDF 之間的差異。
生成的 PDF 文檔在左側和右側顯示兩個原始文檔,其中刪除的項目以紅色顯示,添加的項目以黃色顯示。
以下是比較兩個PDF文檔的詳細步驟:
【C#】
using Spire.Pdf; using Spire.Pdf.Comparison; namespace ExtractTablesToExcel { class Program { static void Main(string[] args) { //Create an object of PdfDocument class and load a PDF document PdfDocument pdf1 = new PdfDocument(); pdf1.LoadFromFile("Sample1.pdf"); //Create another object of PdfDocument class and load another PDF document PdfDocument pdf2 = new PdfDocument(); pdf2.LoadFromFile("Sample2.pdf"); //Create an object of PdfComparer class with the two document PdfComparer comparer = new PdfComparer(pdf1, pdf2); //Compare the two document and save the comparing result to another PDF document comparer.Compare("output/ComparingResult.pdf"); pdf1.Close(); pdf2.Close(); } } }
創建PdfComparer類實例后,開發人員還可以使用PdfComparer.Options.SetPageRange()方法設置要比較的頁面范圍。這樣可以僅比較兩個 PDF 文檔中的指定頁面范圍。詳細步驟如下:
【C#】
using Spire.Pdf; using Spire.Pdf.Comparison; namespace ExtractTablesToExcel { class Program { static void Main(string[] args) { //Create an object of PdfDocument class and load a PDF document PdfDocument pdf1 = new PdfDocument(); pdf1.LoadFromFile("Sample1.pdf"); //Create another object of PdfDocument class and load another PDF document PdfDocument pdf2 = new PdfDocument(); pdf2.LoadFromFile("Sample2.pdf"); //Create an object of PdfComparer class with the two document PdfComparer comparer = new PdfComparer(pdf1, pdf2); //Set the page range to be compared comparer.Options.SetPageRanges(1, 1, 1, 1); //Compare the specified page range and save the comparing result to another PDF document comparer.Compare("output/PageRangeComparingResult.pdf"); pdf1.Close(); pdf2.Close(); } } }
歡迎下載|體驗更多E-iceblue產品
獲取更多信息請咨詢 ;技術交流Q群(767755948)
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn