Forum How do I...?

CSS3 string-set and content property

matt_d_rat
Hi,

Was wondering whether anyone could help me solve a small issue I am having. The software I am writing uses prince to generate pdfs of invoices. A requirement for the invoice is to have the registered company address and vat number on the invoice, this is usually placed in a footer. Occasionally invoices will be too big to fit on a single page and will break onto a second which is fine, but in this case the registered company address that appears in the footer needs to appear in the footer of both pages.

I achieved this without problem using:

@page { @bottom-center { content: 'Footer Text Here';} 


Now the issue I am having is that I must generate this footer text dynamically, which itself is not a problem - however the text is only appearing on the last page and not all pages. I am using the following code to pull the text from the html document and pass it to css content property:

@media print {
	.cb-registered-office {
		string-set: company_reg contents; /* Get the contents from the footer and save them to string company_ref */
		position: absolute;
		visibility: hidden; /* Hide the footer so it doesn't appear in the pdf */
	}

	@page {
		margin: 0.5cm 1cm 2.5cm 1cm;
		size: A4 portrait;
		@bottom-center {
			content: string(company_reg); /* Load contents for company_reg into the page footer */
			font-size: 7pt;
		}
	}
}


Would this issue occur if the element from which I am pulling the content from over spills itself onto the second page? So when it comes to generating the first page of the PDF, the element is somehow not there on that page from which to pull the content? Any ideas how to get around this problem?
jim_albright
I think you are on the right track. There must be content before you will get anything to show up.
Can you put it in the metadata? That would ensure it would be present on first page.

Jim Albright
Wycliffe Bible Translators

matt_d_rat
I do have the option of putting it in the meta data. How would I write this and what is the css property for pulling content from a metatag?
mikeday
Here is a one example to grab the "author" metadata field:
<meta name="author" content="John Smith"/>

meta[name="author"] { string-set: author-name attr(content) }
jim_albright
Thanks Michael for responding. I was too busy yesterday.

Jim Albright
Wycliffe Bible Translators

matt_d_rat
Thank you for your help guys. Absolutely love prince.