Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PageMerge with canvas :: Links are not working #238

Open
epdxb opened this issue May 5, 2023 · 0 comments
Open

PageMerge with canvas :: Links are not working #238

epdxb opened this issue May 5, 2023 · 0 comments

Comments

@epdxb
Copy link

epdxb commented May 5, 2023

When we use PageMerge with canvas, links are not working in output pdf. You can use the attached file and below code to reproduce it. Am I missing some thing here?

link_file.pdf

from pdfrw import PdfReader, PageMerge
from pdfrw.buildxobj import pagexobj
from reportlab.pdfgen import canvas
from pdfrw.toreportlab import makerl
from io import BytesIO
import io
import base64
input_pdf = PdfReader('link_file.pdf')

def conevrt_using_canvas(input_pdf):
    packet = io.BytesIO()
    can = canvas.Canvas(packet) 
    for page_num, page in enumerate(input_pdf.pages, start=0):           
        page = pagexobj(PageMerge().add(input_pdf.pages[page_num]).render())
        width = float(page.BBox[2])
        height = float(page.BBox[3])        
        can.setPageSize((page.BBox[2], page.BBox[3]))
        can.doForm(makerl(can, page))
        can.drawString(70, 750, 'Using Canvas')
        can.showPage()
        can.save()
        rendered_file = base64.b64encode(packet.getvalue())        
        with open('output_link_file.pdf', 'wb') as f:
            decodedData = base64.b64decode((rendered_file))
            f.write(decodedData)
            
conevrt_using_canvas(input_pdf)
@epdxb epdxb changed the title PageMerge with canvas :: Link are not working PageMerge with canvas :: Links are not working May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant