Forum How do I...?

Hide element in bookmarks, like body?

jablko
My input document contains headings like,

<h1>Lorem ipsum dolor sit amet<span class="foo">Foo</span></h1>

e.g. http://www.sfu.ca/~jdbates/tmp/css/201006240/

I hide <span class="foo"/> with,

.foo
{
  display: none;
}


This works great in the body of Prince' output, but the bookmarks don't look correct - they include the <span class="foo"/> element, e.g. http://www.sfu.ca/~jdbates/tmp/css/201006240/index.pdf

How can I hide <span class="foo"/> in bookmarks, as well as the body?
mikeday
That's a good question. You can use the bookmark-label property to specify the content of the bookmark label. However, display: none elements are still included by default, as it is a common request to create bookmarks from hidden elements. As a result I'm not sure if they can be removed automatically at this time.
mwiik
Perhaps this has changed with later versions of PrinceXML.

I, too am working with getting bookmarks correct. In my xhtml application I have a series of questions, each covering one to several pdf pages of tabular data. I placed my inline text for a bookmark inside a div.caption element, and set this to prince-bookmark-level: 1

This div.caption is intended to have an initial and 'continued' form, and I accomplished this by making the 'continued' form the default in my xhtml, and used css to target the first such instance to remove the 'continued' elements. Nonetheless, the bookmarks showed the initial instance to contain some text set to display: none in the css, but the first bookmark for a question still contained my 'Continued' text.

Ok, trying a different approach, I turned off bookmarks for my div.caption and instead made a new div.for-bookmark which appears only once per question. Not wanting to show this in the pdf, this is set to display: none in the css, but *doesn't* appear in the resulting pdf's bookmarks at all.

It seems therefore I cannot display per-question bookmarks w/o having them actually appear in the pdf (since display: none seems to preclude them), and also cannot have both the initial and continued form of the bookmark (which works fine in the pdf narrative).

To be more specific, here is a typical div.caption which appears inside a th in the thead section of the data tables I wish to generate as pdfs:

<div class="caption">
<span class="questionNum">3</span> <span class="continued">Continued:</span> Are we making progress over time?
</div>

I have this set for prince bookmarks:
div.caption {
prince-bookmark-level: 1;
}

Here I am relying on thead and tfoot to repeat on each page, but specifically targetting the first instance with css to make style changes and remove the 'Continued' text:

/*
Basically, for question03 we turn all captions
to 'continued' form, then turn off continued
for the very first one.
*/

div.question03 table.trendgraph:first-child span.continued {
display: none;
}


The above works in the narrative of the pdf, turning the first such div.caption into the initial form, but in the pdf bookmarks, they are all in the 'continued' form.

I then figured that I would just have one bookmark for the initial page of a question, but not intended to be in the pdf narrative. So, right before my table, I added:

<div class="for-bookmark">
(3) Are we making progress over time?
</div>

and set this to be a bookmark but not displayed:

div.for-bookmark {
prince-bookmark-level: 1;
display: none;
}

and then removed the css for using div.caption as a bookmark.

But as stated, this did not work, no bookmarks were created. If I took out the display: none declaration, then the bookmarks were created, but that's not what I want in the narrative.

Thinking this might be a div/span difference, I tried making some span.for-bookmark text, also set to display: none and prince-bookmark-level: 1, but neither the div nor span versions appear as bookmarks.

Any workarounds for my conundrum? Thanks. I am using Prince 7.1 on OS X 10.6.4
mikeday
Right, two problems. Firstly, bookmarks display text even from sub-elements with "display: none". Secondly, if the element itself has "display: none" then it will not appear in the PDF document and will not generate a bookmark. Awkward!

One workaround is to use "visibility: hidden" instead:
div.for-bookmark {
    prince-bookmark-level: 1;
    visibility: hidden
}

This will generate a bookmark. However, although the element is invisible, it will still take up space on the page, which is probably not what you want. You could absolutely position it to avoid this:
div.for-bookmark {
    prince-bookmark-level: 1;
    visibility: hidden;
    position: absolute
}

Not an obvious solution, but it should work. Another option is to make the element empty and put the bookmark text inside an attribute, like this:
<div class="for-bookmark" title="This is the bookmark text!"></div>

div.for-bookmark {
    prince-bookmark-level: 1;
    prince-bookmark-label: attr(title)
}

There are probably other ways of doing it as well. We may need to reconsider the way that bookmarks interact with "display: none" to reduce the need for these kind of workarounds.
mwiik
Thanks Mike! I used the visibility: hidden and position: absolute approach to create my per-question bookmarks, and they are working fine.

Thanks again.