C# 使用Aspose.Pdf讀取Pdf表格


pdf文件內容:

1.上面我們有一個pdf文件,內容為表格形式的,在使用Aspose.Pdf讀取的時候,如果不定義讀取時的TextExtractionOptions,我們看一下讀取的內容是什么樣子的?

可以看到在讀取pdf文字的時候,並沒有按照表格划分,而是視覺上同一行的文字被划分到同一行,這樣在處理數據的時候就比較麻煩。

2.我們定義一下TextExtractionOptions試試:

var textExtractionOptions = new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.Raw);

我們可以看到這時候的文字已經按照單元格分開了。

參考代碼:

 1 using Aspose.Pdf;
 2 using Aspose.Pdf.Text;
 3 using Aspose.Pdf.Text.TextOptions;
 4 
 5 namespace Test
 6 {
 7     class Program
 8     {
 9         static void Main(string[] args)
10         {
11             Document pdfDocument = new Document(@"d:\pdf.pdf");
12             var textExtractionOptions = new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.Raw);
13             var textSearchOptions = new TextSearchOptions(true);
14             TextAbsorber textAbsorber = new TextAbsorber(textExtractionOptions, textSearchOptions);
15             pdfDocument.Pages.Accept(textAbsorber);
16             string content = textAbsorber.Text;
17         }
18     }
19 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM