- Code: Select all
docx4j.openpackaging.parts.WordprocessingML.ObfuscatedFontPart.tmpFontDir = D:\\home\\site\\wwwroot\\temp\\
- Code: Select all
The type initializer for 'org.docx4j.fonts.BestMatchingMapper' threw an exception.","InnerException":{"ClassName":"java.lang.RuntimeException","Message":"org.docx4j.fonts.fop.apps.FOPException: .docx4j (Access is denied)\njava.io.FileNotFoundException: .docx4j (Access is denied)","Data":null,"InnerException":{"ClassName":"org.docx4j.fonts.fop.apps.FOPException","Message":"","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at org.docx4j.fonts.fop.util.LogUtil.handleException(Logger log, Exception e, Boolean strict)\r\n at org.docx4j.fonts.fop.fonts.FontCache.saveTo(File cacheFile)\r\n at org.docx4j.fonts.fop.fonts.FontCache.save()\r\n at org.docx4j.fonts.PhysicalFonts.discoverPhysicalFonts()\r\n at org.docx4j.fonts.BestMatchingMapper..cctor()","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":"8\nhandleException\ndocx4j, Version=3.2.0.1, Culture=neutral, PublicKeyToken=null\norg.docx4j.fonts.fop.util.LogUtil\nVoid handleException(org.slf4j.Logger, java.lang.Exception
I don't think it's a simple 'write permission' problem, because i have other code that writes files inside the wwwroot directory and it works fine.
My code:
- Code: Select all
using System.IO;
using java.io;
using org.docx4j.fonts;
using org.docx4j.openpackaging.packages;
public static MemoryStream ConvertDocxToPdf(MemoryStream docxToBeConverted)
{
java.io.ByteArrayOutputStream fos = new java.io.ByteArrayOutputStream();
// Necessary, if slf4j-api and slf4j-NetCommonLogging are separate DLLs
ikvm.runtime.Startup.addBootClassPathAssembly(
System.Reflection.Assembly.GetAssembly(
typeof(org.slf4j.impl.StaticLoggerBinder)));
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)));
// Configure to find docx4j.properties
// .. add as URL the dir containing docx4j.properties (not the file itself!)
Plutext.PropertiesConfigurator.setDocx4jPropertiesDir("D:\\home\\site\\wwwroot\\bin");
byte[] docByteArray;
using (docxToBeConverted)
{
docByteArray = docxToBeConverted.ToArray();
}
InputStream myInputStream = new ByteArrayInputStream(docByteArray);
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
.load(myInputStream);
wordMLPackage.setFontMapper(new BestMatchingMapper());
org.docx4j.Docx4J.toPDF(wordMLPackage, fos);
return new MemoryStream(fos.toByteArray());
}
Please let me know if you have any idea on how to approach this issue, it would be highly appreciated.