java.io.IOException”类型的未经处理的异常在 PDFBox-0.7.3.dll 中发生
其他信息: Error: Could not find predefined CMAP file for 'UniGB-UTF16-H'
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using org.pdfbox.pdmodel;
using org.pdfbox.util;
using System.IO;
private void button1_Click(object sender, EventArgs e)
{
FileInfo file = new FileInfo(@"c:\invoice.pdf");
FileInfo txtfile = new FileInfo(@"c:\invoice.txt");
pdf2txt(file, txtfile);
}
public void pdf2txt(FileInfo file, FileInfo txtfile)
{
PDDocument doc = PDDocument.load(file.FullName);
PDFTextStripper pdfStripper = new PDFTextStripper();
string text = pdfStripper.getText(doc);
StreamWriter swPdfChange = new StreamWriter(txtfile.FullName, false, System.Text.Encoding.GetEncoding("gb2312"));
swPdfChange.Write(text);
swPdfChange.Close();
}
版本低了,我用的1.7.1版本后,这个问题解决了