我必须从PDF文件中检索文本.但是使用下面的代码我只得到空文本文件.
for (int i = 0; i < n; i++) { pagenumber = i + 1; filename = pagenumber.ToString(); while (filename.Length < digits) filename = "0" + filename; filename = "_" + filename; filename = splitFile + name + filename; // step 1: creation of a document-object document = new Document(reader.GetPageSizeWithRotation(pagenumber)); // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.GetInstance(document,new FileStream(filename + ".pdf",FileMode.Create)); // step 3: we open the document document.Open(); PdfContentByte cb = writer.DirectContent; PdfImportedPage page = writer.GetImportedPage(reader,pagenumber); int rotation = reader.GetPageRotation(pagenumber); if (rotation == 90 || rotation == 270) { cb.AddTemplate(page,-1f,1f,reader.GetPageSizeWithRotation(pagenumber).Height); } else { cb.AddTemplate(page,0); } // step 5: we close the document document.Close(); PDFParser parser = new PDFParser(); parser.ExtractText(filename + ".pdf",filename + ".txt"); }
我做错了什么以及如何从PDF中提取文本?