Hello GemBox Support Team,
I’m experiencing content overflow issues when converting HTML email content to PDF using GemBox.Document. The problem occurs when HTML contains fixed-width tables and long unbreakable strings (such as URLs), causing parts of the content to extend beyond the PDF page boundaries and become invisible.
Problem Details:
When converting email messages (specifically newsletter-style emails with fixed-width layouts) to PDF, content at the right edge of the page gets cut off and becomes invisible. The HTML typically contains:
- Fixed-width tables (e.g., )
- Long URLs in links that don’t break naturally
- Inline styles with fixed pixel widths
- Nested table structures, common in email templates
Sample method for testing/reproducing the issue:
public static void ConvertHtmlToPdfMinimalExample(string htmlContent, string outputPdfPath)
{
var document = new DocumentModel();
var options = new HtmlLoadOptions();
document.Content.End.LoadText(htmlContent, options);
if (document.Sections.Any())
{
foreach (var section in document.Sections)
{
var pageMargins = section.PageSetup.PageMargins;
pageMargins.Top = 36;
pageMargins.Bottom = 36;
pageMargins.Left = 54;
pageMargins.Right = 54;
}
}
document.Save(outputPdfPath, SaveOptions.PdfDefault);
}
Here is GemBox’s conversion result that illustrates the issue.
I can provide sample email HTML files that demonstrate the issue if that would be helpful for reproduction.
Questions:
- Does GemBox.Document provide any built-in options in HtmlLoadOptions to automatically scale or fit HTML content to the PDF page width?
- Is there a recommended approach for handling fixed-width HTML content (like email templates) to ensure it fits within PDF page boundaries?
- Can GemBox.Document be configured to automatically:
• Override fixed-width styles in HTML
• Break long URLs/text that would cause overflow
• Scale down content proportionally to fit the page
- Are there any properties on HtmlLoadOptions or LoadOptions that could help with this scenario? For example, something like:
• PreferredWidth or MaxWidth
• AutoFit or ScaleToFit
• Word-breaking or text-wrapping controls
Desired Behavior:
Ideally, I’d like GemBox.Document to either:
• Automatically scale fixed-width HTML content to fit the PDF page width, or
• Provide configuration options to enforce content fitting without requiring manual CSS injection/manipulation
Thank you for your assistance!
Hi Yaroslav,
Yes, please send us a sample HTML that reproduces your issue so we can investigate it.
You can send it via email or support ticket, see the Contact page.
Regarding this requirement, no option or configuration will allow you to adjust or scale the content automatically.
However, you could try this workaround that specifies 100% width on tables that are larger than the page width:
var pageSetup = document.Sections[0].PageSetup;
double maxWidth = pageSetup.PageWidth - pageSetup.PageMargins.Left - pageSetup.PageMargins.Right;
foreach (Table table in document.GetChildElements(true, ElementType.Table))
{
var tableWidth = table.TableFormat.PreferredWidth;
if (tableWidth.Unit == TableWidthUnit.Point && tableWidth.Value > maxWidth)
table.TableFormat.PreferredWidth = new TableWidth(100, TableWidthUnit.Percentage);
}
Or instead, you could increase the page width.
I hope this helps.
Regards,
Mario
Hi,
Please try using this:
var document = new DocumentModel();
document.Content.End.LoadText(htmlContent, LoadOptions.HtmlDefault);
var pageSetup = document.Sections[0].PageSetup;
var pageMargins = pageSetup.PageMargins;
pageMargins.Top = 36;
pageMargins.Bottom = 36;
pageMargins.Left = 54;
pageMargins.Right = 54;
double maxWidth = pageSetup.PageWidth - pageSetup.PageMargins.Left - pageSetup.PageMargins.Right;
double maxTableWidth = document.GetChildElements(true)
.OfType<Table>()
.Select(t => t.TableFormat.PreferredWidth)
.Where(tw => tw.Unit == TableWidthUnit.Point)
.Max(tw => tw.Value);
if (maxTableWidth > maxWidth)
pageSetup.PageWidth += maxTableWidth - maxWidth;
document.Save(outputPdfPath, SaveOptions.PdfDefault);
Does this solve your issue?
Regards,
Mario
Hi Mario,
Thank you for a prompt reply!
Unfortunately, the suggested approaches do not fix everything. There is still some content that becomes invisible/gets out of the boundaries.
Here you can see a fragment of the 3rd page of the document that demonstrates the issue:
The screenshot is taken for the second suggestion (with extending page size), but a similar issue is present with the first one as well.
Also, for my case, I think it’s undesirable to change the page size, so hopefully, there is another solution for that.
And I think adding such code to workaround this particular case would not guarantee that a similar issue will not appear again in cases where a couple of large objects (even, possibly two tables) are placed next to each other would appear on the same page (or some other corner cases).
Hi Yaroslav,
Please try again with this NuGet package:
Install-Package GemBox.Document -Version 2025.12.123
Does this solve your issue?
Regards,
Mario
Hi Mario.
Unfortunately, it still doesn’t seem to be working (with 2025.12.123 and proposed page resize code).
The 3rd and 4th pages highlight the problem the best:
Hi Yaroslav,
Please try again with this NuGet package:
Install-Package GemBox.Document -Version 2025.12.125
Does this solve your issue?
Regards,
Mario
Hi Mario,
It works amazingly in combination with the page resize you suggested earlier - thank you!
I also noticed that with the new version of GemBox.Document it works much better even without resizing the page. Previously, the right column was completely invisible (rendered outside the page boundaries), but now it almost fits the page on its own.
VS
This gives me hope that it might be possible to improve it even further, so that extending the page size won’t be necessary at all to fit the content.
Thanks again for the great help!