Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linebreaks inside SelectPdf

Tags:

c#

selectpdf

We're using the SelectPdf Html2Pdf api to generate pdf from html code. This is working well, but there is a problem we can't get find the solution. When we have a long line inside a

tag, this line is getting outside the pdf. What we would like, is that the line is breaking to multiple lines.

var html = $"<html><body><p>{aVeryLongLine}<p></body></html>";
SelectPdf.GlobalProperties.LicenseKey = "{our_license_key}";
var converter = new SelectPdf.HtmlToPdf();
converter.Options.AutoFitWidth = SelectPdf.HtmlToPdfPageFitMode.NoAdjustment;
converter.Options.AutoFitHeight = SelectPdf.HtmlToPdfPageFitMode.NoAdjustment;
var doc = converter.ConvertHtmlString(html, "");
var stream = new System.IO.MemoryStream();
doc.Save(stream);
pdfbytes = stream.ToArray();
stream.Close();
doc.Close();

We've tried to experiment with the HtmlToPdfPageFitMode, but that option only shrinks the line so it fits on the page, but that is unreadable, because it's getting too small. Does anyone know if there is an option to set this right?

like image 903
henk Avatar asked Feb 28 '26 05:02

henk


1 Answers

If your line does not contain any line break characters (like spaces), it will remain in 1 line. To allow it to be broken into several lines, you need to set the following style:

<p style="word-wrap: break-word;">{aVeryLongLine}</p>
like image 199
Tom Avatar answered Mar 02 '26 19:03

Tom