由网友(少走感情路)分享简介:如何使用ABCPdf.NET工具从PDF文件中提取文本的内容?How to use the ABCPdf.NET tool to extract the content texts from a PDF file?我试过了gettext方法,但不提取的内容:I tried the GetText method b...
如何使用ABCPdf.NET工具从PDF文件中提取文本的内容?
How to use the ABCPdf.NET tool to extract the content texts from a PDF file?
我试过了gettext方法,但不提取的内容:
I tried the GetText method but doesn't extract the contents:
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的话。我意识到它返回的第一页只有文字。
My pdf has almost 1000 words but the GetText only returns 4-5 words. I realized it returns only the texts of the first page.
因此,问题应该是如何提取从PDF文件的所有页面的文字? - (改标题,以使其更清晰)
So the question should be "how to extract the text from all pages of a pdf file?" -(changed the Title to make it clearer).
谢谢
推荐答案
有关您的利益,是你!
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();
}
如果您还没有网址,但有个字节,则:
if you don't have the url but have the bytes, then:
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();
}
相关推荐
最新文章