Example scripts
To homepage
Confluence

Export Page as PDF Job
App in script

ScriptRunner For Confluence
by Adaptavist
Compatibility

Confluence (7.15 - 8.6)

ScriptRunner For Confluence (7.10.0)
Language |
groovy
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal
import com.atlassian.confluence.extra.flyingpdf.PdfExporterService
import com.atlassian.confluence.extra.flyingpdf.analytic.PageExportMetrics
import com.atlassian.confluence.pages.Page
import com.onresolve.scriptrunner.parameters.annotation.ShortTextInput
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import org.apache.commons.io.FileUtils
@ShortTextInput(label = 'Local directory', description = 'The directory to store the exported PDFs')
String localDirectory
assert localDirectory
@PluginModule
@WithPlugin("com.atlassian.confluence.extra.flyingpdf")
PdfExporterService pdfExporterService
def user = AuthenticatedUserThreadLocal.get()
hits.each {
def pdf = pdfExporterService.createPdfForPage(user, (Page) it, null, new PageExportMetrics())
def dest = new File(localDirectory + File.separator + "${it.title}(${new Date().format("yyyyMMdd")}).pdf")
FileUtils.copyFile(pdf, dest)
}
"CQL search returned ${hits.size()} item(s). Each item was exported to the local directory '${localDirectory}'"
Having an issue with this script?
Report it here