Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Rest API for Exporting PDF/Word Document

PASUPULA REDDY January 22, 2020

Hi,

could you help us with the rest api for Exporting PDF/Word Document in Confluence.

Regards,

Kulasekhar

 

 

5 answers

1 vote
Elliot Sloman January 23, 2020

If you hover over the "Export to PDF" and the "Export to Word" buttons in Confluence you can see the links that are called when you press those buttons. You can do a GET on these URLs to get the objects.

So the URL would be something like (for PDF):

"confluenceurl" + "/spaces/flyingpdf/pdfpageexport.action?pageId=PAGE_ID"

The auto-generated filename is then in the "content-disposition" of the return object. But you can always set your own filename.

The content of the file is in the return object's content.

 

We use the above method and python to dynamically export pages to PDF when we need to.

 

Hope that helps!

Ronaldo Huang November 18, 2020

@Elliot Sloman 

Hi,how about the URL for exporting Word?

Like 太田 裕康 likes this
Elliot Sloman November 19, 2020

Seems to work as well!

 

The URL is simpler and something like this:

 

"CONFLUENCE_URL" + "exportword?pageId=PAGE_ID"

 

Like above, the filename is in the content-disposition header but you can always set your own if you don't want the auto-generated file name.

The content of the file is in the "content" of the return object. You can simply write that to a file.

 

I tested this morning with a bit of python code and it worked fine.

Ronaldo Huang November 19, 2020

@Elliot Sloman 

It doesn't work for me.My confluence server is local. 

How can I export word using template?

I have tried rest api GET 'http://CONFLUENCE_URL/plugins/servlet/scroll-office/api/public/1/export-sync?templateId=com.k15t.scroll.office.default-template-1&pageId=67415595'

But the response downloaded word is error coding. 

And I also tried the rest api POST 'http://CONFLUENCE_URL/plugins/servlet/scroll-office/api/public/1/exports'

But the response is {
"status": 403,
"message": "User not allowed to export because of export restrictions on either space or groups."
}

According to the document https://help.k15t.com/scroll-pdf-exporter/latest/server/export-content-via-rest-api-125699615.html

David Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2021

Hello @Elliot Sloman 

Using Confluence cloud, when I try doing a GET request to that URL via Postman to export the PDF, then HTML content is returned, not JSON, and there is no 'content-disposition' object.

Can you provide more details and an example for doing that GET request.

0 votes
Urban_Pettersson April 11, 2024

While there is no proper Rest API support for this, you can still get this to work. I have created a GitHub gist which details the necessary steps using NodeJS.

0 votes
Larry.D.East November 4, 2020

I'm working on the same type of issue but only for pdf's.  If you're using Python, you can use the confluence package (https://atlassian-python-api.readthedocs.io/confluence.html) and the export_page function for pdf.

confluence.export_page(page_id)

As the doc indicates, if you're using Confluence Cloud, make sure when you instantiate confluence that you set the api_version to cloud.


confluence = Confluence( url='https://yourcompany.atlassian.net/', api_version='cloud', username=username, password=password)
Dev CloudApp August 22, 2021

@Larry.D.East Were you able to get the PDF exported? What is the scope that was used?

 

token={
"access_token": "token_xxx",
"token_type": "Bearer"
}

oauth2_dict = {
"client_id": "client_id_xxx",
"token": token}

confluence= Confluence( url='https://api.atlassian.com/ex/confluence/{cloud_id_xxx}',
oauth2=oauth2_dict)

 

With the above code, I am able to use the OAuth2.0 authentication and make other functions like 'get_spaces' working. However, the export_page, doesn't return the PDF. Receiving an error  "Unauthorized; scope does not match"

Larry.D.East August 23, 2021

It's been a while since I worked on this so I'll make the disclaimer upfront that it's all a little fuzzy now :)  From what I can find of the source code I still have access to, I didn't specify a scope.  However, a quick search turned up these two links, https://community.developer.atlassian.com/t/unauthorized-scope-does-not-match-forge-app/49459 and https://community.developer.atlassian.com/t/scope-does-not-match/49346, both of which point to recreating the app as a confluence app instead of a jira app.  Don't know if that's your situation, but hope it helps.  Good luck!

0 votes
Nils Bier _K15t_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 23, 2020

Hi @PASUPULA REDDY ,

you might want to have a look at our Scroll PDF Exporter, which lets you easily create templates using a graphical template designer, without the need to know any CSS.

Additionally you can use our REST API (or even Java API) to perform exports automatically.

Scroll PDF Exporter is available via the Atlassian Marketplace and can be tested using a free evaluation license.

Cheers,
Nils

PASUPULA REDDY January 23, 2020

Hi,

 

thanks for the reply, It would be great for us if you share the code along with the http head managers.

 

Regards,

Kulasekhar

Like Ronaldo Huang likes this
0 votes
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 22, 2020

@PASUPULA REDDY  There are no rest api's to export PDF/Word out of Confluence.

But there exists SOAP API's for this - https://developer.atlassian.com/server/confluence/remote-api-specification-for-pdf-export/

Please do verify if SOAP is working with your version of Confluence as Atlassian team is looking to deprecate it as soon as all its features are replicated in REST.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events