Forum How do I...?

Prince not honoring different placement of page numbers in left/right pages

elrond25
I have the following code:

@page {
size: 8.5in 11in;
margin: 0.5in 1in;
orphans:4; /* min number of lines of a paragraph left at bottom of a page */
widows:2; /* min number of lines of a paragraph that left at top of a page.*/
/* Footnote related attributes */
counter-reset: footnote;
@footnote {
counter-increment: footnote;
float: bottom;
column-span: all;
height: auto;
}
}

@page chapter {
@bottom-center {
vertical-align: middle;
text-align: center;
content: element(heading);
}
}

@page chapter:right {
@bottom-right-corner { content: counter(page) }
}

@page chapter:left {
@bottom-left-corner { content: counter(page) }
}

Problem is that Prince is printing the page number on both right and left pages. It is also ignoring the requirement of only putting them in chapter pages and it has put it everywhere.

Any ideas of what do I need to change to make it so page numbers will only display on chapter pages?
mikeday
Problem is that Prince is printing the page number on both right and left pages.

Since you have a rule for :left and :right, isn't that what you would expect?

What element are you applying "page: chapter" to?

By the way, widows/orphans can only be applied to blocks, not @page rules.
elrond25
I'll take widow/orphan out of the page declaration. Thanks for the tip.

Since I have a declaration for both left and right chapter pages I'd expect it to honor one or the other not both. Only the right side pages should get the page number on the right and only left side pages should get the page number on the left.

I apply all page rules to sections with a data-type attribute
mikeday
So all pages are getting page numbers in both corners?
dauwhe
I did a tiny test with your CSS:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8" />
	<title>Untitled</title>
	<style>
	@page {
size: 8.5in 11in;
margin: 0.5in 1in;
counter-reset: footnote;
@footnote {
counter-increment: footnote;
float: bottom;
column-span: all;
height: auto;
}
}

@page chapter {
@bottom-center {
vertical-align: middle;
text-align: center;
content: element(heading);
}
}

@page chapter:right {
@bottom-right-corner { content: counter(page) }
}

@page chapter:left {
@bottom-left-corner { content: counter(page) }
}

div {
page: chapter;
page-break-before: always;
}
</style>
</head>
<body>

<div>
<p>page one</p>

</div>

<div>
<p>page two</p>

</div>

</body>
</html>


And get page numbers as expected (see attached PDF).

If I'm getting page numbers where I don't want them, I often find I need to explicitly set that margin box to content: normal

@page chapter:right {
@bottom-right-corner { content: counter(page) }
@bottom-left-corner { content: normal }
}
  1. page.pdf16.2 kB
elrond25
@mikeday

Yes, all pages are getting numbers on both corners, whether they are chapter pages or not.


@dauwhe

Thanks, your solution fixed the problem for chapters. Now I need to work on why are page numbers appearing in non-chapter pages

Edited by elrond25

elrond25
I was able to make the page number disappear from the title page by using

@page titlepage{
@bottom-right-corner { content: normal }
@bottom-left-corner { content: normal }
}

But now I can't make the page number on the blank page generated by

section[data-type="chapter"] {
page: chapter;
page-break-before: always;
}
mikeday
You can style @page chapter:blank { ... }.
elrond25
I'm using

@page chapter:blank {
@bottom-left-corner { content: normal;}
@bottom-right-corner {content:normal;}
}

which worked for clearing the title page of the numbering, however when I run prince it still prints the page number on the bottom of the page before the chapter starts.

Am I missing something?