Can I Add bookmarks in PDF file converted from Excel template

Hi ,

We are using Aspose.Cells , we do have different excel templates used for reporting.

I am using following method to convert Excel template to PDF :

book.Save("yahoo.pdf", SaveType.OpenInExcel, FileFormatType.Pdf, HttpContext.Current.Response);

Is there any way I can add bookmarks to this PDF file ? I mean to say can we have tab names as individual bookmarks in converted PDF ?

Regards

Pankaj Singh

Hi Pankaj,

Thanks for your inquiry.

Yes, you can add your desired bookmarks to generated pdf file.
See the following sample code, you can modify the code for your requirements. Also, kindly use latest fix e.g 4.8.0.13 (that i provided you in other thread).

Sample code:
Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
Aspose.Cells.Cell A = cells[“A10”];
A.PutValue(“page1”);
Aspose.Cells.Cell D = cells[“H15”];
D.PutValue(“page1(H15)”);
workbook.Worksheets.Add();
cells = workbook.Worksheets[1].Cells;
Aspose.Cells.Cell B = cells[“B10”];
B.PutValue(“page2”);
workbook.Worksheets.Add();
cells = workbook.Worksheets[2].Cells;
Aspose.Cells.Cell C = cells[“C10”];
C.PutValue(“page3”);

PdfBookmarkEntry pbeRoot = new PdfBookmarkEntry();
pbeRoot.Text = “section1”;
pbeRoot.Destination = A;
pbeRoot.SubEntry = new ArrayList();
PdfBookmarkEntry subPbe = new PdfBookmarkEntry();
subPbe.Text = “section2.1”;
subPbe.Destination = B;
pbeRoot.SubEntry.Add(subPbe);
subPbe = new PdfBookmarkEntry();
subPbe.Text = “section2.2”;
subPbe.Destination = C;
pbeRoot.SubEntry.Add(subPbe);

PdfBookmarkEntry lastSubPbe = subPbe;
subPbe = new PdfBookmarkEntry();
subPbe.Text = “section3.1”;
subPbe.Destination = D;
lastSubPbe.SubEntry = new ArrayList();
lastSubPbe.SubEntry.Add(subPbe);
workbook.SaveOptions.PdfBookmark = pbeRoot;
workbook.Save(“f:\test\3Testasdfasds.pdf”);


Thank you.

Thanks a lot Amjad . This one really helped me.

I have one more query I was not able to implement more than one bookmark at Root

Meaning I want to implement something like :

Section 1

Sectoin 2

Section 3

Instead of

Section 1

Section 1.1

Section 1.2

Is there any pointer on this OR there might be I am making some mistake ?

Hi,

I think you may define one main Root element and then three sub-root elements in the format (if it suit your requirements) e.g

Sections

Section 1

Sectoin 2

Section 3


Sample code:

Workbook workbook = new Workbook();
Cells cells = workbook.Worksheets[0].Cells;
Aspose.Cells.Cell p = cells["A1"];
p.PutValue("Preface");

Aspose.Cells.Cell A = cells["A10"];
A.PutValue("page1");
Aspose.Cells.Cell D = cells["H15"];
D.PutValue("page1(H15)");
workbook.Worksheets.Add();
cells = workbook.Worksheets[1].Cells;
Aspose.Cells.Cell B = cells["B10"];
B.PutValue("page2");
workbook.Worksheets.Add();
cells = workbook.Worksheets[2].Cells;
Aspose.Cells.Cell C = cells["C10"];
C.PutValue("page3");

PdfBookmarkEntry pbeRoot = new PdfBookmarkEntry();
pbeRoot.Text = "Sections";
pbeRoot.Destination = p;
pbeRoot.SubEntry = new ArrayList();

PdfBookmarkEntry subPbe1 = new PdfBookmarkEntry();
subPbe1.Text = "Section 1";
subPbe1.Destination = A;
pbeRoot.SubEntry.Add(subPbe1);

PdfBookmarkEntry subPbe2 = new PdfBookmarkEntry();
subPbe2.Text = "Section 2";
subPbe2.Destination = B;
pbeRoot.SubEntry.Add(subPbe2);

PdfBookmarkEntry subPbe3 = new PdfBookmarkEntry();
subPbe3.Text = "Section 3";
subPbe3.Destination = C;
pbeRoot.SubEntry.Add(subPbe3);

workbook.SaveOptions.PdfBookmark = pbeRoot;

workbook.Save("f:\\test\\TestBookmarks.pdf");

Thank you.