PDF Lesezeichen mit benannten Zielen hinzufügen
Mögliche Verwendungsszenarien
Benannte Ziele sind spezielle Arten von Lesezeichen oder Links in PDF, die nicht von PDF-Seiten abhängen. Das bedeutet, dass Lesezeichen ungültig werden können, wenn Seiten im PDF hinzugefügt oder gelöscht werden, benannte Ziele jedoch intakt bleiben. Für die Erstellung eines benannten Ziels setzen Sie bitte die PdfBookmarkEntry.DestinationName-Eigenschaft.
PDF-Lesezeichen mit benannten Zielen hinzufügen
Bitte sehen Sie sich den folgenden Beispielcode, die Quelldatei Excel (50528348.xlsx) und die Ausgabedatei PDF (50528349.pdf) an. Der Screenshot zeigt die Lesezeichen und benannten Ziele in der Ausgabedatei PDF. Der Screenshot beschreibt auch, wie benannte Ziele angezeigt werden können und dass Sie die professionelle Version von Acrobat Reader benötigen.
Beispielcode
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Load source Excel file | |
Workbook wb = new Workbook(sourceDir + "samplePdfBookmarkEntry_DestinationName.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access cell C5 | |
Cell cell = ws.Cells["C5"]; | |
//Create Bookmark and Destination for this cell | |
PdfBookmarkEntry bookmarkEntry = new PdfBookmarkEntry(); | |
bookmarkEntry.Text = "Text"; | |
bookmarkEntry.Destination = cell; | |
bookmarkEntry.DestinationName = "AsposeCells--" + cell.Name; | |
//Access cell G56 | |
cell = ws.Cells["G56"]; | |
//Create Sub-Bookmark and Destination for this cell | |
PdfBookmarkEntry subbookmarkEntry1 = new PdfBookmarkEntry(); | |
subbookmarkEntry1.Text = "Text1"; | |
subbookmarkEntry1.Destination = cell; | |
subbookmarkEntry1.DestinationName = "AsposeCells--" + cell.Name; | |
//Access cell L4 | |
cell = ws.Cells["L4"]; | |
//Create Sub-Bookmark and Destination for this cell | |
PdfBookmarkEntry subbookmarkEntry2 = new PdfBookmarkEntry(); | |
subbookmarkEntry2.Text = "Text2"; | |
subbookmarkEntry2.Destination = cell; | |
subbookmarkEntry2.DestinationName = "AsposeCells--" + cell.Name; | |
//Add Sub-Bookmarks in list | |
ArrayList list = new ArrayList(); | |
list.Add(subbookmarkEntry1); | |
list.Add(subbookmarkEntry2); | |
//Assign Sub-Bookmarks list to Bookmark Sub-Entry | |
bookmarkEntry.SubEntry = list; | |
//Create PdfSaveOptions and assign Bookmark to it | |
PdfSaveOptions opts = new PdfSaveOptions(); | |
opts.Bookmark = bookmarkEntry; | |
//Save the workbook in Pdf format with given pdf save options | |
wb.Save(outputDir + "outputPdfBookmarkEntry_DestinationName.pdf", opts); |