Blazor HTML to PDF conversion Extra space at top and bottom of every page

We are converting HTML to PDF using Blink Rendering. It is working fine and it is creating some extra space at the top and bottom. That space is same in all pages.


We tried with adding remove header and footer, it's not the header and footer issue.
We tried with Margin set to zero and with some margin, but nothing change in that unwanted space.


Please Help us in this.


HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
BlinkConverterSettings settings = new BlinkConverterSettings();
settings.BlinkPath = Path.Combine(environment.ContentRootPath, "BlinkBinaries");
int viewportWidth = 1366;
int viewportHeight = 0;
settings.ViewPortSize = new Size(viewportWidth, viewportHeight);
htmlConverter.ConverterSettings = settings;
PdfDocument document = htmlConverter.Convert(sb.ToString(),"");
MemoryStream stream = new MemoryStream();
document.Save(stream);
document.Close(true);


1 Reply

GK Gowthamraj Kumar Syncfusion Team June 6, 2022 07:51 AM UTC

Hi Kishore,


We have tried to reproduce the reported extra spacing issue in HTML to PDF conversion on our end, but it is working properly and it renders the content fully on the pages without any spacing. We suspect that the baseURL was not specified to find the resources (scripts, styles) of the HTML string. For converting HTML string to PDF, we have to specify the base URL (path of the resources) to load the external scripts/styles used in the HTML string. So, try to provide the path (Base URL) contains (styles, scripts) used in the HTML string.
We have attached the runnable sample and output document for your reference, please try the sample on your end and let us know the result.


Sample:https://www.syncfusion.com/downloads/support/directtrac/general/ze/BlazorHTMLToPDF_Blink158725917

Output: https://www.syncfusion.com/downloads/support/directtrac/general/pd/HTMLToPDF_Blazor1929457452

UG: https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/blink#html-string-to-pdf


If you are facing any issue, we request you to share the complete input HTML/ URL (with all resources such as scripts, styles, etc) , product version, output document, modified sample to reproduce the issue in our end. So, it will be helpful for us to analyze and assist you further on this.   


Regards,

Gowthamraj K


Loader.
Up arrow icon