asp.NET c# : Code working as a console app but not as a web app -


my basic problem converting .docx file .pdf. problem solved incase allowed use microsoft.office.interop.word.dll, not since server not have ms office installed. needed free/open-source library allow me so. , came across docx4j.net.

http://www.docx4java.org/blog/2014/09/docx-to-pdf-in-c-net/

this worked fine long ran console app. following concerned code snippet:

string filein = @"c:\users\...\visual studio 2013\projects\hrdapp\hrdapp\letter_templates\ap.docx"; string fileout = @"c:\users\...\visual studio 2013\projects\hrdapp\hrdapp\letter_templates\ap.pdf";  log.info("hello common logging");  // necessary, if slf4j-api , slf4j-netcommonlogging separate dlls ikvm.runtime.startup.addbootclasspathassembly(     system.reflection.assembly.getassembly(         typeof(org.slf4j.impl.staticloggerbinder)));  // configure find docx4j.properties // .. add url dir containing docx4j.properties (not file itself!) plutext.propertiesconfigurator.setdocx4jpropertiesdir(projectdir + @"src\samples\resources\");  java.io.file file = new java.io.file(filein);  // ok, it.. wordprocessingmlpackage wordmlpackage = wordprocessingmlpackage.load(file);  java.io.fileoutputstream fos = new java.io.fileoutputstream(new java.io.file(fileout));  org.docx4j.docx4j.topdf(wordmlpackage, fos);  fos.close(); 

in case of using in web app, code runs fine till

java.io.file file = new java.io.file(filein); 

and gets stuck at

wordprocessingmlpackage wordmlpackage = wordprocessingmlpackage.load(file); 

although file path correct , works fine in console app, there seems else missing here. log prints upto following statement-

iisexpress.exe information: 0 : [info] org.docx4j.jaxb.context - using java 6/7 jaxb implementation

.. , stops. kind of reply directing me source of error helpful. thanks.

as jeroen (of ikvm fame) has explained, when there no main assembly (eg in asp.net application), ikvm class loader can't find assembly when code trying dynamically load class.

so you'll want add not just:

    ikvm.runtime.startup.addbootclasspathassembly(         system.reflection.assembly.getassembly(             typeof(org.slf4j.impl.staticloggerbinder))); 

but also:

    ikvm.runtime.startup.addbootclasspathassembly(         system.reflection.assembly.getassembly(             typeof(org.slf4j.loggerfactory)));      ikvm.runtime.startup.addbootclasspathassembly(         system.reflection.assembly.getassembly(             typeof(org.docx4j.jaxb.context)));    

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -