C# 操作IitextPdf

1.读取PDF内容
public string ReadPdfFile(string fileName) { StringBuilder text = new StringBuilder(); if (File.Exists(fileName)) { PdfReader pdfReader = new PdfReader(fileName); for (int page = 1; page <= pdfReader.NumberOfPages; page++) { ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); string currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy); currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText))); text.Append(currentText); } pdfReader.Close(); } return text.ToString(); }

  

2.读取PDF页数
PdfReader reader = new PdfReader(imageFile);
int iPageNum = reader.NumberOfPages;
reader.Close();

  

posted @ 2017-11-09 15:21  公众号python学习开发  阅读(277)  评论(0编辑  收藏  举报