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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

How do I render a Confluence page programatically?


When somebody creates a blog post in one of our Confluence pages, we want to e-mail the content to a distribution list. I have successfully created an event listener using ScriptRunner to call a mail-dispatch API and send the raw page content, which renders all right as HTML in an e-mail client. However, any macros in the content are in raw wiki code form and are not rendered. How can I use the Confluence Java API to render the page content to (X)HTML and send that to my e-mail service?

I am well versed with the Jira Java API and ScriptRunner but am newer to the Confluence API, but I have noticed much overlap.

3 answers

1 accepted

0 votes
Answer accepted

Using the DefaultRenderer class from the Java API worked for us. The renderer will convert macros to XML format, although anything that requires Javascript would of course not render outside of Confluence.

import com.atlassian.confluence.content.render.xhtml.DefaultRenderer;

// page is an instance of com.atlassian.confluence.core.ContentEntityObject
DefaultRenderer renderer = ComponentLocator.getComponent(DefaultRenderer);
String content = renderer.render(page)

Maybe I'm doing something wrong, but this code doesn't render macros, it outputs them as the placeholders as you would see them in the editor.

Many macros offload their loading and rendering to JavaScript and the UI so the page itself will load faster. Any content that gets rendered in the UI via AJAX/JavaScript will not appear in the XML output, so it’s not a perfect solution.

If anyone needs rendering html I found this method using XhtmlContent component


xhtmlContent.convertStorageToView(        page,        new DefaultConversionContext(page.toPageContext())    );
0 votes
Dar Kronenblum
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Apr 30, 2018

try to use page.getBodyAsString()

Hi Dar,

I found that getBodyAsString() didn't fit my needs because it returns the raw, unprocessed page XML with all the macros unrendered.

Hi Sammo,

Can you post the Scriptrunner script that you used both to a) render and b) email the blog page? Would be great to see how it's done!

Thank you!

Hi Brian, the above snippet will render the content of a page to XML (see caveat about it being imperfect). I am not exactly certain how to send an e-mail using the Confluence Java API. We are using an program called Sendy to send these newsletters out. It has a simple REST API to use.

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events