【问题标题】:Export a single Confluence page as PDF (Python)将单个 Confluence 页面导出为 PDF (Python)
【发布时间】:2017-09-12 10:44:18
【问题描述】:

我有一个 python 脚本试图将汇合页面导出为 pdf 并且尝试了几种方法均未成功:

1.WGET:

wget --ask-password --user xxxxxxxx -O out.pdf -q http://confluence.xxxx.com/spaces/flyingpdf/pdfpageexport.action?pageId=xxxxxxxx

这不起作用,因为它只是返回一个登录对话框而不是实际的 pdf。

2.REMOTE API:

使用:https://developer.atlassian.com/confdev/deprecated-apis/confluence-xml-rpc-and-soap-apis/remote-confluence-methods#RemoteConfluenceMethods-Pages

有一个 exportSpace 方法有效,但我只想要一个页面,据我所知,getPage 方法不会导出为 pdf。此外,这在技术上已被弃用,因此 Atlassian 建议:

3.REST API

使用:https://docs.atlassian.com/atlassian-confluence/REST/latest-server/

这似乎没有将页面导出为 PDF 的选项

如果您有一个完全不同的方法,我将不胜感激,只要我可以从 python 脚本中获取页面的 PDF。

【问题讨论】:

  • 嘿,我刚刚开发了一种从 Confluence(云库)导出任何 PDF 的方法。你也在使用云吗?

标签: python confluence confluence-rest-api xmlrpclib


【解决方案1】:
#This worked for me
#pip install atlassian-python-api
from atlassian import Confluence

#This creates connection object where you provide your confluence URL  and credentials.
confluence = Confluence(
    url='https://confluence.xxxxx.com/',
    username='xxxxxxx',
    password='yyyyyyy')

# If you know page_id of the page, you can get page id by going to "Page Information" menu tab and the page id will be visible in browser as viewinfo.action?pageId=244444444444. This will return a response having key:value pairs having page details.
page = confluence.get_page_by_id(page_id=<some_id>)
your_fname = "abc.pdf"
#A function to create pdf from byte-stream responce
def save_file(content):
    file_pdf = open(your_fname, 'wb')
    file_pdf.write(content)
    file_pdf.close()
    print("Completed")

#Get your confluence page as byte-stream
response = confluence.get_page_as_pdf(page['id'])
#Call function that will create pdf and save file using byte-stream response you received above.
save_file(content=response)

【讨论】:

    【解决方案2】:

    根据Michael Pillai的回答,我想修改一下,对于Confluence Cloud你必须添加api_version='cloud'关键字:

    confluence = Confluence(
        url='https://confluence.xxxxx.com/',
        username='xxxxxxx',
        password='yyyyyyy',
        api_version='cloud'  # <<< important for the pdf export <<<<
    )
    content = confluence.get_page_as_pdf(page_id)
    

    抄自官方pdf export example

    【讨论】:

      【解决方案3】:

      您可以将您的脚本与 Confluence Bob Swift CLI 插件集成。该插件支持各种类型的导出。

      第 1 步:在前端和后端都安装插件。

      第 2 步:通过此命令验证您的安装 -

      /location-of-plugin-installation-directory/.confluence.sh --action getServerInfo
      

      第 3 步:使用以下命令导出您的空间

      /location-of-plugin-installation-directory/.confluence.sh --action exportSpace  --space "zconfluencecli"  --file "target/output/export/exportSpacepdf.txt"  --exportType "PDF"
      

      Link to bob swift plugin

      【讨论】:

        【解决方案4】:

        最新的文档使用 confluence.export_page(page_id) 对于仍在寻找此信息的任何人。

        【讨论】:

          猜你喜欢
          • 2016-12-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2023-03-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多