Font data cannot be retrieved by PdfSharp / MigradDoc
I have an ASP.NET MVC web application and I am using PdfSharp / MigraDoc to generate reports. When I publish my app to azure and print the report, the following exception is thrown:
Internal error. Font data could not retrieved.
I have this method that determines the style of the report and I select the font Arial.
private void DefineStyle(Document document)
{
Style style = document.Styles.AddStyle("Table", "Normal");
style.Font.Name = "Arial";
style.Font.Size = 9;
}
And in the last step, I render a PDF call to this method:
public void RenderAsPdf(Document document, HttpResponseBase response, string title)
{
PdfDocumentRenderer renderer = new PdfDocumentRenderer(true, PdfSharp.Pdf.PdfFontEmbedding.Always);
renderer.Document = document;
renderer.RenderDocument();
MemoryStream stream = new MemoryStream();
renderer.Save(stream, false);
response.Clear();
response.AddHeader("Cache-Control", "no-cache");
response.AddHeader("Pragma", "no-cache");
response.ContentType = "application/pdf";
response.AddHeader("Content-Disposition", "filename=" + title + ".pdf");
response.AddHeader("content-length", stream.Length.ToString());
response.BinaryWrite(stream.ToArray());
response.Flush();
stream.Close();
response.End();
}
This clause below throws an exception.
renderer.RenderDocument();
I already fully trusted my application and didn't work. I added this config to web.config.
<configuration>
<system.web>
<trust level="Full" />
</system.web>
</configuration>
I really don't know what to do ... How can I solve this? Thank!
** Sorry for my English: (
source to share
Make sure the Arial font is installed on the server - or use a proprietary font (including the font with your project).
The API has changed since version 1.50. Sample version 1.50 can be found here:
http://forum.pdfsharp.net/viewtopic.php?p=8961#p8961
The sample API used in version 1.3x can be found in the complete source package. See also: http://pdfsharp.net/wiki/PrivateFonts-sample.ashx
source to share