Read a PDF and find a specific column to add to a list
那么谁能找到一种方法以编程方式仅读出
列格式如下:
401232111555713
以下代码将使用 iTextSharp 打开任何 PDF 并将其读入字符串:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | public static 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(); } |
从那里您可以简单地运行一些
1 2 3 4 5 6 7 |
您需要使用一些 PDF 处理库。这是一个关于该主题的讨论的 SO 链接:
用C#阅读PDF