Why are page-breaks not generating bookmarks in PDF on export - as expected.

I've successfully used both user macros and CSS to force page-breaks at various points of the confluence page - when exported to PDF.

I'm not seeing any bookmarks generated, however, following each 'page-break' ?

Why is this so difficult...

Please see my image attachments..

Thanks

6 answers

This widget could not be displayed.

OK... This seems to be - the only way to do it...

1) Confluence does not directly support - inserting markup - into the page <head>

This is most unfortunate...

2) However, it is possible to insert <script> which in theory could lookup the head element and insert the bookmark tags when the page is loaded.

Printing the PDF then - should have the bookmarks automatically generated...

This should work...

I got the idea from here:

RE: [CONF-user] Custom macro & head/page top/bottom problem

Subject: RE: [CONF-user] Custom macro & head/page top/bottom problem (find more)
From: Dan Hardiker <hidden> (find more)
Date: Mar 04, 2005 05:50

If you must load a script tag into head, you can use the following:

<script>
var script = document.createElement("script");
script.src = "path/to/file.js";
document.childNodes[0].childNodes[0].appendChild( script );
</script>

I have found that to be reliable during testing in various browsers,
this assumes that the first nodes in the DOM are <html> and <head> ... a
more resilient option might utilise a function like:

<script>
document.getElementByNodeName = function (name, recurse, parent) {
if (typeof(recurse) == "undefined" || recurse == null) recurse = -1;
if (typeof(parent) == "undefined" || parent == null) parent =
document;
for (var i=0; i<parent.childNodes.length; i++) {
if (parent.childNodes[i].nodeName == name.toUpperCase()) return
parent.childNodes[i];
if (recurse != 0) {
document.getElementByNodeName(name, (recurse-1),
parent.childNodes[i]);
}
}
return null;
}
var script = document.createElement("script");
script.src = "path/to/file.js";
script.loading = false;
var head = document.getElementByNodeName("HEAD", 3);
if (head != null) {
script.loading = true;
head.appendChild( script );
}
</script>

Please note - I've not tested that code so it may well have a few bugs
...

Dan Hardiker

This widget could not be displayed.

Home these images are visible...

This widget could not be displayed.

Hi fmisa,

I am afraid I don't have an answer but yet another question:

I would also like to be able to generate bookmarks in the left panel of my PDf file and I don't have a clue how this is done. Do I understand you correctly that you assume that page breaks on the confluence page should create bookmarks on the PDF?

If so, is this documented somewhere or where did you get that information from?

Steffen

Hi Steffen...

Yes - this is my understanding - though given it's not working - maybe I'm wrong ;)

I base my thoughts on these links:

https://answers.atlassian.com/questions/30169/confluence-export-to-pdf-generate-bookmark-index

https://answers.atlassian.com/questions/4625/pdf-export-creates-bookmarks-at-end-of-prior-section

See my previous question:

https://answers.atlassian.com/questions/68373/pdf-stylesheet-customization-generating-bookmarks-page-breaks-for-h1-and-h2-headings

Check back next week - if I figure this out - I will post my answer here...

Cheers

F

This widget could not be displayed.

Hi,

I had similiar questions and what I learned is that "flying saucer" is the library used by confluence. Hence what happens or does not happen when you export to PDF lies within flying saucer.

On their page there is some explanation about how to create PDF bookmarks:
http://code.google.com/p/flying-saucer/wiki/HowTo_PDF_bookmarks_from_xhtml_markup

If there is a simpler method with page breaks I would be happy to know it but I rather doubt it.

But let us know if you found something.

Cheers

This widget could not be displayed.

Hi,

I had similiar questions and what I learned is that "flying saucer" is the library used by confluence. Hence what happens or does not happen when you export to PDF lies within flying saucer.

On their page there is some explanation about how to create PDF bookmarks:
http://code.google.com/p/flying-saucer/wiki/HowTo_PDF_bookmarks_from_xhtml_markup

If there is a simpler method with page breaks I would be happy to know it but I rather doubt it.

But let us know if you found something.

Cheers

Ahhh... I'm silly...

I knew flying saucer was the backing library - doing the work - and have come across the project before. That's where I should have been directing my energies !

Thanks for the kick...

I'll look into it - and get back to you...

Cheers

F

Found something else:

If CSS bookmarks did work it should probably do so as described here. I quickly tried, couldn't get it to work and suppose it doesn't because it is CSS3 and not 2.1.

Hi Steffen

I'm back on this issue... and would like to solve today.

I've researched the google-code FlyingSaucer docs - and have a solution.

See here:

http://code.google.com/p/flying-saucer/wiki/HowTo_PDF_bookmarks_from_xhtml_markup

It will only work - if you're programatically generating your confluence pages... AND inserting the custom bookmark "markup" into the <head> of the confluence page....

I won't be writing any user macros for this...

The question now remains - is there a way to insert content into the <head></head> sections of pages that confluence generates ?

Does confluence provide some custom HTMLMacro ? or UserMacro ? that allows insertion of custom markup - into the html <head> of a page ?

I suspect the technique - defined at the above link - will work..... but I'm having trouble finding mechanisms that would allow me to control where in a page - my markup is placed ?

<head> <body> <script> etc. ?

Hope you may have some ideas ?

Hi Steffen....

I mis-spoke.... this will work - without dynamic/programatically generating pages as well...

Nothing is stopping you from taking the code - from referenced website:

     <head>  
<bookmarks>
<bookmarkname="A bookmark"href="#bm"/>
<bookmarkname="A bookmark 2"href="#bm2">
<bookmarkname="A bookmark 3"href="#bm3"/>
</bookmark>
<bookmarkname="A bookmark invalid"href="#bm99"/>
</bookmarks>
</head>

And just statically.... a) Click page EDIT b) insert markup.... when page is printed - bookmarks will be generated and work as long as referenced href #bm, #bm2 etc. anchors exist...

     <body>  
<aname="bm1">Jumpmark 1</a>
<aname="bm2">Jumpmark 2</a>
<aname="bm3">Jumpmark 3</a>
</body>

Do you know - is it possible in confluence - with some macro perhaps - to add content to the <head> of a document - not unlike the SytleMacros - that allow you to inject custom CSS styles into a page.... Could we do same with the above <bookmark> code ?

This widget could not be displayed.

Was there any progress on this issue in the last 5 years , anybody successfully implemented a solution for this ? 

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Tuesday in Confluence

Add-on evaluation with confluence templates

Atlassian market place contains number of Apps/Addons which improves the capability of out of the box Atlassian products. It is good to follow a plugin evaluation process before install add-ons. So t...

94 views 12 6
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you