Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 problems with Dompdf : 1 due to 100% value, 1 on table/tr/td or css equivalent #1337

Closed
sdonnet opened this issue Dec 22, 2016 · 1 comment
Labels

Comments

@sdonnet
Copy link

sdonnet commented Dec 22, 2016

Hi,

I have an 0.7.0 Dompdf installation, on an Ubuntu server, with PHP > 5.5.

First problem :

With the following html (stored in $html) :

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Character Sheet</title>
        <meta name="description" content="Character Sheet, by SagaS">
    <style type="text/css" >
  .page
  {
    border: 1pt solid black;
    width: 100%;
    height: 100%;
  }
    </style>
    </head>
    <body>
      <div class="page">
          <p>Some Text...</p>
      </div>
    </body>
</html>

and with following code :

       $dompdf = new Dompdf();
        $dompdf->setPaper('A4', 'portrait');
        $dompdf->set_option('isHtml5ParserEnabled', TRUE);
.../...
        $dompdf->loadHtml($html);
        $dompdf->render();
        $dompdf->stream("sample.pdf", array("Attachment"=>0));

I produce a 3-pages PDF, the pages one and three being blank, the page two containing my rectangle, with "Some Text..."

If I change height by any absolute value (as 600pt for instance), I got a one-page PDF, but rectangle does not fit the whole page

I need to control the full page, because I want to write the same HTML, for "letter" or "A4" formats, and I need to work with relative values (25%, 50%, ...) for bocks inside my full page. Is the problem due to "height: 100%" ?

Second problem :
(quite relative to first one)

I wanted to use table/tr/td to structure my page, but as soon as I write even a minimal table structure, I got a max_execution_time (of course, I am no more with a page class with its 100% height).

The following HTML code crashes:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Character Sheet</title>
        <meta name="description" content="Character Sheet, by SagaS">
    <style type="text/css" >
  .page
  {
    border: 1pt solid black;
    width: 300pt;
    height: 500pt;
  }
    </style>
    </head>
    <body>
      <table>
        <tr>
          <td>Some Text...</td>
        </tr>
      </table>
    </body>
</html> 

I have read other same issues, regarding "anonymous table", and I am ready to replace them by a bunch of span with css styles, but I am not able to control the width of each cell, row by row.
I want to perform for instance :
first row, with 3 cells, at 33%
second row, with 2 cells, at 75%/25%, ...
Most of the time, my "width:XX" are not taken into account, and cells adjust themselves to their content.

Is there a bullet-proof method to control the widths ?

Best Regards

@bsweeney
Copy link
Member

For the first problem, you should style your body element to produce a rectangle that spans the length of the content area of the page (.page { border: 1pt solid black; }).

Your second issue isn't related to anonymous tables, it's due to the fact that currently dompdf is unable to split table cells across pages. So if any table cell spans more than one page it may cause dompdf to enter an infinite loop as it tries to move the entire table row to the next page. See #98.

So you can use the table method to style your content, just keep that limitation in mind.

Finally, with regard to setting a width. You can't give an inline element (e.g. a span element) a width. If you want to do that you should style your span with display: inline-block;. But really you probably want to use a div element instead. But no matter which route you take keep in mind that because of the way dompdf renders the HTML if you have a block element that flows beyond the bound of the page a page break will occur inside that element (except for table cells). Any content that is adjacent to the element will also flow to the next page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants