different margin per page

749 views
Skip to first unread message

maverick

unread,
Mar 26, 2012, 8:45:59 AM3/26/12
to dompdf
Hi there,

I need to have different margin per page... even numbered pages should
have margin-right 10cm and odd numbered pages should have margin-left
10cm and margin-right 0cm... how can i do that?

was looking at different methods available in the $pdf object
available in inline php but couldn't find any that would change
margin... and i have found a problem with the method $pdf-
>get_page_number() and variable $PAGE_NUM which always return 1 ... i
am using dompdf 6.0 beta 2 and according to the posts in this group,
$PAGE_NUM should return the correct page number in dompdf 6.0

thx in advance for your help
Message has been deleted

BrianS

unread,
Mar 27, 2012, 10:45:13 PM3/27/12
to dom...@googlegroups.com
On Monday, March 26, 2012 8:45:59 AM UTC-4, maverick wrote:
I need to have different margin per page... even numbered pages should
have margin-right 10cm and odd numbered pages should have margin-left
10cm and margin-right 0cm... how can i do that?

So long as you're using at least beta 2 of v0.6.0 you can do this through HTML+CSS. Check out the following example:
http://eclecticgeek.com/dompdf/debug.php?identifier=b4059a83aac4c546d858b07d4a1a6e2b


was looking at different methods available in the $pdf object
available in inline php but couldn't find any that would change
margin... and i have found a problem with the method $pdf-
>get_page_number() and variable $PAGE_NUM which always return 1 ... i
am using dompdf 6.0 beta 2 and according to the posts in this group,
$PAGE_NUM should return the correct page number in dompdf 6.0

You wouldn't be able to affect the margins using inline script. The HTML rendering engine works to a large degree independently of anything you do via scripting.

As for your other problems, can you post some sample code? I suspect you're using them in a way that won't produce what you want. Inline scripts are only executed once even if the result is duplicated across multiple pages. So if you call get_page_number() on the first page you will always get "1" as the result.

There are methods available via both HTML+CSS and inline script that will output the current page number on a page. We can provide more detail once we know what you're trying to achieve.

maverick

unread,
Mar 28, 2012, 1:09:56 AM3/28/12
to dom...@googlegroups.com
The page numbering that's not a problem for me; was just pointing out that $PAGE_NUM does not seem to work.(but not my real problem atm)..

my problem is to have different margin per page... odd numbered pages should have margin-left:0 and margin-right:10cm while even numbered pages should have margin-left:10cm and margin-right:0.... how can that be achieved?

Fabien Ménager

unread,
Mar 28, 2012, 1:47:50 AM3/28/12
to dom...@googlegroups.com
You can achieve this like in the example Brian showed you : 

<style>
@page :odd { margin-left:10cm; }
@page :even { margin-right:10cm; }
</style>

maverick

unread,
Mar 28, 2012, 2:02:28 AM3/28/12
to dom...@googlegroups.com
sorry missed it!! but unfortunately, it does not seem to work... i am on beta2... that's weird! :(

Fabien Ménager

unread,
Mar 28, 2012, 3:19:00 AM3/28/12
to dom...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages