We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to handle the GDI restriction of Windows azure when creating the PDF document

Platform: ASP.NET Web Forms |
Control: PDF |
Published Date: November 30, 2015 |
Last Revised Date: April 25, 2019

How to handle the GDI restriction of Windows azure when creating PDF document?

Windows azure web application doesn’t have the elevated permission to access the system fonts, so you can face unexpected exceptions when generating the PDF document. You can work around this by attaching the TTF fonts with the Web application and access it in the program. Please refer the below code snippet for the same.

C#

//Creating the new PDF document
PdfDocument doc = new PdfDocument();
doc.PageSettings.Size = PdfPageSize.Letter;
doc.PageSettings.Orientation = PdfPageOrientation.Portrait;
 
PdfPage page = doc.Pages.Add();
PdfColor color = new PdfColor(System.Drawing.Color.Black);
PdfSolidBrush brushBlack = new PdfSolidBrush(color);
 
//Creating the new font from the TTF file
PdfFont font = new PdfTrueTypeFont(Server.MapPath(@"~/App_Data/calibri.ttf"), 24, PdfFontStyle.Regular);
 
page.Graphics.DrawString("Hello World", font, PdfBrushes.Red, 0, 0);
 
//Save the PDF document
doc.Save("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save);
 
//Close the PDF document
doc.Close(true);

 

Sample project:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/PDFFontTest827240610

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon