How to use PDFBox 1.0 in .net / C# environment using IKVM

ぐ巨炮叔叔 提交于 2020-01-06 02:59:04

问题


Id like to use PDFBox to generate PDF highlight files in my .net project. PDFBox states that it can be used in .net via IKVM http://www.pdfbox.org/userguide/dot_net.html

BUT running ikvmc (latest version) to generate the DLLs on PDFBOX.1.0.0.jar generates a whole lot of NoClassDefFound warnings.

How should I fix this, and what other DLLs do I need to include in my project? It seems as though file names have changed from the older documentation/articles I have read on the matter.

thanks in advance.


回答1:


I just came across this question while trying to figure out for myself how to get PDFBox 1.0 working. It appears that the NoClassFound errors are being generated because it can't find the referenced jars (which are in the folder titled "external"). Here's how I was finally able to get it working:

  1. Use the binaries from IKVM 0.30.00
  2. Put the pdfbox-1.0.0 jar file in the "external" folder (easier to reference)
  3. In command line, execute lkvmc.exe -target:library -out:"[Output Path]\netpdfbox.dll" "[PDFBox Path]\*.jar" <-- the *.jar tells IKVM to run include all jar files as one large assembly

You should be able to include the outputted .dll in your C# code. I was able to execute the following code without any issues:

PDDocument doc = PDDocument.load("test.pdf");
string output = new PDFTextStripper().getText(doc);



回答2:


It depends on what version of PDFBox you are using. The latest releaesd version (0.7.3) uses IKVM 0.30.00. There are other versions of IKVM out there as well, and not all are backwards compatible. There is also another beta PDFBox that I believe uses a newer version of IKVM.

I'm pretty sure that the IKVM libraries that are required for each versioned release of PdfBox are in the release zip file. Be sure you use the one that comes with the release, and not the latest version of IKVM because they may not be compatible.



来源:https://stackoverflow.com/questions/2314759/how-to-use-pdfbox-1-0-in-net-c-sharp-environment-using-ikvm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!