How to start PDF export from Java API?

Tuelle July 31, 2017

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

0 votes
Jens Rutschmann _K15t_
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.
August 1, 2017

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

Tuelle August 5, 2017

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

Thanks

Tuelle

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events