Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to create PDFs using Java?

swisscompedia
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 8, 2022

Hi there,

I am trying to create PDF exports of pages using the Java API of Confluence. I am using @ComponentImport PdfExporterService

This groovy code example works:

import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.confluence.extra.flyingpdf.analytic.PageExportMetrics;
import com.atlassian.confluence.extra.flyingpdf.PdfExporterService
import com.atlassian.user.User

Page page = ComponentLocator.getComponent(PageManager.class).getAbstractPage(114915234)
User user = AuthenticatedUserThreadLocal.getUser()
return pdfExporterService.createPdfForPage(user, page, "", new PageExportMetrics())

(I am using an own groovy console which allows me to inject a binding to the PdfExporterService)

Doing similar in Java fails with

java.lang.ClassNotFoundException: com.atlassian.confluence.extra.flyingpdf.analytic.PageExportMetrics

I played around with the class loaders a little, but nothing seems to help. How can I make the class loader find that class?

 

1 answer

0 votes
David Herrera July 12, 2022

Hey @swisscompedia how are you? Did you finally were able to solve this?

 

We are in the same situation. We tried to use the PdfExporterService and we got the same error because of the PageExportMetrics class not found. 

 

Seems like they only exported first level classes of the package com.atlassian.confluence.extra.flyingpdf

But this is really weird as you cannot use this service without analytics classes.

 

The only service we could use is the XmlToPdfConverter. But we still got no successful results because some resources cannot be resolved (the contextPath parameter is best candidate to be wrong).

 

Did you opened a ticket to Atlassian for this? Maybe we should do it.

David Herrera July 27, 2022

Updates: They have created a bug ticket, so there is hope of incoming versions with a fix. Feel free to vote!! :pray:

https://jira.atlassian.com/browse/CONFSERVER-79556

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events