As a new Admin for JIRA/Confluence, I am trying to figure out the path of least resistance to create a scriptrunner job to do a daily export of a Confluence page to a pdf to be saved in a shared file. Any and all help is greatly appreciated.
Hi Justin,
You can call Confluence's export to PDF URL to get the PDF file. The request URL should be something like:
<Confluence_URL>/spaces/flyingpdf/pdfpageexport.action?pageId=<Page_Id>
Then, you can probably use the Apache Common IO FileUtils's copyURLToFile to download the file and save it to your destination folder - See example
Ultimately, your script in Job could be something like:
import org.apache.commons.io.FileUtils// Replace <Confluence_URL>// Replace <Page_Id>def requestUrl = "<Confluence_URL>/spaces/flyingpdf/pdfpageexport.action?pageId=<Page_Id>"// Update destinationPath with your shared directory and file namedef destinationPath = "PATH/FILENAME.pdf"try { URL url = new URL(requestUrl) File destinationFile = new File(destinationPath) FileUtils.copyURLToFile(url, destinationFile)} catch (MalformedURLException e) { // Handle} catch (IOException e) { // Handle}
I hope this helps!
Cheers,Helmy
Helmy,
Thank you for the response! I am building and trying it today. I hope that all goes smooth if not I'll be back .
Thank you,
Justin
This post on StackOverflow should help!
Ah you edited your reponse.
Hope everything goes well
You don't have to replace the string 'user.dir'. It is literally it:
System.getProperty("user.dir")
sorry about that.
Can you check if you actually have permission to create a file in that directory?
You can run this script in the Script Console to test:
def testFile = new File("C:/Users/jmele/Desktop/Export_Test/test.txt")log.warn testFile.getAbsolutePath()
My original script above did not handle any authentication. Please use the following script instead: https://www.mysamplecode.com/2019/04/java-download-image-from-url-authentication.html
Hi all, this script is now available in our script library for ScriptRunner for Confluence Server/DC (tested by our engineers).
Feel free to copy or customise it as you wish.
https://library.adaptavist.com/entity/export-page-as-pdf-job
It looks like you're new here. Sign in or register to get started.