如何使用远程API将Confluence“Space”导出为PDF

时间:2014-01-31 18:33:56

标签: ruby xml-rpc confluence

如何将Confluence“space”导出为pdf?看起来它仍然可以使用XML-RPC API在Confluence 5.0中得到支持。但是,我找不到一个可以调用的例子。

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

该链接表示调用应以pdfexport为前缀,但不会列出任何调用或举例。

3 个答案:

答案 0 :(得分:1)

这可以使用Bob Swift的SOAP库('org.swift.common:confluence-soap:5.4.1')。我在gradle插件中使用它,所以你需要改变一些东西

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()}
        """)
    }

}

答案 1 :(得分:0)

我知道这是一个PHP示例,而不是Ruby,但您可以在https://github.com/VoycerAG/confluence-xmlrpc-pdf-export/blob/master/src/Voycer/Confluence/Command/PdfExportCommand.php的Github上查看VoycerAG的PHP项目中的XML-RPC示例...希望它有所帮助。

基本上,您只需要调用login方法,并且用户返回的身份验证令牌可以调用exportSpace方法。这反过来又会返回一个URL,经过身份验证的用户可以从中下载PDF。

答案 2 :(得分:0)

原来,soap API是目前唯一可用于导出空间的API

在Ruby中使用Savon库:

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"})