How to specify file name of viewpdf macro

GordonS February 2, 2023

How do I create a page using Python API create_page() with embedded PDF?  I'm formatting the body of the page as XHTML, however, I could not find out how to embed PDF file.

https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html

does not go into detail about embedding pdf.

Here's the content of body:

<ac:link>
<ri:attachment ri:filename="report.pdf" />
<ac:plain-text-link-body>
<![CDATA[Link to a report.pdf Attachment]]>
</ac:plain-text-link-body>
</ac:link>
<hr />
<ac:structured-macro ac:name="viewpdf" ac:schema-version="1" >
<ac:parameter ac:name="filename">report.pdf</ac:parameter>
</ac:structured-macro>

The first link works and I can open the attachment.  However, the viewpdf does not find the report.pdf file.

1 answer

1 accepted

0 votes
Answer accepted
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 3, 2023

Hi @GordonS ,

welcome to the Atlassian community!

PDF macro structure at storage format level is the following :

<ac:structured-macro ac:name="viewpdf" ac:schema-version="1" data-layout="default" ac:local-id="7be9d23b-d502-4bae-9de0-8d8f26d02898" ac:macro-id="852d4900-52ce-4967-9c7c-26493c4973e8">
<ac:parameter ac:name="name">
<ri:attachment ri:filename="YOUR_FILE_NAME_HERE.pdf" ri:version-at-save="1" />
</ac:parameter>
</ac:structured-macro>

Hope this helps,

Fabio 

GordonS February 3, 2023

Thank you Fabio for quick reply:

In the end I got it to work, however, I have a question that needs clarification

 <ac:structured-macro ac:name="viewpdf" ac:schema-version="1"
data-layout="default"

ac:local-id="xxxxxxxx-32ea-4827-b4ce-xxxxxxxxxxxx"
ac:macro-id="852d4900-52ce-4967-9c7c-26493c4973e8" >
<ac:parameter ac:name="name">
<ri:attachment ri:filename="report.pdf" ri:version-at-save="1" />
</ac:parameter>
</ac:structured-macro>

I generated my own random GUID for local-id and copied your macro-id.  Is that what I was supposed to do?  Should the local-id match the attachment?  The following command

attach_file('report.pdf', page_id = pageID, content_type='application/pdf')
returns structure with
"extensions" {
"mediaType": "application/pdf",
"fileSize": 5384227,
"comment": "Uploaded report.pdf.",
"mediaTypeDescription": "PDF Document",
"fileId": "xxxxxxxx-3f69-4d8a-ae3c-eef4c2a928aa",
...

However, I do the attach_file() after I do the create_page() since I need the page_id from the return value of create_page().  Was I supposed to go back to the page and edit it?

By the way, I did not include content_type to attach_file() at first and got the following message.   The correct content_type fixed it.  Yay!  

Screen Shot 2023-02-03 at 11.22.38 AM.png

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events