REST API to export and download a page in PDF format

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Rest API to export and download a page in PDF format in Confluence

Environment

Confluence Data Center 7.x.x

Solution

Since there isn't an official API for exporting pages as PDFs as per Confluence REST API, you can use the export action from FlyingPDF as a workaround to export and download the page in PDF format.

This can be done in the below steps :

  • First, call the export URL, in verbose mode using the below curl command:

1 curl -v -u user:password -H "X-Atlassian-Token: no-check" <BASE_URL>/spaces/flyingpdf/pdfpageexport.action\?pageId=<PAGE-ID>
  • In the response headers from the above curl command, you'll find the URL to download the PDF under the location :

1 2 3 4 5 6 7 8 9 10 < HTTP/2 302 < cache-control: no-store < content-security-policy: frame-ancestors 'self' < content-type: text/html;charset=UTF-8 < date: Thu, 22 Aug 2024 04:11:03 GMT < expires: Thu, 01 Jan 1970 00:00:00 GMT < location: /confluence/download/export/pdfexport-20240822-220824-0410-1/test_8797801676934c48931f83261b52adf6-220824-0410-2.pdf?contentType=application/pdf < set-cookie: _b0691=720538dfc61b5d60; Path=/ < set-cookie: JSESSIONID=3A0BC7AD0A643250FD0E962B884F0ED7; Path=/confluence; Secure; HttpOnly < x-ausername: admin
  • Copy the path from the above location and make another call to download the file. Specify the destination where you want to save the file under --output :

1 curl -v -u user:password <BASE_URL>/download/export/pdfexport-20240822-220824-0410-1/test_8797801676934c48931f83261b52adf6-220824-0410-2.pdf --output /location/to/file.pdf

The above command will save the PDF export of the specified page to the location specified in the --output option.

Updated on March 12, 2025

Still need help?

The Atlassian Community is here for you.