We're sorry AsposeCloud doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.cloud

How To Add Bookmarks in PDF via cURL Command Using Aspose.PDF REST API

I am trying to Use the Aspose. PDF Cloud API. Starting with the Swagger Spec I’m trying to populate the Body JSON to add bookmarks with certain names that will allow a user to click to a certain page though the Bookmark tree in the PDF.

I’m not familiar with the schema and how to construct the body of the Post Call to accomplish this

@Dgain

Please check sample cURL command to add bookmarks in PDF via cURL with sample JSON request body using Aspose.PDF REST API. You may please also check Bookmark object details from GitHub as well. Hopefully, it will help you to accomplish the task.

Insert Bookmarks in PDF

curl -X POST "https://api.aspose.cloud/v3.0/pdf/02_pages.pdf/bookmarks/bookmark/%20" 
-H "accept: application/json" 
-H "authorization: Bearer [Access_Token]" 
-H "Content-Type: application/json" 
-H "x-aspose-client: Containerize.Swagger" 
-d "[ { \"Title\": \"NewBookmark xyz\", \"Italic\": true, \"Bold\": true, \"Color\": { \"A\": 255, \"R\": 255, \"G\": 0, \"B\": 0 }, \"Action\": \"GoTo\", \"Level\": 0, \"PageDisplay\": \"string\", \"PageDisplay_Bottom\": 10, \"PageDisplay_Left\": 10, \"PageDisplay_Right\": 10, \"PageDisplay_Top\": 10, \"PageDisplay_Zoom\": 2, \"PageNumber\": 2 }]"

Thank you! This was very helpful.

Currently, the problem I’m encountering is figuring out what I need to input for the “bookmarkPath” parameter. Whenever I try to Post a new bookmark to this file, I keep getting Error Code 500 “Message”: “Invalid shape’s path. (bookmark)”

For my document “Test.pdf”

I’ve been able to Get the Bookmarks tree:

{
“Bookmarks”: {
“List”: [],
“Links”: [
{
“Href”: “/test.pdf/bookmarks”,
“Rel”: “self”,
“Type”: null,
“Title”: null
}
]
},
“Code”: 200,
“Status”: “OK”
}

@Dgain

Please check the parameter description in Swagger Web API explorer. If you want to add a child bookmark to an existing root bookmark then you need to pass the index of the root bookmark in bookmarkPath parameter. Otherwise, leave it empty. Hopefully, it answers your question.

However, if you still have any confusion then please share your sample code along with the input PDF document and expected PDF document. We will look into these and will share our findings with you.

I have been able to add one or more bookmarks to a PDF document using the POST method, but I have been unable to add a nested bookmark to a second level. For example:

Bookmark 1: Header
Bookmark 2: Header
Bookmark 2/1: sub header (This is what I can’t make work)

[
{
“Links”: [
{
“Href”: “/test.pdf/bookmarks/bookmark/1”,
“Rel”: “self”,
“Type”: null,
“Title”: null
}
],
“Title”: “Test with Levels”,
“Italic”: true,
“Bold”: true,
“Color”: {
“A”: 0,
“R”: 0,
“G”: 0,
“B”: 0
},
“Action”: “GoTo”,
“Level”: 1,
“Destination”: “3”,
“PageDisplay”: “Fit”,
“PageDisplay_Bottom”: 0,
“PageDisplay_Left”: 0,
“PageDisplay_Right”: 0,
“PageDisplay_Top”: 0,
“PageDisplay_Zoom”: 0,
“PageNumber”: 3,
“RemoteFile”: null,
“Bookmarks”: {
“Links”: [
{
“Href”: “/test.pdf/bookmarks/bookmark/1”,
“Rel”: “self”,
“Type”: null,
“Title”: null
}
],
“List”: [
null
]
}
},
{
“Links”: [
{
“Href”: “/test.pdf/bookmarks/bookmark/2”,
“Rel”: “self”,
“Type”: null,
“Title”: null
}
],
“Title”: “2. Test with Levels”,
“Italic”: true,
“Bold”: true,
“Color”: {
“A”: 0,
“R”: 0,
“G”: 0,
“B”: 0
},
“Action”: “GoTo”,
“Level”: 1,
“Destination”: “5”,
“PageDisplay”: “Fit”,
“PageDisplay_Bottom”: 0,
“PageDisplay_Left”: 0,
“PageDisplay_Right”: 0,
“PageDisplay_Top”: 0,
“PageDisplay_Zoom”: 0,
“PageNumber”: 5,
“RemoteFile”: null,
“Bookmarks”: {
“Links”: [
{
“Href”: “/test.pdf/bookmarks/bookmark/2”,
“Rel”: “self”,
“Type”: null,
“Title”: null
}
],
“List”: [
{
“Links”: [
{
“Href”: “/test.pdf/bookmarks/bookmark/2/1”,
“Rel”: “self”,
“Type”: null,
“Title”: null
}
],
“Title”: “1. Resume”,
“Italic”: true,
“Bold”: true,
“Color”: {
“A”: 0,
“R”: 0,
“G”: 0,
“B”: 0
},
“Action”: “GoTo”,
“Level”: 2,
“Destination”: “8”,
“PageDisplay”: “Fit”,
“PageDisplay_Bottom”: 0,
“PageDisplay_Left”: 0,
“PageDisplay_Right”: 0,
“PageDisplay_Top”: 0,
“PageDisplay_Zoom”: 0,
“PageNumber”: 8,
“RemoteFile”: null,
“Bookmarks”: {
“Links”: [
{
“Href”: “/test.pdf/bookmarks/bookmark/2/1”,
“Rel”: “self”,
“Type”: null,
“Title”: null
}
],
“List”: [
null
]
}
}
]
}
}
]

@Dgain

Please note for the nested(child) bookmark you need to set bookmarkPath for the parent bookmark index. Mean in your scenario you need to set bookmarkPath to 2.

Thank you, so there is no way to Bookmarks with their Child Bookmarks in a single API call–I would have to add the parent bookmarks, then do an additional API call to add the child bookmarks?

@Dgain

Yes, you can add a single bookmark(parent/child) with an API call at a time. If your PDF document has already a parent bookmark then you can add directly a child bookmark to the parent bookmark. Otherwise, for a child bookmark, first, you need to add a parent bookmark and then add a child bookmark using an additional API call.