我将 PDFBox 用于 C# .NET 项目。并且在执行以下代码块时,我得到了“TypeInitializationException”('java.lang.Throwable' 的类型初始化程序引发了异常。):
FileStream stream = new FileStream(@"C:\1.pdf",FileMode.Open);
//retrieve the pdf bytes from the stream.
byte[] pdfbytes=new byte[65000];
stream.Read(pdfbytes, 0, 65000);
//get the pdf file bytes.
allbytes = pdfbytes;
//create a stream from the file bytes.
java.io.InputStream ins = new java.io.ByteArrayInputStream(allbytes);
string txt;
//load the doc
PDDocument doc = PDDocument.load(ins);
PDFTextStripper stripper = new PDFTextStripper();
//retrieve the pdf doc's text
txt = stripper.getText(doc);
doc.close();
异常发生在第三条语句:
PDDocument doc = PDDocument.load(ins);
我能做些什么来解决这个问题?
这是堆栈跟踪:
at java.lang.Throwable.__<map>(Exception , Boolean )
at org.pdfbox.pdfparser.PDFParser.parse()
at org.pdfbox.pdmodel.PDDocument.load(InputStream input, RandomAccess scratchFile)
at org.pdfbox.pdmodel.PDDocument.load(InputStream input)
at At.At.ExtractTextFromPDF(InputStream fileStream) in
C:\Users\Administrator\Documents\Visual Studio 2008\Projects\AtProject\Att\At.cs:line 61
InnerException 的内部异常:
- InnerException {“无法加载文件或程序集'IKVM.Runtime,Version = 0.30.0.0,Culture = Neutral,PublicKeyToken = 13235d27fcbfff58'或其依赖项之一。系统找不到指定的文件。”:“IKVM.Runtime,版本=0.30.0.0,文化=中性,PublicKeyToken=13235d27fcbfff58"} System.Exception {System.IO.FileNotFoundException}
好的,我通过将PDFBox的一些.dll文件复制到我的bin文件夹来解决了前面的问题。但现在我收到了这个错误:expected='/'actual='.'--1 org.pdfbox.io.PushBackInputStream@283d742
有没有使用 PDFBox 的替代方法?有没有其他可靠的库可以用来从 pdf 文件中提取文本。