dompdf / dompdf

HTML to PDF converter for PHP
https://dompdf.github.io/
GNU Lesser General Public License v2.1
10.49k stars 1.79k forks source link

p { page-break-after: always; } causes infinite loop #864

Open franzholz opened 10 years ago

franzholz commented 10 years ago

The PDF generation seems to hang in an endless loop. After some modifications in the CSS the PDF generation never ends and causes an Apache timeout.

Here is the HTML source file:

http://jambage.com/fehlersuche/Zulu-Bill.html ``` PHPWord
The Wayback Machine - http://web.archive.org/web/20161107090944/http://jambage.com:80/fehlersuche/Zulu-Bill.html
ZULU PUBLISHERSWeggrund 8, 79533 Zulu Town, TansaniaTel. +49 (0) 5484.308, Fax +49 (0) 5484.550E-Mail: zulu@t-online.deSteuernummer: 337/7771/333 | Ust-ID: TA04928273 Bankverbindung:Postbank Tansania IBAN: TA44 4445 ßß45 7933 04 BIC: DDDDEFFKontoinhaber: Nuaga Dugut

Seite: ${pageno}

04.10.2014

Franz Holzinger, Meister Gerhard Str. 9, 50674 Köln

Rechnungsnr.: SHOP_43322

Kundennr.: 9442000388

Artikel Menge Einzelpreis (Euro) Gesamtpreis (Euro)
Apfel 1 1 1
Birne 2 2 4
Kirsche 3 3 9
Weintraube 4 4 16
Marille 5 5 25
Zwetschge 6 6 36
Orange 7 7 49
Mandarine 8 8 64
Pfirsich 9 9 81
Melone 10 10 100
Kiwi 11 11 121
Ananas 12 12 144
Banane 13 13 169
Nektarine 14 14 196
Dattel 15 15 225
Feige 16 16 256
Zitrone 17 17 289
Heidelbeere 18 18 324
Erdbeere 19 19 361
Haselnuss 20 20 400
Walnuss 21 21 441
Erdnuss 22 22 484
Stachelbeere 23 23 529
Quitte 24 24 576
Honigmelone 25 25 625
Kokosnuss 26 26 676
Vanille 27 27 729
Brombeere 28 28 784
Johannisbeere 29 29 841
Himbeere 30 30 900
Netto: 7945,38
MwSt. (19%): 1509,62
Brutto: 9455

Zahlung dankend erhalten!

```
bsweeney commented 10 years ago

The style that's causing problems is p { page-break-after: always; } ... which is just an insane style to begin with. Who wants to break pages after every single paragraph? Every. Single. Paragraph.

Removing the page break styling seems to fix things, but I'm not sure why it's causing the problem. It's not the styling itself, but something about your document combined with that styling (I can use that style on a simple document without issue). We'll need to look into this further.

franzholz commented 10 years ago

I have used this page-break-after clause because I copied it from this issue example I have found by my search engine search: https://github.com/dompdf/dompdf/issues/571 I just wanted to use a page number. I think that it is not an endless loop. This 2 page bill example generates hundreds of pages. Then the PDF generation hangs because of the PHP timeout after 240 seconds.

bsweeney commented 10 years ago

Who would write such crazy CSS ... oh. Ha ha. Sorry, yes.

The page break styling does exactly what it sounds like. After every p element a new page is created. I wanted to keep that example simple, it wasn't meant to be used in production. I'll try to do better with my sample code next time. Since all you really want is the page number, you can get rid of the page break styling. All you really need is this part:

<html>
  <head>
    <style>
      .footer { position: fixed; bottom: 0px; }
      .pagenum:before { content: counter(page); }
    </style>
  </head>
  <body>
    <div class="footer">Page: <span class="pagenum"></span></div>
  </body>
</html>

That being said, I think it could be an endless loop. You don't have enough p elements to create hundreds of pages. I think the page break styling may be getting pushed to a new page, causing a new page to render, then getting pushed yet again to a new page.