0

When using TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(); my PDF comes up blank. Edit: I believe it is not rendering the styling, but I'm unsure how to solve it. We are using .xsl classes to style the HTML, whereas the GeneratePDF(); function expects to be passed a CSS class, OR it uses the default W3 styling. In theory, it should just work because out styling is all inline anyway (See the HTML sample I've attached below).

Source: PDFGenerator

I have tried rendering the HTML straight to PDF, and also HTML to a bitmap image, then to a PDF.

PdfDocument pdf = PdfGenerator.GeneratePdf(faxBody, PageSize.Letter,20,null,null,null);
string path = HostingEnvironment.MapPath("~/App_Data/mytestpdf.pdf");
pdf.Save(path);

And/Or

PdfDocument pdf = PdfGenerator.GeneratePdf(faxBody, PageSize.Letter,20,null,null,null);
Bitmap bitmap = new Bitmap(1200, 1800);
PdfPage page = new PdfPage();
XImage img = XImage.FromGdiPlusImage(bitmap);
pdf.Pages.Add(page);
XGraphics xgr = XGraphics.FromPdfPage(pdf.Pages[0]);
xgr.DrawImage(img, 0, 0);
string path = HostingEnvironment.MapPath("~/App_Data/mytestpdf.pdf");
pdf.Save(path);

I took the second snippet from another Stackoverflow thread to try. I get the same result either way: A blank PDF. The string "faxBody" definitely contains HTML here.

If I run this in the Immediate Window:

pdf.Save(HostingEnvironment.MapPath("~/App_Data/mytestpdf.pdf"));

I get this:

"Expression has been evaluated and has no value."

PDF: mytestpdf.pdf

HTML string: HTMLsample

Mike
  • 51
  • 8
  • Would you show us a generated PDF? Is it an Azure Server? If yes, see also: http://stackoverflow.com/a/41095869/162529 – I liked the old Stack Overflow Dec 15 '16 at 08:36
  • I've updated the post to include a link to my last test PDF. I'm using MS SQL Server 2014. Thanks – Mike Dec 15 '16 at 17:00
  • I think my issue might be the styling. My file size is about 50KB, where a blank PDF is usually 12-15KB. We use XML/XSL -> HTML -> PDF. This function expects to be passed a CSS class to use, OR it uses defualt W3 styling. Even still, I'm surprised it doesn't work with the HTML block that is passed, because all of the styling is inline by that point. I'll add a sample of the HTML, too. – Mike Dec 16 '16 at 15:48

0 Answers0