How to start PDF export from Java API?


I want to export a page to PDF through the Java API. I cannot use the REST api of e.g Scroll PDF because, the event listener that should trigger the export also modifies a custom active object earlier. This change to the custom AO is however not reflected during the REST export. If I understand the docs correctly this is due the way Confluence handles sessions and transactions. A REST call is in a separate session and therefore cannot see the changes. If I would export through the Java API, it should be in the same session.


1 answer



Scroll PDF Exporter does not expose any Java API to other plugins, so there is no way you could invoke it.

Furthermore exports are usually performed in a separate worker thread, which would not run in the scope of your transaction anyway.

Your best option would probably be to defer the export action until the transaction your event handler is running in has been commited.

AFAIK there still are no 'run-after-commit' event handlers so you would need to implement this on your own.

This is not trivial.

You could for example in your event handler submit sort of an export task along with the page revision from the event into an ExecutorService's queue, then when the task executes periodically (in individual transactions) poll the page manager for the page and check if it already returns your expected revision. Then launch the export by performing a REST API call. You'd also need to preserve the user context somehow so the REST API call is performed for the correct user.



Thanks for your reply. It basically confirms what also have in mind.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

281 views 2 11
Read article

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