Agregar marcadores PDF con Destinos Nominados

Escenarios de uso posibles

Los Destinos Nominados son un tipo especial de marcadores o enlaces en PDF que no dependen de las páginas PDF. Esto significa que si se añaden o eliminan páginas del PDF, los marcadores pueden volverse inválidos pero los destinos nominados permanecerán intactos. Para crear un Destino Nombrado, por favor establece la propiedad PdfBookmarkEntry.DestinationName.

Agregar Marcadores de PDF con Destinos Nombrados

Consulte el siguiente código de muestra, su archivo Excel fuente y su archivo PDF de salida. La captura de pantalla muestra los marcadores y destinos nombrados dentro del PDF de salida. La captura de pantalla también describe cómo ver los Destinos Nombrados y que se necesita la versión Profesional de Acrobat Reader.

todo:image_alt_text

Código de muestra

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Load source Excel file
Workbook wb = new Workbook(srcDir + "samplePdfBookmarkEntry_DestinationName.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Access cell C5
Cell cell = ws.getCells().get("C5");
//Create Bookmark and Destination for this cell
PdfBookmarkEntry bookmarkEntry = new PdfBookmarkEntry();
bookmarkEntry.setText("Text");
bookmarkEntry.setDestination(cell);
bookmarkEntry.setDestinationName("AsposeCells--" + cell.getName());
//Access cell G56
cell = ws.getCells().get("G56");
//Create Sub-Bookmark and Destination for this cell
PdfBookmarkEntry subbookmarkEntry1 = new PdfBookmarkEntry();
subbookmarkEntry1.setText("Text1");
subbookmarkEntry1.setDestination(cell);
subbookmarkEntry1.setDestinationName("AsposeCells--" + cell.getName());
//Access cell L4
cell = ws.getCells().get("L4");
//Create Sub-Bookmark and Destination for this cell
PdfBookmarkEntry subbookmarkEntry2 = new PdfBookmarkEntry();
subbookmarkEntry2.setText("Text2");
subbookmarkEntry2.setDestination(cell);
subbookmarkEntry2.setDestinationName("AsposeCells--" + cell.getName());
//Add Sub-Bookmarks in list
ArrayList list = new ArrayList();
list.add(subbookmarkEntry1);
list.add(subbookmarkEntry2);
//Assign Sub-Bookmarks list to Bookmark Sub-Entry
bookmarkEntry.setSubEntry(list);
//Create PdfSaveOptions and assign Bookmark to it
PdfSaveOptions opts = new PdfSaveOptions();
opts.setBookmark(bookmarkEntry);
//Save the workbook in Pdf format with given pdf save options
wb.save(outDir + "outputPdfBookmarkEntry_DestinationName.pdf", opts);