Dynamic page header / body margin

340 views
Skip to first unread message

batss...@gmail.com

unread,
Nov 4, 2009, 4:49:29 PM11/4/09
to dompdf
I'm rendering a report with a bunch of different sections and what I'm
trying to do is add "Section 2 (CONT.)" text dynamically if necessary
on each page.

Right now, I have a <script> block to render a header on each page:

<script type="text/php">
if (isset($pdf))
{
$header = $pdf->open_object();

// render stuff - about 1 inch

$pdf->close_object();
$pdf->add_object($header, "all");
}
</script>

Then, we set the body margin in the css to make sure the body text
does not overlap the header:

body {
...
margin-top: 78pt;
}


I was thinking that I can use add_object($continueText, "next") and
stop_object($continueText) to add the text to each page, but how can I
dynamically adjust the body margin to account for that? Sometimes a
section will end at the bottom of a page and we won't want the space
on the next page.

Is this possible? Thanks.

BrianS

unread,
Nov 4, 2009, 11:51:30 PM11/4/09
to dompdf
On Nov 4, 4:49 pm, "batssha...@gmail.com" <batssha...@gmail.com>
wrote:
Your thought to use an object to set the text for the next page then
discontinue it at the end of the section sounds good. Unfortunately, I
don't see any way that you would be able to use inline script to
affect the margins of the document. The content that you create using
inline script is completely separate from the content of the HTML
document. Also, any objects created using inline script are placed on
the page after the HTML content has been rendered, so DOMPDF would
have no way of knowing in advance that it needs to modify the
positioning of the content. Also, I can't say of any way you would be
able to modify the CSS dynamically using inline script.

Your only hope, then, is perhaps through CSS. You could still use an
inline script to create your header text, but use CSS to style the
section so that after the initial page the margin is adjusted. Or
perhaps there's a purely CSS way to accomplish what you want. Sadly,
I'm at a loss for a solution.

BrianS

unread,
Nov 5, 2009, 12:44:08 AM11/5/09
to dompdf
Your problem was intriguing to me so I spent a little time hacking at
it. Take a look at this document as a possible solution:
http://eclecticgeek.com/dompdf/debug_tests/87a83a6cb712ddf7.htm

You'll need to be using DOMPDF 0.6.0 alpha2 for the CSS to render
correctly. Or you can view the rendered document here:
http://eclecticgeek.com/dompdf/index.php?input_file=87a83a6cb712ddf7.htm&paper=&orientation=&dompdf_ver=trunk&load_method=1&submit=submit

Unfortunately, rendering this document shows that the object functions
are not behaving as expected when using CPDF. Perhaps it is my own
system, so if you try it out let me know if your experience is
different. I'll test on another system when I get a chance.

Even with the rendering issues you can see how this might present a
solution to your problem.

Scott Webber

unread,
Nov 5, 2009, 9:16:16 AM11/5/09
to dom...@googlegroups.com
Hi Brian,

I had the same results locally. It looks like you may be on the right
track, though there are a few issues:

1) The first paragraph of Section 2 is wrapping to the next page and
ignoring the margin adjustment.
2) I am actually using tables for most of my content. I will try to
tweak your example to use some long tables and see what happens.

The problem with Cpdf is that addObject(obj, 'next') is not actually
implemented - he has it using the 'all' logic. Has Cpdf support
discontinued? If I make changes to it, who do I have to submit them
to?

Thanks for your help on this.

Scott Webber

unread,
Nov 5, 2009, 10:52:20 AM11/5/09
to dom...@googlegroups.com
It looks like addObject(obj, 'add') doesn't even work correctly. It
should add only to the current page, but it is rendering on all pages.

BrianS

unread,
Nov 5, 2009, 11:14:17 AM11/5/09
to dompdf
On Nov 5, 10:52 am, Scott Webber <batssha...@gmail.com> wrote:
> On Thu, Nov 5, 2009 at 9:16 AM, Scott Webber <batssha...@gmail.com> wrote:
> > Hi Brian,
>
> > I had the same results locally.  It looks like you may be on the right
> > track, though there are a few issues:
>
> > 1) The first paragraph of Section 2 is wrapping to the next page and
> > ignoring the margin adjustment.
> > 2) I am actually using tables for most of my content.  I will try to
> > tweak your example to use some long tables and see what happens.
>
> > The problem with Cpdf is that addObject(obj, 'next') is not actually
> > implemented - he has it using the 'all' logic.  Has Cpdf support
> > discontinued?  If I make changes to it, who do I have to submit them
> > to?
>
> > Thanks for your help on this.
>
> >>http://eclecticgeek.com/dompdf/index.php?input_file=87a83a6cb712ddf7....
>
> >> Unfortunately, rendering this document shows that the object functions
> >> are not behaving as expected when using CPDF. Perhaps it is my own
> >> system, so if you try it out let me know if your experience is
> >> different. I'll test on another system when I get a chance.
>
> >> Even with the rendering issues you can see how this might present a
> >> solution to your problem.
>
> It looks like addObject(obj, 'add') doesn't even work correctly. It
> should add only to the current page, but it is rendering on all pages.

Yes, there do seem to be some problems with object handling in CPDF.
If you figure out what needs to be done to fix things just submit the
code changes to us. I don't know that CPDF is in active development,
and there have been quite a few modifications to the code by the
DOMPDF team.

FYI, the object handling also appears to be broken in PDFLib. I was
getting the same results as when I used CPDF.
Reply all
Reply to author
Forward
0 new messages