如何作为单个PDF在Confluence中下载页面?

发布于 2025-01-30 16:20:00 字数 258 浏览 2 评论 0原文

我正在尝试从汇合处下载页面作为单个PDF文件。 我有50多个儿童页面,我想下载每个页面作为单个PDF。 例如,如果我有:

 Parent of Parent   
      Parent Page
       Child Page 1
       Child Page 2
       Child page 3

我想下载“儿童”第1、2和3页作为单独的PDF。

无论如何是否有任何脚本? 也许是python? 请帮我

I'm trying to download pages from my confluence as individual pdf files.
I have more than 50 child pages and I want to download each page as individual pdf.
For example if I have:

 Parent of Parent   
      Parent Page
       Child Page 1
       Child Page 2
       Child page 3

I want to download the child page 1, 2 and 3 as seperate pdf.

Is there anyway or any script to do this?
Maybe python?
Please help me out guys

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘香 2025-02-06 16:20:00

您可以使用atlassian-python-api == 3.27.0来实现这一目标。

获取页面ID

如果您只想从父母方面下载孩子:

from atlassian import Confluence

PARENT_PAGE_ID = 'parent page id'

# This creates connection object confluence with your credentials
confluence = Confluence(
    url='https://confluence.xxxxx.com/',
    username='your_username',
    password='your_password'
)

# Get object contains pages information
children = confluence.get_child_pages(PARENT_PAGE_ID)
for i in children:
    title = i['title']
    id = i['id']
    pdf_name = title + '.pdf'
    # Get confluence page as byte-stream
    content = confluence.get_page_as_pdf(id)
    file_pdf = open(pdf_name, 'wb')
    file_pdf.write(content)
    file_pdf.close()

如果您想下载所有的孩子及其孩子,则必须使用递归:

def tree_downloader(confluence: Confluence, children: list) -> list:
    list_id = []
    for i in children:
        if isinstance(i, str):
            i_id = i
        else:
            i_id = i['id']
        grandchildren = confluence.get_child_pages(i_id)
        list_id.append(i_id)
        if grandchildren:
            list_id.extend(tree_downloader(confluence, grandchildren))
    return list_id

编辑:这里的功能的版本:您的功能的外观:

children = confluence.get_child_pages(PARENT_PAGE_ID)
children = tree_downloader(confluence, children)
for i in children:
    p = confluence.get_page_by_id(i)
    title = p['title']
    id = p['id']
    pdf_name = title+'.pdf'
    content = confluence.get_page_as_pdf(id)
    file_pdf = open(pdf_name, 'wb')
    file_pdf.write(content)
    file_pdf.close()

You can achieve this by using atlassian-python-api==3.27.0.

To get page id instruction

If you want to download simply children from the parent side:

from atlassian import Confluence

PARENT_PAGE_ID = 'parent page id'

# This creates connection object confluence with your credentials
confluence = Confluence(
    url='https://confluence.xxxxx.com/',
    username='your_username',
    password='your_password'
)

# Get object contains pages information
children = confluence.get_child_pages(PARENT_PAGE_ID)
for i in children:
    title = i['title']
    id = i['id']
    pdf_name = title + '.pdf'
    # Get confluence page as byte-stream
    content = confluence.get_page_as_pdf(id)
    file_pdf = open(pdf_name, 'wb')
    file_pdf.write(content)
    file_pdf.close()

If you want to download all the children and their children you have to use recursion:

def tree_downloader(confluence: Confluence, children: list) -> list:
    list_id = []
    for i in children:
        if isinstance(i, str):
            i_id = i
        else:
            i_id = i['id']
        grandchildren = confluence.get_child_pages(i_id)
        list_id.append(i_id)
        if grandchildren:
            list_id.extend(tree_downloader(confluence, grandchildren))
    return list_id

EDIT: here a version of what your function could look like:

children = confluence.get_child_pages(PARENT_PAGE_ID)
children = tree_downloader(confluence, children)
for i in children:
    p = confluence.get_page_by_id(i)
    title = p['title']
    id = p['id']
    pdf_name = title+'.pdf'
    content = confluence.get_page_as_pdf(id)
    file_pdf = open(pdf_name, 'wb')
    file_pdf.write(content)
    file_pdf.close()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文