[英]How to use the ABCPdf.NET to extract texts from all pages of a PDF file?
如何使用ABCPdf.NET工具從PDF文件中提取內容文本?
我嘗試了GetText方法,但沒有提取內容:
var doc = new Doc();
var url = @".../FileName.pdf";
doc.Read(url);
string xmlContents = doc.GetText("Text");
Response.Write(xmlContents);
doc.Clear();
doc.Dispose();
我的pdf有近1000個單詞,但GetText只返回4-5個單詞。 我意識到它只返回第一頁的文本。
所以問題應該是“如何從pdf文件的所有頁面中提取文本?” - (更改標題以使其更清晰)。
謝謝,
為了你的利益,是的你!
public string ExtractTextsFromAllPages(string pdfFileName)
{
var sb = new StringBuilder();
using (var doc = new Doc())
{
doc.Read(pdfFileName);
for (var currentPageNumber = 1; currentPageNumber <= doc.PageCount; currentPageNumber++)
{
doc.PageNumber = currentPageNumber;
sb.Append(doc.GetText("Text"));
}
}
return sb.ToString();
}
如果你沒有url但是有字節,那么:
public string ExtractTextsFromAllPages(Byte[] pdfBytes)
{
var sb = new StringBuilder();
using (var doc = new Doc())
{
doc.Read(pdfBytes);
for (var currentPageNumber = 1; currentPageNumber <= doc.PageCount; currentPageNumber++)
{
doc.PageNumber = currentPageNumber;
sb.Append(doc.GetText("Text"));
}
}
return sb.ToString();
}
你試過GetText方法嗎?
doc.Read(.......);
var textOperation = new TextOperation(doc);
textOperation.PageContents.AddPages();
string allText = textOperation.GetText();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.