Forum How do I...?

CSS alternative to prince command and CSS priority

Nick0164
Hi

I am fairly new to html/css and just trying to use prince to generate a paged html report. I've got it working but I have got a couple of queries.

The report is made up of a cover, toc and report sections.

I am adding a header to each page of the report where there is not already a section name. The start of each section is set by a div class called "page" and includes the section name. The header name is obtained by getting a string of the current section name.

In order to achieve this I am having to use prince-page-group: start in order to not show the header at the start of each page section. Is there a pure CSS standard implementation of this? I ask as I would like the print style sheet to be multi-program as the html report is sent to a third party who also converts the html to pdf but using the itext library.

When using prince I am using the inline style sheet within the HTML and using prince to import a separate prince style sheet for pagination. Within the inline style sheet I am using h6{page-break-before: always} and in the pagination style sheet h6{page-break-after: always}. The inline style sheet seems to have priority over the imported one. Is there a way to solve this? I have looked here princexml.com/doc/9.0/apply-css/ but couldnt find the answer.


Prince CSS:
@page{

size: A4;
margin: 10mm 14mm 15mm 25mm;
padding-top: 5mm;
font-family: Arial, Helvetica, Veranda;
font-size: 9.5pt;

@bottom-center {
	content: "Page " counter(page);
    }
	
@top-right { 
	content: string(header) " CONTINUED";
	margin-top: 5mm;
	border-bottom: 1px solid #000;
	font-weight: bold;
	}
}

@page page:first {
	padding-top: 2mm;	
    @top-right {
        content: none;
    }
}

@page cover {
	@top-right {
        content: none;
    }

    @bottom-center {
        content: none;
    }
}

@page toc {
	@top-right {
        content: none;
    }
	
    @bottom-center {
        content: none;
    }
}

.page {
    page: page;
    prince-page-group: start
}

.cover {
    page: cover;
}

.toc {
    page: toc;
}

div.toc p a:after {
		content: leader("...") target-counter(attr(href, url), page);
	}
	
div.toc {counter-reset: page 1}
	
p.title {string-set: header content()}

h6{page-break-after: always}
mikeday
Prince does not support any other mechanism to suppress headers/footers at the beginning of page groups. But we keep a close eye on the spec and coordinate with other implementations, so hopefully common standards will emerge over time.

If you apply page-break-before in one style sheet and page-break-after in another, then both properties will apply. If you want to cancel out one of them, then you will need to explicitly add a rule such as "page-break-after: auto".
Nick0164
Thanks Mike

Hopefully the standards will start to include this over time as it would be great to have a pure css implementation.

I have just been playing with the page break but coudnt get it to work. In the inline style sheet I am including:

@media print {

	h6{page-break-before: always}
}


Then in the external style sheet referenced via the prince gui setting it to:

@media print {

	h6{page-break-before: auto}
}


Setting it back to auto in the external style sheet seems to have no affect. Any thoughts?
mikeday
Are other rules applying? What if you apply "color: red" in the external style sheet? Or add:
h6 {page-break-before: auto !important}

to ensure that it overrides the other rule?
Nick0164
!important worked. Thought I had already tested it... It seems that the internal styles override the external.

Thanks
Nick0164
Sorry Mike, one last question then.

Just looking at the css3 spec (http://www.w3.org/TR/css3-page/#first-pseudo) example 7 shows
 @page CompanyLetterHead:first { ... } /*  identifier and pseudo page. */ 


I tried using this within prince instead of prince-page-group: start but couldnt get it to work.

I then came across this thread http://www.princexml.com/forum/topic/414/different-page-headers-on-first-pages which seems to conclude that prince used to support it but no longer does.

So am I write in saying that @page :first can not be used in conjunction with named pages within prince? If so is it something you will offer in the future?
mikeday
It cannot be used in conjunction with named pages unless you also use the prince-page-group property. Otherwise a rule like "@page name:first" will only match the first page of the document if that page also has the specified name, which is probably not what you want.

The reason for this is that there is no other way to match the first page of each chapter, as the page groups are immediately adjacent and would otherwise merge into one big page group. Since it is annoying to have to define a separate named page for each chapter, we need a way to indicate that the page group restarts at a particular element boundary.
Nick0164
Thanks for the explanation Mike. I've just done my final bits of testing and its working great. Will be purchasing this week