Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export to PDF a confluence page within a script

I'd like to automatically export to PDF some confluence pages.

It can be downloaded with URL :

  • http://<confluence server>/confluence/spaces/flyingpdf/pdfpageexport.action?pageId=<pageID>

When typing this URL, it works perfectly.

But when I try to download with wget, an HTML page is downloaded instead ( asking for login and password). I tried to provide login/password with --user and --password wget options but it does not work.

Do you have an idea to provide confluence credentials to wget command? Or another solution to download the PDF page?

like image 435
Alpes Maritimes Avatar asked Aug 04 '16 15:08

Alpes Maritimes


2 Answers

If you are using a Confluence Server before Confluence 5.5 you are in luck! Confluence has an API to handle this, see their documentation.

Update : If you are using Confluence Server 5.5 or later, they do not enable the API for this by default. See Confluence Administration > Further Configuration to enable the XML-RPC and SOAP APIs. (Thanks @fatpanther for pointing this out)

The new REST API does not support this, see the REST API documentation.

You may be able to use the Confluence Command Line Interface to export to PDF.

like image 179
Brandon Haugen Avatar answered Nov 01 '22 10:11

Brandon Haugen


First request the resource:

curl -D- -u user:pwd -X GET -H "Content-Type: application/json" "https://your-url/confluence/spaces/flyingpdf/pdfpageexport.action?pageId=12345678"

Extract the "Location" value from the resulting JSON (e.g. grep | cut), then repeat the query with adjusted URL and mime type:

curl -D- -u user:pwd -X GET -H "Content-Type: text/html;charset=UTF-8" "https://your-url/$LOCATION_JUST_EXTRACTED" --output file.pdf
like image 25
Narcolessico Avatar answered Nov 01 '22 11:11

Narcolessico