Creating a header und footer table for all pages

2,910 views
Skip to first unread message

zegerman

unread,
Feb 16, 2010, 5:12:55 AM2/16/10
to dompdf
Hi,

I want to create a PDF template with HTML. After i tried several other
pdf-generators I was happy to find dompdf... but i am stuck right...
and I hope some help me.

my template consists of:
- Header-table (Heading, Logo)
- Main-table (size: half of a page)
- Member-table (dynamic list of attenting people; has a table heading)

The member-table has the size upt to one page, therefore the last part
of that table is on page 2 without the table header.

I want to accomplish 3 Things:
1. Header-table with heading and logo on all pages
2. Addional footer-table with a horisontal line and the page number
3. Either a table heading on each page of the Member-table or to move
the whole table to the second page if the size exceeds the first page

I started with inline-php... but i dont get the hang of it. I can
place the header on all pages (but not as a table) but the spacing to
next table isnt working properly.

Are there any tutorials on howto layout a page or can anyone help me
to setup the header and footer?

What OI what comes pretty close to the dompdf samples "large_table"...
but when I view the code can't find the code to create the footer e.g.

Thx in advance
Plautzer

zegerman

unread,
Feb 16, 2010, 8:46:21 AM2/16/10
to dompdf
Hi,

after I did a lil more digging I found a soultion to 1 and 2:

<style type="text/css">
body {
margin:45mm 0mm 20mm 0mm;
padding:0px;
width: 210mm;
}

#list{
margin-left:10px;
margin-right:10px;
padding:0px;
}
</style>
</head>
<body>
<script type="text/php">
if(isset($pdf)){
$w = $pdf->get_width();
$h = $pdf->get_height();
//header
$header = $pdf->open_object();
$img_w = 124; // in points
$img_h = 82; // in points
$x = 15;
$y = 20;
$size = 22;
$font = Font_Metrics::get_font("helvetica");
$color = array(0,0,0);

$pdf->text(100,50,"HEADINFs", $font, $size);
$pdf->image("templates/logo.png", "png",442, 20, $img_w,
$img_h);
$pdf->close_object();
$pdf->add_object($header, "all");
//footer
$footer = $pdf->open_object();

// Draw a line along the bottom
$y = $h - $text_height - 20;
$pdf->line(28, $y, $w - 44, $y, $color, 0.5);

// Pages
$width = Font_Metrics::get_text_width("page1 von 2", $font, 10);
$text = "page {PAGE_NUM} of {PAGE_COUNT}";
$pdf->page_text($w / 2 - $width / 2, $y, $text, $font, 10, $color);
$pdf->close_object();
$pdf->add_object($footer, "all");
}
</script>


Now, I have two issues left:
1. I want to print the footer only if there are more than one pages
2. Repeating the table-heading of the member table on the second page
or printing the whole table on one page

can anyoen help with that?

Greetz

BrianS

unread,
Mar 1, 2010, 1:36:09 PM3/1/10
to dompdf
> Hi,
>
> after I did a lil more digging I found a soultion to 1 and 2:
>
> ...

>
> Now, I have two issues left:
> 1. I want to print the footer only if there are more than one pages
> 2. Repeating the table-heading of the member table on the second page
> or printing the whole table on one page
>
> can anyoen help with that?
>
> Greetz
>

You should be able to accomplish #2 by using a thead. So your table
structure could be similar to the following:

<table>
<thead>
{header rows}
</thead>
{table body}
</table>

Another option would be to use page-break-inside: avoid ... but DOMPDF
doesn't handle that option very well. DOMPDF could enter an infinite
loop if your table is too big to fit on one page.

As for #1 ... that's a little more difficult. First, the $pdf-
>page_text() method is a global setting, so you can't use it to add
text to only certain pages. And, unfortunately, the {PAGE_NUM}
placeholder is not available to the regular $pdf->text() method,
meaning there isn't really a way to insert the current page using this
method.

If I can think of a way to do it I'll let you know.

Reply all
Reply to author
Forward
0 new messages