Linebreaks inside SelectPdf

848 Views Asked by At

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?

1

There are 1 best solutions below

0
On BEST ANSWER

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>