【问题标题】:How to export a Confluence "Space" to PDF using remote API如何使用远程 API 将 Confluence“空间”导出为 PDF
【发布时间】:2014-01-31 18:33:56
【问题描述】:

如何将 Confluence 的“空间”导出为 pdf? Confluence 5.0 使用 XML-RPC API 似乎仍然支持它。不过,我找不到如何调用的示例。

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

该链接说呼叫应以pdfexport 为前缀,但没有列出任何呼叫或给出示例。

【问题讨论】:

  • 你有命令行界面 Confluence 插件的许可证吗?那么将有一种非常简单的方法将汇合空间导出为 pdf
  • 不,我正在使用 confluence 的按需版本,它对插件的支持有限。

标签: ruby xml-rpc confluence


【解决方案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()}
        """)
    }

}

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 你试过了吗?我不相信 xmlrpc 端点不再受支持。我已经尝试了各种 ruby​​ xmlrpc 客户端并返回神秘错误
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-01
      • 1970-01-01
      • 2021-12-27
      相关资源
      最近更新 更多