简体   繁体   中英

PDFsharp generates blank page in Azure, but works locally

This works in an ASP.NET MVC application when run locally, but not when deployed on Azure:

Document doc = new Document();  
Section section = doc.AddSection();
section.AddParagraph("Some text to go into a PDF");          
PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(false, PdfFontEmbedding.Always);
pdfRenderer.Document = doc;
pdfRenderer.RenderDocument();
System.IO.MemoryStream stream = new System.IO.MemoryStream();
pdfRenderer.PdfDocument.Save(stream, false);
Byte[] documentBytes = stream.ToArray();

return File(documentBytes, "application/pdf");

Locally, I get a nice PDF. On Azure, I get a blank PDF. I'm not seeing any exceptions thrown or other error messages. I found some SO answers stating that the GDI version of PDFsharp doesn't work on Azure, so I'm using the WPF version instead - same result.

I found this SO question, but I'm not clear how to apply it to an MVC app: Why is MigraDoc generating a blank pdf in my asp.net application?

Sorry if this is an obvious question, I'm just stuck!

It's likely a font problem if a complete PDF arrives at the client (I asked for conformation in a comment but got no answer yet).

PDFsharp must have access to the TTF files to extract information. Are the fonts you use in the %windir%\\fonts folder and does your process have privileges to read them?

Azure is a candidate for IFontResolver because many fonts are missing and privileges are usually not granted.

With IFontResolver you give PDFsharp direct access to the TTF files (as byte[]).

You can use my class EZFontResolver for that purpose:
http://developer.th-soft.com/developer/2015/12/11/ezfontresolver-a-generic-font-resolver-for-pdfsharp-and-migradoc/

I also have a sample that shows how to implement your own IFontResolver:
http://developer.th-soft.com/developer/2015/09/21/using-private-fonts-with-pdfsharp-1-50-beta-2-or-migradoc/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM