Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Copy the page title to the header of a PDF export

Stefan Marko April 3, 2019

Hello everyone,

I need to export a couple of pages in Confluence to PDF to serve as project documentation.

For this I wanted to add the title of the page to the header of the export.

I found (and tried) this CSS code in the PDF stylesheet in order to achieve this:

@top-left { 
content: element(runningheader);
}

...

.pagetitle h1 {
position: running(runningheader);
font-size: 6pt;
}

However, I am facing two problems:

  1. This approach does of course not copy the title to the header but instead moves it, meaning that there is no big document title on the first page any more. (I could probably overcome this by simply adding the page title to the template again via the scriptrunner page info macro.)
  2. This is the main problem I have: After inserting this code to the stylesheet my PDF does not contain any h1 headings any more as they are all moved to the top-left. So only the first h1 per page shows up in the header and not a single h1 is present in the text itself any more.

Does anyone have a solution for this?

 

Thanks in advance!

1 answer

1 accepted

4 votes
Answer accepted
Stefan Marko April 8, 2019

In case someone else needs this:

I found two possible solutions now:

1) use h1:first-child instead of .pagetitle h1:

h1:first-child {
position: running(runningheader);
}

 This only moves the title to the header, the other h1 headings stay where they should be

2) Create a user macro that displays the page title and use CSS to move that content to the header. For this to work every page you want to export with  the title in the header needs to have the specified macro in it of course.

User macro:

## @noparams
<div class="pageTitleHeader" style="display:none">
$content.title
</div>

CSS:

.pageTitleHeader{
display: block !important;
position: running(runningheader);
}

The advantage of this solution is that you will still have the title printed in a large font on the first page and have it in the header at the same time.

Probably not the best way to do it but at least it seems to work.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events