Custom user macro not working on pdf space export

I have the following maco that creates a table of information that includes, who edited the page, modification date, page name and version.

This macro works fine when applied to the page, it also works if you export just the page containing the macro.

However when you export the space, the table only shows the page on which the macro is applied.

Here is the code

## Macro title: Page Data
## Macro has a body: N
## Body processing: n/a
## Output: HTML
##
## Developed by: Brian Mitchell
## Date created: 06/27/2013
## @noparams
 
#set ($PageTitle = $content.displayTitle)
#set ($PageVersion = $content.version)
#set ($PageDate = $action.dateFormatter.formatGivenString("dd MMM yyyy", $content.lastModificationDate))
#set ($PageAuthor = $content.lastModifierName)
#set ($pageListArray = [])
#set ($currentPage = $action.page)
 
#macro ( process $rp )
  #set ($pagelist = $rp.getSortedChildren() )  ## returns List<Page>
  #foreach( $child in $pagelist )
    #set($p = $pageListArray.add( $child ) )
    #if( $child.hasChildren() )
      #process ( $child )
    #end
  #end
#end
 
#process ( $currentPage)

<h1> Confluence Page Versions </h1>
<table class="confluenceTable">
 <tbody>
 <tr>
  <th class="confluenceTh">Page Title</th>
  <th class="confluenceTh">Page Version</th>
  <th class="confluenceTh">Date</th>
  <th class="confluenceTh">Changed By</th>
 </tr>
 
<tr>
<td>$PageTitle</td>
<td><a href=http://confluence.mango.local/pages/viewpreviousversions.action?pageId=$content.getIdAsString()>$PageVersion</a></td>
<td>$PageDate</td>
<td>$PageAuthor</td>
</tr>


 #foreach( $child in $pageListArray)   ## child is of type Page
   <tr>
     <td class="confluenceTd">$child.getTitle()</td>
     <td class="confluenceTd"><a href=http://confluence.mango.local/pages/viewpreviousversions.action?pageId=$child.getIdAsString()>$child.getVersion()</a> </td>
     <td class="confluenceTd">$action.dateFormatter.formatGivenString("dd MMM yyyy", $child.getLastModificationDate())</td>
     <td class="confluenceTd">$child.getLastModifierName()</td>
   </tr>
 #end
 
</tbody>
</table>

Does anyone know why this is the case?

4 answers

If your macro is dynamically creating content then most likely the pdf isn't rendering the script when it's creating it's printout. I suggest you use the File > Print > Save to PDF. This will convert the page as you see it once everything is loaded, instead of recreating the pdf from scratch like the export link does.

Well exporting just the page is not a issue, the problem occurs when exporting a entire space.

Its because something is not being run when exporting the space, however i have had a thought.

If i can add something in to the macro that allows the user to decide what page it uses as its head page and the macro scans everything below that and populates the table that might work.

This is effectivly hard coding the first page in rather than using

#set ($currentPage = $action.page)

I found this out by setting this to entire space and the export worked so if i could allow the user to set the page on which is scans from it might work.

Brian,

I tried out your macro and it works fine for me with the standard PDF Export option. It also works fine with the Scroll PDF Export plugin.

What version of Confluence are you using? We're on 4.2.1.

@ Sean - the Velocity code in Brian's macro is all executed server-side by Confluence before the PDF Export process does its stuff. There's no client-side code (i.e. javascript) so what is seen in the browser ought to be included in the PDF too.

Regards,

Charles

The File > Print solution will not work as the macro works fine was exporting a single page.

The problem occurs when you export a entire space, the page on which the macro sits is not rendered.

Exporting that very same page indivdually is not a issue, but we have a lot of people exporting entire spaces to create documents so we need this macro to be reliable when exporting.

Is there solution for that?

I've user macro to customize CSS during export to PDF. And this macro applied during export single page to PDF but when I try to export space or several pages from space it doesn't work.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

800 views 23 12
Join discussion

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