Agregar marcadores de posición en PDF
Este artículo proporciona información sobre cómo insertar marcadores de posición en PDF al convertir una hoja de cálculo a PDF.
Aspose.Cells para Python via .NET te permite agregar marcadores sobre la marcha. Los marcadores de PDF pueden mejorar drásticamente la navegabilidad de documentos largos. Al agregar enlaces de marcadores al documento PDF, puedes tener un control preciso sobre la vista exacta que deseas, no estás limitado a enlazar a una página. Puedes configurar la vista precisa posicionando la página de destino y luego crear el marcador.
Por favor, consulta el siguiente código de ejemplo para saber cómo agregar marcadores PDF. El código genera un libro de trabajo sencillo, especifica marcadores PDF con ubicaciones de destino y genera el archivo PDF.
from aspose.cells import PdfSaveOptions, Workbook | |
from aspose.cells.rendering import PdfBookmarkEntry | |
from os import os, path | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Create directory if it is not already present. | |
IsExists = path.isdir(dataDir) | |
if notIsExists: | |
os.makedirs(dataDir) | |
# Instantiate a new workbook | |
workbook = Workbook() | |
# Get the cells in the first(default) worksheet | |
cells = workbook.worksheets[0].cells | |
# Get the A1 cell | |
p = cells.get("A1") | |
# Enter a value | |
p.put_value("Preface") | |
# Get the A10 cell | |
A = cells.get("A10") | |
# Enter a value. | |
A.put_value("page1") | |
# Get the H15 cell | |
D = cells.get("H15") | |
# Enter a value | |
D.put_value("page1(H15)") | |
# Add a new worksheet to the workbook | |
workbook.worksheets.add() | |
# Get the cells in the second sheet | |
cells = workbook.worksheets[1].cells | |
# Get the B10 cell in the second sheet | |
B = cells.get("B10") | |
# Enter a value | |
B.put_value("page2") | |
# Add a new worksheet to the workbook | |
workbook.worksheets.add() | |
# Get the cells in the third sheet | |
cells = workbook.worksheets[2].cells | |
# Get the C10 cell in the third sheet | |
C = cells.get("C10") | |
# Enter a value | |
C.put_value("page3") | |
# Create a main PDF Bookmark entry object | |
pbeRoot = PdfBookmarkEntry() | |
# Specify its text | |
pbeRoot.text = "Sections" | |
# Set the destination cell/location | |
pbeRoot.destination = p | |
# Set its sub entry array list | |
pbeRoot.sub_entry = [] | |
# Create a sub PDF Bookmark entry object | |
subPbe1 = PdfBookmarkEntry() | |
# Specify its text | |
subPbe1.text = "Section 1" | |
# Set its destination cell | |
subPbe1.destination = A | |
# Define/Create a sub Bookmark entry object of "Section A" | |
ssubPbe = PdfBookmarkEntry() | |
# Specify its text | |
ssubPbe.text = "Section 1.1" | |
# Set its destination | |
ssubPbe.destination = D | |
# Create/Set its sub entry array list object | |
subPbe1.sub_entry = [] | |
# Add the object to "Section 1" | |
subPbe1.sub_entry.append(ssubPbe) | |
# Add the object to the main PDF root object | |
pbeRoot.sub_entry.append(subPbe1) | |
# Create a sub PDF Bookmark entry object | |
subPbe2 = PdfBookmarkEntry() | |
# Specify its text | |
subPbe2.text = "Section 2" | |
# Set its destination | |
subPbe2.destination = B | |
# Add the object to the main PDF root object | |
pbeRoot.sub_entry.append(subPbe2) | |
# Create a sub PDF Bookmark entry object | |
subPbe3 = PdfBookmarkEntry() | |
# Specify its text | |
subPbe3.text = "Section 3" | |
# Set its destination | |
subPbe3.destination = C | |
# Add the object to the main PDF root object | |
pbeRoot.sub_entry.append(subPbe3) | |
# Create an instance of PdfSaveOptions | |
pdfSaveOptions = PdfSaveOptions() | |
# Set the PDF Bookmark root object | |
pdfSaveOptions.bookmark = pbeRoot | |
dataDir = dataDir + "PDFBookmarks_test.out.pdf" | |
# Save the pdf file | |
workbook.save(dataDir, pdfSaveOptions) |