问题
How should internal linking be done? I try to link from page 1 to page 2. That works ok. But from page to page 2 doesn't work. What is wrong.
from fpdf inport FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_font('Arial', 'B', 16)
to_page_2 = pdf.add_link()
pdf.cell(40, 10, 'Page 1', border=1, ln=0, align='', fill=False, link=to_page_2)
pdf.add_page()
pdf.set_font('Arial', 'B', 16)
pdf.set_link(to_page_2)
pdf.cell(40, 10, 'Page 2', border=1, ln=0, align='', fill=False)
pdf.add_page()
pdf.set_font('Arial', 'B', 16)
to_page_2 = pdf.add_link()
pdf.cell(40, 10, 'Page 3', border=1, ln=0, align='', fill=False, link=to_page_2)
pdf.output('pdf_link.pdf', 'F')
回答1:
You have not set the destination of second link. set_link
defines the page and position a link points to.
Add this line before you link the cell on page 3.
pdf.set_link(to_page_2, page=2)
In case you need more info on parameters you can pass to set_link
check out the the documentation.
来源:https://stackoverflow.com/questions/49031121/pyfpdf-internal-link