Important alert: (current site time 7/16/2013 7:23:19 AM EDT)
 

article

Insert PDF Bookmarks While Converting a Spreadsheet to PDF file

Email
Submitted on: 1/13/2011 5:34:36 PM
By: aspose_seo 
Level: Intermediate
User Rating: Unrated
Compatibility: Java (JDK 1.2), Java (JDK 1.3), Java (JDK 1.4)
Views: 4450
 
     This technical tip shows how to insert PDF Bookmarks while converting a spreadsheet to PDF file.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				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 extracted 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.Cells for Java
- Homepage of Aspose.Cells for Java: http://www.aspose.com/categories/java-components/aspose.cells-for-java/default.aspx
- Read more technical tips by Aspose.Cells for Java: http://www.aspose.com/documentation/java-components/aspose.cells-for-java/index.html 
- Download Aspose.Cells for Java: http://www.aspose.com/community/files/72/java-components/aspose.cells-for-java/default.aspx 
Contact Information
Aspose Pty Ltd, 
Suite 163, 79 Longueville Road
Lane Cove, NSW, 2066 
Australia
http://www.aspose.com/
sales@aspose.com
Phone: 888.277.6734
Fax: 866.810.9465l


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.