Reputation: 39
I have an ASP .NET MVC web application and I'm using PdfSharp/MigraDoc to generate the reports. When I publish the application to azure and print the report the following exception is raised:
Internal error. Font data could not retrieved.
I have this method that define the report style and I choose the "Arial" font.
private void DefineStyle(Document document)
{
Style style = document.Styles.AddStyle("Table", "Normal");
style.Font.Name = "Arial";
style.Font.Size = 9;
}
And in the final step I render the PDF calling 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();
}
At this point below, that the exception is raised.
renderer.RenderDocument();
I have already given full trust to my application and didn't work. I added this config in the web.config.
<configuration>
<system.web>
<trust level="Full" />
</system.web>
</configuration>
I really don't know what to do... How can I solve this? Thanks!
**Sorry for my english :(
Upvotes: 3
Views: 1523
Reputation: 21689
Make sure the Arial font is installed on the server - or use a private font (include the font with your project).
The API has changed with version 1.50. A sample for version 1.50 can be found here:
http://forum.pdfsharp.net/viewtopic.php?p=8961#p8961
A sample for the API used by version 1.3x can be found with the complete source package. See also:
http://pdfsharp.net/wiki/PrivateFonts-sample.ashx
Upvotes: 4