我有一个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:
有一个exportSpace方法可以工作,但我只想要一个页面,getPage方法不会导出到pdf据我所知。此外,这在技术上已被弃用,因此Atlassian建议:
3.REST API
使用:https://docs.atlassian.com/atlassian-confluence/REST/latest-server/
这似乎没有选项将页面导出为PDF
我希望得到一个答案,使任何这些方法工作或如果你有一个完全不同的方法,我不在乎,只要我可以从python脚本获取页面的PDF。
您可以将脚本与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"
#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)