HTML-Renderer icon indicating copy to clipboard operation
HTML-Renderer copied to clipboard

I got an 'System.InvalidOperationException' and message 'Cannot save a PDF document with no pages.'

Open denghuichao opened this issue 8 years ago • 9 comments

I generate a PdfDocument with TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.Letter), and the html has contents, but the PdfDocument is empty and cause a 'System.InvalidOperationException' when i save the document by pdf.Save(memoryStream)

denghuichao avatar Sep 07 '17 09:09 denghuichao

@denghuichao Any luck with this error

rgarita avatar Oct 12 '17 06:10 rgarita

Same situation for me

AlejandroGen avatar Jan 18 '18 17:01 AlejandroGen

Same for me when using in a Azure Function

brettflitter avatar Aug 28 '18 16:08 brettflitter

Hi guys, same issue for but only for first load of the application, any fix on this?

mbtix avatar Oct 10 '18 06:10 mbtix

any update on this? I'm having the same error reading an html file

mlaguayojr avatar Apr 30 '19 14:04 mlaguayojr

I was also getting this error, and I believe it was due to my Bootstrap column layout. Bootstrap puts display: flex; on elements with class="row", and HtmlRenderer doesn't seem to handle that well.

Here's a minimal reproduction; this code throws "System.InvalidOperationException: Cannot save a PDF document with no pages".

var htmlString = @"<div class=""row"">Hello, world!</div>";

var styleSheet = @".row { display: flex; }";

var pdf = PdfGenerator.GeneratePdf(
    html: htmlString,
    pageSize: PageSize.Letter,
    cssData: PdfGenerator.ParseStyleSheet(styleSheet));

pdf.Save("PdfSharp_FlexLayout.pdf");

I'm afraid I don't have a workaround at this time.

benj2240 avatar Sep 19 '19 21:09 benj2240

@benj2240 have you found a solution for this bug?

cfrancoluna avatar Dec 15 '21 21:12 cfrancoluna

@cfrancoluna I'm afraid not. I had to take my project in a different direction.

benj2240 avatar Dec 15 '21 22:12 benj2240

@benj2240 Ok thank for your time

cfrancoluna avatar Dec 15 '21 22:12 cfrancoluna