How to export a Confluence "Space" to PDF using remote API
Asked Answered
C

3

6

How can I export a Confluence 'space' as a pdf? It looks like it might still be supported in Confluence 5.0 using the XML-RPC API. I cannot find an example of what to call, though.

https://developer.atlassian.com/display/CONFDEV/Remote+API+Specification+for+PDF+Export#RemoteAPISpecificationforPDFExport-XML-RPCInformation

That link says calls should be prefixed with pdfexport, but then doesn't list any of the calls or give an example.

Conterminous answered 31/1, 2014 at 18:33 Comment(2)
do you have a license for the Command Line Interface Confluence plugin? then there would be a very easy way to export a confluence space as a pdfSupposal
No I am using the on demand version of confluence which has limited support for plugins.Conterminous
G
1

This works using Bob Swift's SOAP library ('org.swift.common:confluence-soap:5.4.1'). I'm using this in a gradle plugin, so you'll need to change a few things

void exportSpaceAsPdf(spaceKey, File outputFile) {
    // Setup Pdf Export Service
    PdfExportRpcServiceLocator serviceLocator = new PdfExportRpcServiceLocator()
    serviceLocator.setpdfexportEndpointAddress("${url}/rpc/soap-axis/pdfexport")
    serviceLocator.setMaintainSession(true)
    def pdfService = serviceLocator.getpdfexport()

    // Login
    def token = pdfService.login(user, password)

    // Perform Export
    def pdfUrl = pdfService.exportSpace(token, spaceKey)

    // Download Pdf
    HttpClient client  = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(pdfUrl)
    httpget.addHeader(
            BasicScheme.authenticate(
                    new UsernamePasswordCredentials(user,password),"UTF-8", false))
    HttpResponse response = client.execute(httpget)
    HttpEntity entity = response.getEntity()

    if (entity != null) {
        InputStream inputStream = entity.getContent()
        FileOutputStream fos = new FileOutputStream(outputFile)
        int inByte
        while ((inByte = inputStream.read()) != -1)
            fos.write(inByte)
        inputStream.close()
        fos.close()
    } else {
        throw new GradleException("""Cannot Export Space to PDF:
        Space:  ${spaceKey}
        Dest:   ${outputFile.absolutePath}
        URL:    ${pdfUrl}
        Status: ${response.getStatusLine()}
        """)
    }

}
Gaskin answered 19/1, 2016 at 22:23 Comment(0)
B
0

I know this is a PHP example, not Ruby, but you can check out the XML-RPC example in VoycerAG's PHP project on Github at https://github.com/VoycerAG/confluence-xmlrpc-pdf-export/blob/master/src/Voycer/Confluence/Command/PdfExportCommand.php ... hope it helps.

Basically you just need to make a call to the login method and user the authentication token returned to make a call to the exportSpace method. That in turn gives you back a URL which an authenticated user can then download the PDF from.

Blackberry answered 7/2, 2014 at 23:47 Comment(1)
Did you try this? I don't believe the xmlrpc endpoint is supported anymore. I have tried various ruby xmlrpc clients and get back cryptic errorsConterminous
C
0

Turns out the soap API is the only currently available api for exporting a space

Using the Savon library in Ruby here:

require 'savon'
# create a client for the service
# http://<confluence-install>/rpc/soap-axis/pdfexport?wsdll
client = Savon.client(wsdl: 'https://example.atlassian.net/wiki/rpc/soap-axis/pdfexport?wsdl', read_timeout: 200)

# call the 'findUser' operation
response = client.call(:login, message: {username: "user", password: "pass"})

token = response.body[:login_response][:login_return]

response = client.call(:export_space, message:{token: token, space_key: "SPACE KEY"})
Conterminous answered 14/2, 2014 at 0:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.