Articles in this section
Category / Section

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

1 min read

Windows azure web application doesn’t have the elevated permission to access the system fonts, so you can face unexpected exceptions when generating the ASP.NET WebForms 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:

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

Conclusion

I hope you enjoyed learning about how to handle the GDI restriction of Windows azure when creating the PDF document.

You can refer to our ASP.NET WebForm PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our ASP.NET WebForms PDF documentation to understand how to present and manipulate data.

For current customers, you can check out our ASP.NET WebForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our ASP.NET WebForms  PDF and other ASP.NET WebForms  components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied