PDFsharp generates blank page in Azure, but works locally

你。 提交于 2019-12-02 00:36:01

问题


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!


回答1:


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/



来源:https://stackoverflow.com/questions/41051937/pdfsharp-generates-blank-page-in-azure-but-works-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!