我正在使用PDFBox作为C#.NET项目。从PDF文件中提取文本
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();
发生在3日声明的除外:
,我得到一个“TypeInitializationException”执行下面的代码块时(对于“java.lang.Throwable的”的类型初始值引发异常。)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,版本= 0.30.0.0,文化=中性,PublicKeyToken = 13235d27fcbfff58'或其依赖项之一。系统找不到指定的文件。“:”IKVM.Runtime,Version = 0.30.0.0,Culture = neutral,PublicKeyToken = 13235d27fcbfff58“} System.Exception {System.IO .FileNotFoundException}
好的,我通过将PDFBox的某些.dll文件复制到我的bin文件夹中解决了上一个问题。但现在我得到这个错误:expected ='/'actual ='。' - 1 [email protected]
是否有任何替代使用PDFBox?有没有其他可靠的库,我可以用它来从pdf文件中提取文本。
PDFBox的是一个Java库,你的代码看起来像Java。 C#涉及哪里? – dtb 2009-11-15 19:03:11
“TypeInitializationException”的内部异常是什么? – dtb 2009-11-15 19:04:22
有点困惑;你说它的C#,但它的Java。 而在Java中,字符串类型为“String”,但您使用“string” – alternative 2009-11-15 19:06:16