How to start PDF export from Java API?

Hi,

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.

Thanks!

1 answer

Hi,

 

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.

 

Cheers,
Jens

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

Thanks

Tuelle

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,792 views 26 10
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