Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting as pdf #1332

Open
Kruttifrutti opened this issue Feb 6, 2024 · 5 comments
Open

Exporting as pdf #1332

Kruttifrutti opened this issue Feb 6, 2024 · 5 comments

Comments

@Kruttifrutti
Copy link

Hi,

Trying to export as pdf, but only getting an empty pdf.

`def save_file(content, title):
file_pdf = open(title + ".pdf", "w")
file_pdf.write(content)
file_pdf.close()
print("Completed")

if name == "main":
label = "apitesting"
pages = confluence.get_all_pages_by_label(label=label, start=0, limit=10)
for page in pages:
response = confluence.get_page_as_pdf(page["id"])
save_file(content=response, title=page["title"])`

Error message suggests write() argument must be str, not bytes.

Any clues?

@ashishpatel1992
Copy link
Contributor

You should open file as wb instead of w
wb allows files to be opened for writing as binary

@Kruttifrutti
Copy link
Author

You should open file as wb instead of w wb allows files to be opened for writing as binary

Thanks for helping out, unfortunately, I am still getting a corrupted file...

@ashishpatel1992
Copy link
Contributor

Quick check on this, I have tested the code and it is able to generate the pdf for me.
Possibly you need to first check if authentication is working correctly or not.

Sharing the code snippet which worked for me

from atlassian import Confluence

def save_file(content, title):
    file_pdf = open(title + ".pdf", "wb")
    file_pdf.write(content)
    file_pdf.close()
    print("Completed")

secret_key="<your_confluence_secret_key>"
label = "apitesting"
confluence = Confluence(
        url='https://<your_confluence_url>',
        token=secret_key)
pages = confluence.get_all_pages_by_label(label=label, start=0, limit=10)
for page in pages:
    response = confluence.get_page_as_pdf(page["id"])
    save_file(content=response, title=page["title"])

Also I have used adobe acrobat to verify the files

@frankiedrake
Copy link

label

I have a problem with the export API.
I did provide a token and I can successfully get page content etc., but export to pdf returns the HTML content of a login page.
Here's my code:

confluence = Confluence(
    url='https://my.company.confluence/',
    token=token)

page = confluence.get_page_by_id(11111, expand='body.storage') # WORKS WELL
print(page['title'])

response = confluence.get_page_as_pdf(68258487)
print(response) # PRINTS Login page content

@ashishpatel1992
Copy link
Contributor

@frankiedrake It could be possible that your confluence API url is incorrect. thats why you are seeing Login page as HTML result.
Check with your administrator for correct url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants