title: C# MVC generate PDF from View with NReco.PdfGenerator
body: <p>I'm currently working on a project where I need to create a "dashboard" which can be exported as pdf. I wanted to use Rotativa but as our application uses .NET framework 4.0 it's not possible. So I found the NReco PdfGenerator. </p>
  
  <p>Now that's the code how I create the PDF result:</p>
  
  <pre><code>var ViewAsString = RenderViewAsString("~/Views/QMetrics/StandardDashboard.cshtml", viewModel);
  var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
  htmlToPdf.PageWidth = 1600;
  htmlToPdf.PageHeight = 900;
  var pdfBytes = htmlToPdf.GeneratePdf(ViewAsString);
  FileResult FileResult = new FileContentResult(pdfBytes, "application/pdf");
  FileResult.FileDownloadName = "Dashboard-" + viewModel.ProjectName + "-" + 
  DateTime.Now.ToString() + "-.pdf";
  return FileResult;
  </code></pre>
  
  <p>It successfully creates the PDF page with all the content that comes from the backend (Project information, and so on) but the page looks very ugly. On the original page I have 2 columns and on the PDF page it puts everything in one column. I tried a few different page sizes and I also changed the layout to be non-responsive but nothing has changed. </p>
  
  <p>My first suggesstion was that the referenced CSS and JS files are not included when the PDF get's created, so I copied all the stuff that comes from external files (bootstrap, Chart.js) and pasted it directly in the .cshtml file. But nothing changed at all. My Chart is not rendering/loading and the missing CSS stuff is still not there. </p>
  
  <p>On the NReco PDFGenerator website they say that it supports complex CSS code and also javascript code so I don't really understand why this is not working. </p>
  
  <p>Has anyone here experiences with NReco or can someone recommend something else that works for .NET 4.0? </p>