Page 1 of 1

Docx4j.NET (Access is denied)

PostPosted: Thu Oct 20, 2016 2:24 am
by andrei
HI, i'm using Docx4j v3.0.1 inside a .NET Web API project, which will be hosted on Azure App Services(so, no VMs with Windows installed orwith installed fonts, just a plain FTP). Because of that, i went the 'BestMatchingMapper()' way and after embedding the font into my .docx document, i've edited the file and set the
Code: Select all = D:\\home\\site\\wwwroot\\temp\\
(while it looks weird, this is the default path of Azure Web apps in which the project is deployed). After this, when trying to convert the docx file the server returns the following error:

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)\ .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\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=, 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 org.docx4j.fonts;
using org.docx4j.openpackaging.packages;

public static MemoryStream ConvertDocxToPdf(MemoryStream docxToBeConverted)
   fos = new;
            // Necessary, if slf4j-api and slf4j-NetCommonLogging are separate DLLs


            // Configure to find
            // .. add as URL the dir containing (not the file itself!)
            byte[] docByteArray;
            using (docxToBeConverted)
                docByteArray = docxToBeConverted.ToArray();
            InputStream myInputStream = new ByteArrayInputStream(docByteArray);
            WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage
            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.

Re: Docx4j.NET (Access is denied)

PostPosted: Thu Aug 02, 2018 1:04 am
by alexmurat
Hello Andrei,

I solved giving access to the users of ISS to modify the path: (Windows Server)


The home path in my local machine is User\My User, but in the server the path is that in the system32 folder.

string home = java.lang.System.getProperty("user.home"); // return the home path

I hope that help you.