Forum How do I...?

How to obtain book/document title automatically, for dynamic header?

SamD
I tried this in my CSS:
h1 {
string-set: book-title content();
}
in conjunction with
@page {
@top-left {content: string(book-title); }
}
Apparently book-title string was always empty.
I tried h0 but to no avail.
The only element that worked was:
body {
string-set: book-title "The Prince and the Pauper";
}
but of course this is not a way out of situation.
mikeday
Does it show up on page two?

What if you try using the "first" keyword when you access the string:
@top-left {content: string(book-title, first); }

This will get the first value of book-title that has been set on the page.

SamD
No, this doesn't change anything.
I forgot to note that in my example when the tag h1 is used for the string creation chapter title is always loaded into the string book-title. I tried other tags (h0, h2, etc and found that only h1 works and it always provides chapter title only.
It is my intention to fill headers with author name, book title (I'm using Prince to convert some books in ePub format to pdf), chapter title, and page number (on odd and even pages). So far I succeeded only with chapters and pages...can't figure out how to add author as well.
BTW, I noticed that many DIY epub books contain pdf_output.css for Prince and each css has book title hardcoded into the body element.
SamD
Looks as book (and chapter) title problem is document dependable.
Found two books where the following worked for book and chapter titles:
First book:
title {
string-set: book-title content();
}
h1 {
string-set: chapter-title content();
}
Second book:
title {
string-set: book-title content();
}
h2 {
string-set: chapter-title content();
}

Go figure...
SamD
I guess I figured out what happens.
ePub is comprised of multiple html files, each book use different tags to provide chapter titles.
Some ePubs supply chapter titles under h1, some under h2.
Rare ePubs supply book title at the head element in each html file (then CSS tag title works for book title).
Prince processes each html file independently and cannot obtain data that is not supplied.
Looks as my goal is unattainable in this specific situation.
Sorry I took your time.
mikeday
Tricky! I suppose you could use JavaScript to check the document and see what kind of headings it has?
SamD
Sure. Just need to retrieve book title and author not from html files but from file content.opf always present inside zipped ePub. After this code will update external css file accordingly and feed it to Prince.
SamD
BTW, how can I allow more space for header text?
My code is:
@page {
@top-left {
font-size: 50%;
font-style: italic;
border-bottom: solid thin black;
margin-top: 0mm;
margin-bottom: -0.5mm;
padding-top: 0mm;
padding-bottom: 0mm;
content:string(chaptertitle);
}
...
}
Looks like the only way to do this is to set negative margin-bottom. It gives the header text more space but still not enough. Negative margin also brings border line down and places it dangerously close to page text; don't see how to add space between border line and page text, at least page margin-top does nothing.
mikeday
How about adding @page padding-top?
SamD
padding-top with any value kills entire header.