读取pdf文件 .选择了itextsharp 库

<p>此库还是比较成熟.看博客园很多文章都介绍了此库</p> <p>用法</p> <p>&nbsp;</p> <p>如果项目用到读取pdf.&nbsp; 我这只是提供个思路.或者提供个方法.用itextsharp 能方便实现</p> <div class="cnblogs_code"> <pre> StringBuilder text = <span style="color: #0000ff;">new</span><span style="color: #000000;"> StringBuilder(); </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (File.Exists(filepath)) { PdfReader pdfReader </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> PdfReader(filepath); </span><span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">int</span> page = <span style="color: #800080;">1</span>; page &lt;= pdfReader.NumberOfPages; page++<span style="color: #000000;">) { ITextExtractionStrategy strategy </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SimpleTextExtractionStrategy(); </span><span style="color: #0000ff;">string</span> currentText =<span style="color: #000000;"> PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy); currentText </span>=<span style="color: #000000;"> Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText))); text.Append(currentText); } pdfReader.Close(); } </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> text.ToString(); </span></pre> </div> <p>&nbsp;</p> <p>技术更新快,当你看到这个文章的时候也许有更好的库出来了..</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p>

你可能感兴趣的:(itext)