PyFPDF internal link

狂风中的少年 提交于 2021-02-05 07:56:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!