HTML JPG PDF XML DOCX
  Product Family
PDF

Work with Bookmarks in PDF in .NET SDK

Manipulate Bookmarks in PDF Document using server-side .NET API.

Get Started

How to work with Bookmarks via Cloud .NET SDK

In order to work with Bookmarks in PDF via Cloud .NET SDK , we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


     
    PM> Install-Package Aspose.Pdf-Cloud
     
     

Steps to create a Bookmark via .NET SDK

Aspose.PDF Cloud developers can easily load & create bookmark in PDF in just a few lines of code.

  1. Create a new Configuration object with your Application Secret and Key
  2. Create an object to connect to the Cloud API
  3. Upload your document file
  4. Set desired property using PostBookmarkAsync
  5. Checks the response and logs the result.
  6. Downloads the updated file for local use.
 

This sample code shows creating a Bookmark in PDF documents


    public static async Task AppendBookmark()
    {
        const string localPdfDocument = @"C:\Samples\sample.pdf";
        const string storageFileName = "sample.pdf";
        const string localFolder = @"C:\\Samples";
        const string resultFileName = "output_add_bookmark.pdf";
        const string parentBookmarkPath =  "/5";

		// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
		var pdfApi = new PdfApi(AppSecret, AppSid);

        using var file = File.OpenRead(localPdfDocument);
        var uploadResult = await pdfApi.UploadFileAsync(storageFileName, file);
        Console.WriteLine(uploadResult.Uploaded[0]);
         
        // Create new bookmark with input parameters for the PDF on cloud storage.
        Bookmark bookmark = new Bookmark(
                    Action: "GoTo",
                    Bold: true,
                    Italic: false,
                    Title: 		"NEW BOOKMARK TITLE",
                    PageDisplay: "XYZ",
                    PageDisplayBottom: 10,
                    PageDisplayLeft: 10,
                    PageDisplayRight: 10,
                    PageDisplayTop: 10,
                    PageDisplayZoom: 2,
                    PageNumber: 1,
                    Color: new Color(A: 0x00, R: 0x00, G: 0xFF, B: 0x00)
        );
        List<Bookmark> newBookmarks = new List<Bookmark>() { bookmark };

        BookmarksResponse response = await pdfApi.PostBookmarkAsync(storageFileName, parentBookmarkPath, newBookmarks);

        if (response == null)
            Console.WriteLine("ReplaceTextAnnotation(): Unexpected error!");
        else if (response.Code < 200 || response.Code > 299)
            Console.WriteLine("AppendBookmark(): Failed to add bookmark in the document.");
        else
        {
            await (await pdfApi.DownloadFileAsync(storageFileName))
                .CopyToAsync(File.Create(Path.Combine(localFolder, resultFileName)));
            Console.WriteLine("AppendBookmark(): bookmark added in the document '{0}.", resultFileName);
        }
    }