PyFPDF internal link

Question:

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 import 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')
Asked By: ArtDijk

||

Answers:

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.

Answered By: Martin
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.