I believe DOMPDF is using a fairly limited character set for determining how to split a line. Right now it only splits a line at a dash or a space. So something like the URL you have in your sample is going to run past the width of the container. DOMPDF just doesn't know how to break it up.

Starting with dompdf v0.6.0 you can style your text so that words are broken at any character, e.g.:

<span style="word-wrap: break-word;">http://example.com/really/long/.../url</span>

It's not as clean as breaking on a particular character (e.g. a /). If you're comfortable hacking the code you can work around the problem a little more elegantly. Open up the text reflower class and modify the regular expression that splits the line. The regular expression looks like the following:

preg_split('/([\s-]+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE)

Modify that code to include whatever extra characters you think will make for a good line break. You might, for example, break URLs up on ?, &, or even / if you expect to have extremely long URLs in your text:

$words = preg_split('/([\s-\?\&\/]+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE);

In dompdf 0.6.1 the RegEx can be found in dompdf/include/text_frame_reflower.cls.php lines 86 and 371. In the upcoming 0.7.0 the RegEx can be found in dompdf/src/FrameReflower/Text.php lines 106 and 402.

The drawback to modifying the RegEx is that this will affect all text (not just URLs).

Answer from BrianS on Stack Overflow
Top answer
1 of 2
4

I believe DOMPDF is using a fairly limited character set for determining how to split a line. Right now it only splits a line at a dash or a space. So something like the URL you have in your sample is going to run past the width of the container. DOMPDF just doesn't know how to break it up.

Starting with dompdf v0.6.0 you can style your text so that words are broken at any character, e.g.:

<span style="word-wrap: break-word;">http://example.com/really/long/.../url</span>

It's not as clean as breaking on a particular character (e.g. a /). If you're comfortable hacking the code you can work around the problem a little more elegantly. Open up the text reflower class and modify the regular expression that splits the line. The regular expression looks like the following:

preg_split('/([\s-]+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE)

Modify that code to include whatever extra characters you think will make for a good line break. You might, for example, break URLs up on ?, &, or even / if you expect to have extremely long URLs in your text:

$words = preg_split('/([\s-\?\&\/]+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE);

In dompdf 0.6.1 the RegEx can be found in dompdf/include/text_frame_reflower.cls.php lines 86 and 371. In the upcoming 0.7.0 the RegEx can be found in dompdf/src/FrameReflower/Text.php lines 106 and 402.

The drawback to modifying the RegEx is that this will affect all text (not just URLs).

2 of 2
1

Open up the file dompdf/include/text_frame_reflower.cls.php and fine the line that looks like the following:

$words = preg_split('/([\s-]+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE);

Modify the regular expression to include whatever extra characters you think will make for a good line break. You might, for example, break URLs up on ?, &, or even / if you expect to have extremely long URLs in your text:

$words = preg_split('/([\s-\?\&\/]+)/u', $text, -1, PREG_SPLIT_DELIM_CAPTURE);

Also replace the following line

$words = array_flip(preg_split("/[\s-]+/u",$str, -1, PREG_SPLIT_DELIM_CAPTURE));

with

$words = array_flip(preg_split('/([\s-\?\&\/]+)/u', $str, -1, PREG_SPLIT_DELIM_CAPTURE));
🌐
GitHub
github.com › dompdf › dompdf › issues › 1727
Problems with tables in PDF · Issue #1727 · dompdf/dompdf
January 11, 2018 - dompdf / dompdf Public · Notifications · You must be signed in to change notification settings · Fork 1.8k · Star 11k · New issueCopy link · New issueCopy link · Open · Open · Problems with tables in PDF#1727 · Copy link · Labels · bug · andreshg112 ·
Author   andreshg112
🌐
GitHub
github.com › dompdf › dompdf › issues › 3495
Table content overflowing off Page · Issue #3495 · dompdf/dompdf
July 16, 2024 - When having large bodies of text in a table it will overflow off the bottom of the page and not carry on to the next page, as shown: Using: ...
Author   chdonncha
🌐
Stack Overflow
stackoverflow.com › questions › 65469907 › dompdf-table-cells-overflowing-outside-table
laravel - dompdf table cells overflowing outside table - Stack Overflow
December 27, 2020 - I am generating a PDF using dompdf and one of the table cells is overflowing past the edge of the page. I am unable to find any reasoning for this as when displayed as a regular HTML page this does...
🌐
Google Groups
groups.google.com › g › dompdf › c › DSR95EmpCnI
More problems with the tables in DOMPDF
I was able to duplicate your problem using DOMPDF 0.6.0 alpha 2. The issue has already been addressed in the latest dev version of DOMPDF.
🌐
GitHub
github.com › dompdf › dompdf › issues › 1933
Footer does not appear in case of table overflow · Issue #1933 · dompdf/dompdf
May 13, 2019 - I am creating a 5 page report using dom pdf. Each page has it custom header and footer. These headers and footers appears correctly on all pages of the report except on the page where the table overflows to the next page. If the table na...
🌐
Stack Overflow
stackoverflow.com › questions › 36565557 › how-to-display-the-large-table-without-breaking-in-the-dompdf-while-generating-t
php - How to display the large table without breaking in the dompdf while Generating the Pdf - Stack Overflow
In v0.7.0 set the option after instantiating dompdf: $dompdf->set_option('dpi', 300); Finally, drop the page-break-inside: avoid; styling. This can be particularly problematic with content that exceeds the page size, particularly tables.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 29615960 › table-content-overlap-in-page-dompdf
php - Table content overlap in page dompdf - Stack Overflow
April 13, 2015 - i was thinking to do with inline elements and not with tables, but are you sure this can't be done with tables? ... Not 100% but you have DOMPDF right there, try a test. :) Try two rows, one cell in each. Make the rows very high and see if it breaks onto two page.
🌐
GitHub
github.com › dompdf › dompdf › issues › 2189
Page breaking on table · Issue #2189 · dompdf/dompdf
July 5, 2020 - I am trying to bring a weekday table into a PDF. It probably won't fit on one landscape page, so I am looking for a way to have more control over where to do the page break. I have tried page-break-inside: avoid on the table and page-bre...
Author   hhjung2013
🌐
GitHub
github.com › dompdf › dompdf › issues › 1017
Table cell width is not honored if content exceeds the specified dimensions · Issue #1017 · dompdf/dompdf
September 14, 2015 - dompdf has some layout issues with tables that prevents it from limiting width when the contents are larger than the cell size... Just be sure to specify a width on the container and style with word-wrap: break-word; This particular issue occurs ...
🌐
Stack Overflow
stackoverflow.com › questions › 49479618 › dompdf-table-breaks-wrongly
html - DOMPDF table breaks wrongly - Stack Overflow
table { border: 0.3px solid black; page-break-inside: avoid !important; } ... Sign up to request clarification or add additional context in comments. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... I’m Jody, the Chief Product and Technology Officer at Stack Overflow.
🌐
Stack Overflow
stackoverflow.com › questions › 79595680 › dompdf-table-display-is-messy-when-using-rowspan-and-page-break
php - Dompdf - Table display is messy when using rowspan and page break - Stack Overflow
i have a problem with dompdf when using rowspan and table overlaps down, this issue is usually solved by adding css page-break-inside: avoid; but without rowspan, when i add rowspan the table contents are messed up when the data is cut down
🌐
Stack Overflow
stackoverflow.com › questions › 42506638 › dompdf-page-breaking-table-if-exceed-table-height
html - dompdf page breaking table if exceed table height - Stack Overflow
and it's work, i just need to move the number after 10 to the next page / the table exceed the height. if i use overflow : hidden; it sure to hide the row but not showing at the next page. any 1 have idea? thanks for your time sire. best regards · html · css · dompdf ·