Search code examples
pdfwkhtmltopdfnreco

Converted PDF not coming on Full Page using Nreco HTML to PDF converter


I am using a HTML to PDF converter called Nreco and using the tool, i am creating PDF files based on a HTML template using C#.

Everything seems to be working fine apart from the fact that i can`t get the PDF to be shown in Full PDF page (i.e there are white bars around the PDF). I was able to play around with the Margins to get the Top and bottom Margins sorted out but the left and right are still causing issues. There is also extra blank space below the page which makes me think that the converted PDF is not on an A4 size even though i am defining the Page size.

Can anyone help me on this?

The code i am using is as below:

var pageMargins = new NReco.PdfGenerator.PageMargins { Bottom = 0, Left = 0, Right = 0, Top = 0 };
  var htmlContent = HTMLPart1 + FinalHTMLPart2 + HTMLPart3;
                var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
                htmlToPdf.Size = NReco.PdfGenerator.PageSize.A4;
            htmlToPdf.Margins = pageMargins;
            var path = Server.MapPath("~/PDF/" + FileName);
                var path2 = path.ToString();
                //var pdfBytes = htmlToPdf.GeneratePdf(htmlContent);

                htmlToPdf.GeneratePdf(htmlContent, null, path2);

A screenshot to show you what i mean:

You can see that there is extra spaces around the Page and some sort of a shadow as well


Solution

  • okay guys i figured it out, The problem was with the template i was using, it had box-shadow defined in the HTML BODY tag, silly of me to not catch that.

    So all is good.

    html body{font-family:"Open Sans","Helvetica Neue",Helvetica,Arial,Sans-serif;background:white;width:100%;min-height:1158px;
    

    (remove the below)

    -moz-box-shadow:0px 0px 20px rgba(80,80,80,0.7);-webkit-box-shadow:0px 0px 20px rgba(80,80,80,0.7);box-shadow:0px 0px 20px rgba(80,80,80,0.7)}