Fixing DOMPDF ‘Min/max width is undefined for table rows’ Error

Published by John on February 9, 2017 Under PHP

I sometimes use DOMPDF when I need to generate a pdf server side. It lets you use HTML to render a PDF and works fairly well, although has limited CSS support. What is neat about it is that you can literally just take a chunk of html and turn it into a PDF, so as someone who is fairly well versed in HTML, it makes generating a dynamic PDF quite easy/painless.

Recently, while converting a working email template over to a PDF, I ran into the below Min/max width is undefined for table rows Error. Since this was an email template using rather basic/standard table structure, I figured it would work without difficulty, but when I tried to load the pdf, I got the following error:

Error in /home/web/resources/dompdf/src/FrameReflower/TableRow.php on line 66: Min/max width is undefined for table rows

Since the supported CSS that you can use with Dompdf is relatively limited and it doesn’t like validation errors, I ran the HTML through a CSS validator, finding/fixing a few errors, but still was unable to get the PDF to render. I also did some looking around in the code and found where the error was coming from and tried a few things, such as changing the table-layout to fixed. This got me past the above error, but just caused another error to be thrown:

Error in /home/web/resources/dompdf/src/Cellmap.php on line 352: Frame not found in cellmap

The Fix

In this case, the fix ended up being pretty simple, it didn’t like the inline style ‘display:block;’ that I had added to the table. Upon a little more testing, I found that it would allow for ‘display:inline;’ or ‘display:inline-block;’. This makes sense as a table should probably have ‘display:table;’ and I think block is probably not really valid(although works fine in browsers, is a neat trick to apply to td elements to create a responsive table, and didn’t generate any warnings during validation.)

I think it re-enforces a pretty common theme with DOMPDF, which is that if it doesn’t render correctly, there is a better than average chance that you are doing something either invalid or unsupported in your PDF’s CSS/Styles.

If this doesn’t work for you, a good first step is to remove all Styles and verify the PDF renders. If it does, either add your styles back one by one or remove them one by one until you find the style(s) that are causing the issue.


No Comments |

Add a Comment