如何使用itextSharp将确切的内容从pdf转换为Excel?我已经编写了将pdf转换为excel的代码。
string filepath = "filepath.PDF";
string strText = string.Empty;
List<string[]> list = new List<string[]>();
string[] PdfData = null;
try
{
PdfReader reader = new PdfReader((string)filepath);
for (int page = 1; page <= reader.NumberOfPages; page++)
{
ITextExtractionStrategy its = new iTextSharp.text.pdf.parser.LocationTextExtractionStrategy();
String cipherText = PdfTextExtractor.GetTextFromPage(reader, page, its);
byte[] content = reader.GetPageContent(page);
string contentstring = Encoding.UTF32.GetString(content);
cipherText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(cipherText)));
string tcipherText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Unicode, Encoding.UTF8, Encoding.Unicode.GetBytes(cipherText)));
strText = strText + "\n" + cipherText;
PdfData = strText.Split('\n');
}
reader.Close();
}
在这里,我遇到了一个问题,例如“我们的规则和规定”等Pdf文本。我需要将其解析为Excel中的单个列。
您能帮助任何人解决此问题吗?