1
Vote

Azure Website

description

Hi,
I am trying to use HtmlRenderer.PdfSharp in Azure. It works perfectly right on local computer, but once deployed on an Azure WebSite (no VM, Web App), I keep getting the following error :

Cannot save a PDF document with no pages.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Stack Trace:
[InvalidOperationException: Cannot save a PDF document with no pages.]
PdfSharp.Pdf.PdfDocument.DoSave(PdfWriter writer) +769
PdfSharp.Pdf.PdfDocument.Save(Stream stream, Boolean closeStream) +257

Source code is pretty simple actually, for testings I have :
MemoryStream ms = new MemoryStream();
        StringWriter wr = new StringWriter();
        using (HtmlTextWriter writer = new HtmlTextWriter(wr))
        {

            writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily, "Arial");
            writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize, "22pt");
            writer.AddStyleAttribute(HtmlTextWriterStyle.FontWeight, "bold");
            writer.RenderBeginTag("p");

            writer.Write("Ordre de mission");
            writer.RenderEndTag();

            using (PdfDocument pdf = PdfGenerator.GeneratePdf(wr.ToString(), PageSize.A4))
            {
                pdf.Save(ms, false);
            }
        }
Thank you for your help!
Pierre

comments