Closed pemmadi closed 2 weeks ago
It is mandatory to provide reproducing data when submitting a bug.
@JorjMcKie - file1.pdf & file2.pdf have internal links and they are working as expected but after merge they are not working(merged_ouput.pdf)
Please read the documentation here. You will see that "named" internal links are not supported / ignored. As you do not want to provide an example file 😒, you need to check yourself whether file2.pdf has named internal links.
@JorjMcKie - I am using XSL to read data from XML and creating a ToC with internal links then converting to PDF, below is the code snippet for generating links
<xsl:template name="make-tableofcontents">
<h2>
<a name="toc">Table of Contents</a>
</h2>
<ul>
<xsl:for-each select="n1:component/n1:structuredBody/n1:component/n1:section/n1:title">
<li>
<a href="#{generate-id(.)}">
<xsl:value-of select="."/>
</a>
</li>
</xsl:for-each>
</ul>
</xsl:template>
the generate-id() function in XSLT does not directly create a named destination link. It only generates a unique identifier for an XML node.
Can you help how I can fix this internal links issue, Is there any other way to create links without using named destination?
You can convert named links to GoTo
links using PyMuPDF. This script does work:
import pymupdf
doc1 = pymupdf.open("file1.pdf")
doc2 = pymupdf.open("file2.pdf")
for page in doc2:
links = page.get_links()
for link in links: # replace NAMED by GOTO links
if link["kind"] != pymupdf.LINK_NAMED:
continue
nlink = {
"kind": pymupdf.LINK_GOTO,
"from": link["from"],
"to": link["to"],
"page": link["page"],
"zoom": link["zoom"],
}
page.delete_link(link) # delete named link
page.insert_link(nlink) # insert its GOTO version
page = doc2.reload_page(page) # important: finalize page updates!
doc1.insert_pdf(doc2)
doc1.ez_save("merged.pdf")
@JorjMcKie - Thanks man, its working, really appreciated
Description of the bug
I am trying to merge multiple PDFs into a single PDF using PyMuPDF, the merge works but the internal hyperlinks are broken after the merge.
How to reproduce the bug
PyMuPDF version
1.24.0
Operating system
Windows
Python version
3.8