Create bookmarks for each PDF file appended

I am trying to create bookmarks (named after each file) that I append to an existing PDF. My method works OK but the documentation tells me that I am using a deprecated method. I cannot find any updated online documentation on how to do this with the latest version. When I right click on Aspose.Pdf.dll I get:

File Version 11.6.0.0
Product version: 2016.05.04

Here is the method that works with the deprecated function:
private void CombinePDFs(List pdfList, string newPdf)
{
string outputFolder = tbOutput.Text;
int row = 0;

OutlineItemCollection pdfOutline = null;
Aspose.Pdf.Document pdfFile = null;
foreach (string f in pdfList)
{
if (row == 0) // if this is the first file then add a bookmark to page 1
{
pdfFile = new Aspose.Pdf.Document(f);
pdfOutline = new OutlineItemCollection(pdfFile.Outlines);
pdfOutline.Title = Path.GetFileName(f);
pdfOutline.Italic = true;
pdfOutline.Bold = true;
Aspose.Pdf.Annotations.GoToAction action = new Aspose.Pdf.Annotations.GoToAction(1); // this is deprecated
pdfOutline.Destination = action;
pdfFile.Outlines.Add(pdfOutline);
}
else // bookmark the current page
{
Aspose.Pdf.Document pdf2Append = new Aspose.Pdf.Document(f);
int pg = pdfFile.Pages.Count + 1;
pdfFile.Pages.Add(pdf2Append.Pages);
pdfOutline = new OutlineItemCollection(pdfFile.Outlines);
pdfOutline.Title = Path.GetFileName(f);
pdfOutline.Italic = true;
pdfOutline.Bold = true;


Aspose.Pdf.Annotations.GoToAction action = new Aspose.Pdf.Annotations.GoToAction(pg); // this is deprecated
pdfOutline.Destination = action;

pdfFile.Outlines.Add(pdfOutline);
}
row++;
}
pdfFile.Save(newPdf);
}

Hi Richard,

Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for .NET 11.8.0 and I am unable to notice any issue. As per my observations, the PDF files are properly being concatenated and bookmarks are properly being created for individual PDF file. Can you please try using latest release and in case you still face the same problem, please share some sample project. We are sorry for this inconvenience.

[C#]

List<string> list = new List<string>();
list.Add("c:/pdftest/CopyRight_output.pdf");
list.Add("c:/pdftest/Test.pdf");
list.Add("c:/pdftest/Created.pdf");
list.Add("c:/pdftest/Generated_Header.pdf");
CombinePDFs(list, "c:/pdftest/Concatenated_Bookmarked.pdf");

private void CombinePDFs(List<string> pdfList, string newPdf)
{
    string outputFolder = "c:/pdftest/";
    int row = 0;
    OutlineItemCollection pdfOutline = null;
    Aspose.Pdf.Document pdfFile = null;
    foreach (string f in pdfList)
    {
        if (row == 0)
        {
            pdfFile = new Aspose.Pdf.Document(f);
            pdfOutline = new OutlineItemCollection(pdfFile.Outlines);
            pdfOutline.Title = Path.GetFileName(f);
            pdfOutline.Italic = true;
            pdfOutline.Bold = true;
            Aspose.Pdf.Annotations.GoToAction action = new Aspose.Pdf.Annotations.GoToAction(1);
            pdfOutline.Destination = action;
            pdfFile.Outlines.Add(pdfOutline);
        }
        else
        {
            Aspose.Pdf.Document pdf2Append = new Aspose.Pdf.Document(f);
            int pg = pdfFile.Pages.Count + 1;
            pdfFile.Pages.Add(pdf2Append.Pages);
            pdfOutline = new OutlineItemCollection(pdfFile.Outlines);
            pdfOutline.Title = Path.GetFileName(f);
            pdfOutline.Italic = true;
            pdfOutline.Bold = true;
            Aspose.Pdf.Annotations.GoToAction action = new Aspose.Pdf.Annotations.GoToAction(pg);
            pdfOutline.Destination = action;
            pdfFile.Outlines.Add(pdfOutline);
        }
        row++;
    }
    pdfFile.Save(newPdf);
}

As I mentioned in my post, the method works just fine. The issue is that intellisense tells me that the GoToAction method is deprecated so I am looking for the proper method to add the bookmark action. That’s the only issue with the method.

Hi Richard,

We are sorry for the confusion. Please use GoToAction() constructor with Aspose.Pdf.Page parameter as suggested by intellisense. It will help you to accomplish the task.

foreach (string f in pdfList)
{
    if (row == 0)
    {
        pdfFile = new Aspose.Pdf.Document(f);
        pdfOutline = new OutlineItemCollection(pdfFile.Outlines);
        pdfOutline.Title = Path.GetFileName(f);
        pdfOutline.Italic = true;
        pdfOutline.Bold = true;
        Aspose.Pdf.Annotations.GoToAction action = new Aspose.Pdf.Annotations.GoToAction(pdfFile.Pages[1]);
        pdfOutline.Destination = action;
        pdfFile.Outlines.Add(pdfOutline);
    }
    else
    {
        Aspose.Pdf.Document pdf2Append = new Aspose.Pdf.Document(f);
        int pg = pdfFile.Pages.Count + 1;
        pdfFile.Pages.Add(pdf2Append.Pages);
        pdfOutline = new OutlineItemCollection(pdfFile.Outlines);
        pdfOutline.Title = Path.GetFileName(f);
        pdfOutline.Italic = true;
        pdfOutline.Bold = true;
        Aspose.Pdf.Annotations.GoToAction action = new Aspose.Pdf.Annotations.GoToAction(pdfFile.Pages[pg]);
        pdfOutline.Destination = action;
        pdfFile.Outlines.Add(pdfOutline);
    }
    row++;
}

Please feel free to contact us for any further assistance.

Best Regards,

And here I thought it would be complicated. :slight_smile:

Thank you very much!!!