vikrambalye / dompdf

Automatically exported from code.google.com/p/dompdf
0 stars 0 forks source link

proper support for counter-reset with an integer #488

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I would like to be able to set reset certain counters, in my case the 'page' 
counter. I have tried adding counter-reset: page 4; to both 'body' and 'html' 
on the print_header_footer.html example that comes with the dompdf and it 
didn't work. I tried to debug this on the sourcecode and I noticed that if I 
add it to the html rule, nothing happens, but if I add it to the body tag:

body {
counter-reset: page 4;
}

the Frame_Decorator::reset_counter($id, $value) is properly executed, but the 
$id becomes 'page 4'. I was hoping to submit a proper patch, but it was a bit 
hard for me to get a quick idea of where to modify it.

I then also tried to do a quick fix with the following code:

    $counters = preg_match_all('/(\w+) ([0-9]+)/', $id, $matches);
    for ($i = 0 ; $i < $counters ; $i++) {
      $this->get_parent()->_counters[$matches[1][$i]] = $matches[2][$i];
    }

Which works, but was resetting the counter on each page, so I ended up with the 
same page number on all pages.

I am trying to use this tool to create small pdfs then will be combined on a 
big pdf. I need the page number to be set in each pdf properly, that's why I 
was hoping to do this.

I will probably do a quick workaround to only reset the page number once, but I 
wonder if this can be added? I would think it's not that difficult if you know 
where to add it.

Thanks and greetings from Argentina,
Ariel.

dompdf: trunk, php: 5.3.10, os: linux debian

Original issue reported on code.google.com by abar...@gmail.com on 22 May 2012 at 2:47

GoogleCodeExporter commented 9 years ago
html { counter-reset: page 4; } triggers nothing apparently, should that work 
only once.

html { background: red; } doesn't work either but it does on normal HTML, is 
this a separate issue I should open?

Original comment by abar...@gmail.com on 22 May 2012 at 3:01

GoogleCodeExporter commented 9 years ago
I'm not sure how thoroughly (if at all) counter-reset is implemented. This is 
something that needs further development in the code. In the meantime, if all 
you need is set the current document page counter to a new starting value you 
can do so using counter-increment instead. See the following:

<html>
<head>
<style>
  div.first { counter-increment: page 3; }
  div:after { content: counter(page); page-break-after:always; }
</style>
</head>
<body>
  <div class="first">page</div>
  <div>page</div>
</body>
</html>

On your first page you need an uniquely identifiable element that you can use 
to increment the page counter. This is necessary because dompdf currently 
treats each page as a unique document. So you can't rely on tricks like 
body:first-child or anything like that.

..

For the problems related to CSS as applied to the <html> element, create a new 
issue.

Original comment by eclecticgeek on 31 May 2012 at 12:55

GoogleCodeExporter commented 9 years ago

Original comment by eclecticgeek on 24 May 2013 at 3:00