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 }