Advanced PDF export customizations in Confluence
Advanced PDF export customizations in Confluence

Advanced PDF export customizations in Confluence

Confluence provides a basic PDF export that you can customize and style to suit your needs. When someone exports a space to PDF, Confluence will apply any layout and styling directions it finds in the current space or set globally for the whole site. 

  • The PDF Layout allows you to add a title page to your PDF, and add a header and footer to all pages. 
  • The PDF Stylesheet allows you to change the look of the PDF. You can change just about anything, including the paper size, fonts and colours, spacing, and control behaviours like page breaks. 

Both the PDF Layout and PDF Stylesheet can be customized on a space by space basis, or globally for the whole site. Space customizations will always completely override any global customizations. This means you can't mix and match and set some items globally and others at the space level. 

sources:

Customizing the header and footer of a PDF can be a bit tricky so I decided to share my knowledge about that. ?? 

There is also a great add-on to help customizing PDF export, the famous one is Scroll PDF Exporter for Confluence. But before considering buying an add-on, the solution I will present here can be a good way to adapt your PDF style to your own needs.

Adding dynamic data to the PDF header or footer

In order to collect the data that you need in your PDF header or footer, you will have to build your own custom User Macro in Confluence and add it to the pages you want to export with your custom layout and style.

In my example here we will focus on 3 datas especially:

  1. the user that did the last modification on the page,
  2. the date and time of the last modification of the page,
  3. the labels used on the page.

Here is the code of my User Macro called PDF Header:

## Macro title: PDF Header
## Macro has a body: N
## Body processing: Selected body processing option
## Output: Selected output option
##
## Developed by: Damien Lauberton
## Date created: 29/04/2020
## Installed by: Damien Lauberton
## @noparams


#set($currentPage = $pageManager.getPage($content.getId()))
#set($pageLabels = $currentPage.getLabels())
#set($nbLabels = $currentPage.getLabelCount()) 


<div id="runningheader" class="runningheader">
#usernameLink($content.getLastModifierName()) - $action.dateFormatter.formatGivenString("dd/MM/YYYY, HH:mm",$content.getLastModificationDate()) - 
#if($nbLabels>0)
  #foreach( $labelObject in $pageLabels )
  <span class="aui-label">$labelObject.name</span>
 #end
#else
 <span>no labels</span>
#end
</div>

Preview of the macro on a page:

preview of the macro PDF Header

Styling the PDF layout on export

You will have to edit the CSS rules in the PDF Stylesheet page in a space (Space tools > Look and Feel > PDF Stylesheet).

@page {
  /* header */
  @top-center {
    content: element(runningheader);
    font-family: ConfluenceInstalledFont, Helvetica, Arial, sans-serif;
    font-size: 8pt;
  }
  /* footer */
  @bottom-center {
    content: "Page " counter(page) " on " counter(pages);
    font-family: ConfluenceInstalledFont, Helvetica, Arial, sans-serif;
    font-size: 8pt;
  }
}


.runningheader {
  position: running(runningheader);
  text-align: center;
}


.aui-label {
  background: #f4f5f7;
  border: 1px solid #dfe1e6;
  border-radius: 3.01px;
  display: inline-block;
  font-size: 8pt;
  font-weight: 400;
  line-height: 1;
  padding: 1px 5px;
  margin: 0 5px 0 0;
  text-align: left;
  text-decoration: none;
}

Basically what this CSS will do is to take the macro PDF Header from the page content and add it in the PDF header during export. The footer here will display the current page number and the total number of pages.

Finally the full PDF export of a page...

Aucun texte alternatif pour cette image

Enjoy and start customizing yourself your PDF layout and style in Confluence ! ??

Daniel Alomar Claramonte

Centre de serveis compartits del àrea de Sistemes d'Informació de CatSalut

1 年

Any solution for a Confluence Cloud? The cloud flavour does not support custom user macros..

回复

要查看或添加评论,请登录

Damien Lauberton的更多文章

社区洞察

其他会员也浏览了