Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Insert PDF Bookmarks While Converting a Spreadsheet to PDF file

 
Ranch Hand
Posts: 714
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This technical tip shows how to insert PDF Bookmarks while converting a spreadsheet to PDF file. Aspose.Cells allows you to add bookmarks for your requirement at runtime. PDF bookmarks can drastically improve the navigability of longer PDF documents. When adding bookmark links to other parts of a PDF document, users can have precise control over the exacted view as they want, users are not limited to just linking to a page or so. In this document, we have provided the simplest lines of code using Aspose.Cells API to perform the task for you.

Please see the following sample code to find how you can add PDF bookmarks. We will generate a simple workbook, specify PDF bookmarks with their destination locations and finally generate the PDF file.


[Java]



import com.aspose.cells.*;

import java.io.*;

import java.util.*;


public class PdfBookmarksTest

{                                  

    public static void main(String[] args) throws Exception

    {

      


//Instantiate a new workbook.  

Workbook workbook = new Workbook();

//Get the worksheets in the workbook.

Worksheets worksheets = workbook.getWorksheets();

//Add a sheet to the workbook.

worksheets.addSheet("1");

//Add 2nd sheet to the workbook.

worksheets.addSheet("2");

//Add the third sheet.

worksheets.addSheet("3");

//Get cells in different worksheets.

Cell cellInPage1 = worksheets.getSheet(0).getCells().getCell("A1");

Cell cellInPage2 = worksheets.getSheet(1).getCells().getCell("A1");

Cell cellInPage3 = worksheets.getSheet(2).getCells().getCell("A1");


//Add a value to the A1 cell in the first sheet.

cellInPage1.setValue("a");

//Add a value to the A1 cell in the second sheet.

cellInPage2.setValue("b");

//Add a value to the A1 cell in the third sheet.

cellInPage3.setValue("c");


//Create the PdfBookmark entry object.

PdfBookmarkEntry pbeRoot = new PdfBookmarkEntry();

//Set its text.

pbeRoot.setText("root");

//Set its destination source page.

pbeRoot.setDestination(cellInPage1);

//Set the bookmark collapsed.

pbeRoot.setIsOpen(false);

//Add a new PdfBookmark entry object.

PdfBookmarkEntry subPbe1 = new PdfBookmarkEntry();

//Set its text.

subPbe1.setText("1");

//Set its destination source page.

subPbe1.setDestination(cellInPage2);


//Add another PdfBookmark entry object.

PdfBookmarkEntry subPbe2 = new PdfBookmarkEntry();

//Set its text.

subPbe2.setText("2");

//Set its destination source page.

subPbe2.setDestination(cellInPage3);

//Create an array list.

ArrayList subEntryList = new ArrayList();

//Add the entry objects to it.

subEntryList.add(subPbe1);

subEntryList.add(subPbe2);

pbeRoot.setSubEntryList(subEntryList);


//Set the pdf bookmarks, you need to specify the root object here.

workbook.getSaveOptions().setPdfBookmarkEntry(pbeRoot);


//Save the pdf file.

workbook.save("d:\\files\\PdfBookmarks_test.pdf", FileFormatType.PDF);


    }

}


More about Aspose.BarCode for Java



Contact Information


Aspose Pty Ltd

Suite 163, 79 Longueville Road

Lane Cove, NSW, 2066

Australia

Aspose – Your File Format Experts

sales@aspose.com


Phone: 888.277.6734

Fax: 866.810.94651


 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic