Confluence Docs 3.3 : Editing the PDF Stylesheet
This page last changed on May 18, 2010 by alui.
Confluence's PDF Export feature addresses the most highly voted improvement request for Confluence — more control over PDF exporting. Users can customise their PDF exports using a PDF Stylesheet, which is specific to each space in a Confluence installation. The following aspects of PDF exports can be customised:
On this page: Customising the style of PDF exportsPDF export customisations are specific to each space.
There are two areas that control the customisation of space-level PDF exports in Confluence. These are the 'PDF Layout' and 'PDF Stylesheet'. PDF LayoutTo access the PDF Layout for customisation,
PDF StylesheetTo access the PDF Stylesheet for customisation,
Basic CustomisationsPage CustomisationsModifications to page and margin sizes are made in the @page CSS rule. To make changes to this rule, you would implement the following type of code in the 'PDF Export Stylesheet' of the PDF Stylesheet. @page { /*Page specific styles (that is, customisations of properties) go here*/ } Customising the Page SizeThe default page size is based on the locale of your Confluence server. Hence, if this server was located in the US, the default paper size of your PDF export would be US Letter size (8.5 inches wide by 11 inches long). If the server was located in Australia, the default paper size would be A4 (210 mm wide by 297 mm high). To modify the page size to A4, add a size property to the top of the rule like this: @page { /*The A4 paper size is 210 mm wide by 297 mm high*/ size: 210mm 297mm; } More information about paper sizes can be found on Wikipedia. Customising the Page MarginsTo add a margin of 15 mm to a paper size of A4, your CSS @page rule would look like this: @page { size: 210mm 297mm; margin: 15mm; } Customising the Table of ContentsBy default, a table of contents will be generated after the title page, or at the beginning of the document if the 'PDF Space Export Title Page' (of the PDF Layout) is not defined. The look and layout of the table of contents is completely customisable by defining the appropriate CSS rules in the 'PDF Export Stylesheet'.
Disabling the Table of ContentsTo prevent the table of contents being generated in your exported PDF document, add the div.toc rule to the 'PDF Export Stylesheet' section of the PDF Stylesheet and set its display property to none: div.toc { display: none; } Change the Leader CharacterThe leader character is used to visually link the name of a heading in the table of contents list with its page number, which is usually aligned to the page's right-hand margin. By default, the leader character is the '.' (dot) character. However, it can be changed by customising the leader character CSS rule span.toclead:before and adding this to the 'PDF Export Stylesheet' section of the PDF Stylesheet. To change this to a solid line, modify this CSS rule accordingly: span.toclead:before { content: leader(solid); } To change this it to spaces (that is, blank space), modify this CSS rule to: span.toclead:before { content: leader(space); }
Adding a Title Page to PDF-Exported Space or SubsectionYou can create a title or cover page for an PDF-exported space or subsection using XHTML. Use the 'PDF Space Export Title Page' section of the PDF Layout to do this. The following XHTML code example uses an inline CSS rule to generate a title page. <div class="fsTitlePage" style="margin-left:auto;margin-top:75mm;margin-right:auto;"> <img src="/download/attachments/12345/titlepage.png"/> </div> In the example above, an image called 'titlepage.png' will be centred in the middle of the page. This image is attached to a Confluence page and is referenced via its relative URL (that is, without the Confluence site's base URL component). You can obtain the URL of an image attached to a Confluence page by viewing the list of attachments on that page and moving your mouse over the attachment's name. The URL of the image should appear in your browser's status bar or you can copy the link. Once you have this link, paste it into the appropriate src="" attribute within your PDF stylesheet and remove the first part of the URL up to the /download/... part. Adding Headers and FootersHeaders and footers can be added to a PDF-exported space or subsection also using XHTML. Use the 'PDF Space Export Header' and 'PDF Space Export Footer' sections of the PDF Layout to create a custom header and footer, respectively. For simple headers and footers, plain text is sufficient. The following example added to a header or footer will create a simple copyright notice. Copyright © 2009, Atlassian Pty Ltd. Adding page numbering to a header or footerTo add page numbering to your documentation, you need to combine some customised XHTML in the header or footer along with some customised CSS in the 'PDF Export Stylesheet'. First, create a header or footer with an empty span element and give it a unique id, for example pageNum (although this could be anything). This is the page number 'place holder' in your exported PDF document. <span id="pageNum"/>
Next, create the following CSS selector rule for this empty span and add it to the 'PDF Export Stylesheet': #pageNum:before { content: counter(page); } This will add a page number to your header or footer.
General FormattingYou can also use the stylesheet to customise the output of just about anything else that will influence the look and feel of the final document. This includes fonts, tables, line spacing, macros, etc. The export engine works directly from the HTML output produced by Confluence. Therefore, the first step in customising something would be to find a selector for the HTML element produced by Confluence or the Confluence macro. Next you would add a CSS rule to the 'PDF Export Stylesheet' and your customisation would appear in the PDF export. RELATED TOPICSAdvanced PDF Stylesheet Customisations |
![]() |
Document generated by Confluence on Jul 09, 2010 01:08 |