Aggiungi Segnalibri PDF con Destinazioni con Nome
Possibili Scenari di Utilizzo
Le Destinazioni con Nome sono un tipo speciale di segnalibri o collegamenti nei PDF che non dipendono dalle pagine PDF. Ciò significa che, se vengono aggiunte o eliminate pagine dal PDF, i segnalibri possono diventare non validi ma le destinazioni con nome rimarranno integre. Per creare una Destinazione con Nome, si prega di impostare la proprietà PdfBookmarkEntry.destination_name.
Aggiungi Segnalibri PDF con Destinazioni con Nome
Si prega di consultare il codice di esempio seguente, il file Excel di origine e il file PDF di output. La schermata mostra i segnalibri e le destinazioni con nome all’interno del PDF di output. La schermata descrive anche come visualizzare le Destinazioni con Nome e che è necessaria la versione Professionale di Acrobat Reader.
Codice di Esempio
from aspose.cells import PdfSaveOptions, Workbook | |
from aspose.cells.rendering import PdfBookmarkEntry | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Load source Excel file | |
wb = Workbook(sourceDir + "samplePdfBookmarkEntry_DestinationName.xlsx") | |
# Access first worksheet | |
ws = wb.worksheets[0] | |
# Access cell C5 | |
cell = ws.cells.get("C5") | |
# Create Bookmark and Destination for this cell | |
bookmarkEntry = PdfBookmarkEntry() | |
bookmarkEntry.text = "Text" | |
bookmarkEntry.destination = cell | |
bookmarkEntry.destination_name = "AsposeCells--" + cell.name | |
# Access cell G56 | |
cell = ws.cells.get("G56") | |
# Create Sub-Bookmark and Destination for this cell | |
subbookmarkEntry1 = PdfBookmarkEntry() | |
subbookmarkEntry1.text = "Text1" | |
subbookmarkEntry1.destination = cell | |
subbookmarkEntry1.destination_name = "AsposeCells--" + cell.name | |
# Access cell L4 | |
cell = ws.cells.get("L4") | |
# Create Sub-Bookmark and Destination for this cell | |
subbookmarkEntry2 = PdfBookmarkEntry() | |
subbookmarkEntry2.text = "Text2" | |
subbookmarkEntry2.destination = cell | |
subbookmarkEntry2.destination_name = "AsposeCells--" + cell.name | |
# Add Sub-Bookmarks in list | |
list = [] | |
list.append(subbookmarkEntry1) | |
list.append(subbookmarkEntry2) | |
# Assign Sub-Bookmarks list to Bookmark Sub-Entry | |
bookmarkEntry.sub_entry = list | |
# Create PdfSaveOptions and assign Bookmark to it | |
opts = PdfSaveOptions() | |
opts.bookmark = bookmarkEntry | |
# Save the workbook in Pdf format with given pdf save options | |
wb.save(outputDir + "outputPdfBookmarkEntry_DestinationName.pdf", opts) |