Font not found when trying to save pdf document

We are evaluating Aspose.Pdf (.NET) product and the following problem prevents us from buying a license.

When building pdf document using regular console application, or windows service - document is generated without any problem. However, if do the same from WCF service (or ASP.NET application), running under IIS under “Network Service” built-in Windows account, Pdf.Save(Stream) method fails with the following exception:

System.ApplicationException: The embedded font ‘Times New Roman’ is not found. Make sure that you set correct path to the font file. —> System.ApplicationException: Font ‘Times New Roman’ not found. Please make sure the customer font file is correctly set.
at €Š.—.ˆ( , String , String , Boolean )
at €Š.•.( , String , String , Boolean , Boolean , Boolean , String , Boolean )
at €Š.•.FindFont( , String , String , Boolean , Boolean , Boolean , String , Boolean )
— End of inner exception stack trace —
at €Š.•.ž(String , Boolean , String , Exception )
at €Š.•.FindFont( , String , String , Boolean , Boolean , Boolean , String , Boolean )
at €Š..(String , String , Boolean , Boolean , Boolean , String , Boolean )
at €Š..ž(TextInfo )
at Š.eŽ.ž(Text , Pdf )
at Š.eŽ.–€(Pdf , Section , Table , Row , Cell , Text ,  , Ž , Boolean )
at Š.“Ž.›™(Pdf , Section , HeaderFooter , Table , Row , Cell , Text ,  , Ž , Boolean )
at Š.†Ž.‚(Pdf , Section ,  )
at Š.ž.ƒ(Pdf )
at Š.Ž.a€(‰ , Pdf )
at Aspose.Pdf.Generator.Pdf.Save(Stream stream)

Code to reproduce this problem is very simple (but problem is reproduced only under conditions mentioned above - i.e. WCF service running under IIS and “Network Service” account). Note that no “Times New Roman” font is used explicitly:

using (var fs = new FileStream(output, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) {
var doc = new Pdf();
doc.Save(fs);
}

Environment is: Windows Server 2012 Standard, IIS 8.

I found the reason myself. First of all, it has nothing to do with WCF or account application is running under. However, reason is much more mysterious. It seems that Aspose.Pdf looks for variable with name “TempFolder” in application configuration file (variable from section in app.config file). IF this variable points to a folder on a NON-system drive (so, usually, NOT C:\ drive), any attempt to save pdf document to a stream will result in the exception above. Any attempt to save document using Pdf.Save(String) overload (which is intended to save to a file), will result in zero-length pdf file. It took me many hours to figure out that mysterious and non-documented behavior. To reproduce the problem, perform the following simple actions:


1. Create empty console application in Visual Studio.

2. Use the following app.config file for that application:

<?xml version="1.0" encoding="utf-8" ?>

where D:\ is any existing, writable, non-system (not a drive where Windows is installed) drive.

3. Install the latest version of Aspose.Pdf via NuGet package (I used version 9.4).

4. Use the following Main method:

private static void Main(string[] args) {
var doc = new Aspose.Pdf.Generator.Pdf();
using (var fs = new FileStream(“output.pdf”, FileMode.Create))
doc.Save(fs);
}

which just tries to save empty pdf document.

5. Compile and run application. If all done right, you should see the exception.

Hi Evgeny,

Thanks you very much for sharing the details. While testing the scenario with the latest version of Aspose.Pdf for .NET 9.4.0 and VS2012, we have managed to reproduce the reported issue and logged it with high priority in our bug tracking system as PDFNEWNET-37208 for further investigation and resolution. We will notify you via this thread as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-37208) have been fixed in Aspose.Pdf for .NET 9.9.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Evgeny,


Thanks for your patience. As above stated your above reported issue has been fixed. Please use new generator code for creating new PDF document as following, it will resolve the issue.

Document doc = new
Document();<o:p></o:p>

using (var fs = new FileStream("output.pdf", FileMode.Create))

doc.Save(fs);

Please feel free to contact us for any further assistance.


Best Regards,