Skip to content

JS Executing Twice #1425

@hassan-righthand

Description

@hassan-righthand

Hi

I'm attempting to insert JS that opens the URL whenever the user opens the PDF. Whatever JS I add, it executes it twice. In my scenario, Adobe Acrobat is alerting me about security twice because the same JS was executed twice.

Environment

Plaform: Linux-4.15.0-108-generic-x86_64-with-Ubuntu-18.04-bionic
PyPDF2 Version: 1.26.0
Python : 3.6.9

Code + PDF

from PyPDF2 import PdfFileWriter, PdfFileReader

output = PdfFileWriter()
ipdf = PdfFileReader(open('test.pdf', 'rb'))

for i in range(ipdf.getNumPages()):
	page = ipdf.getPage(i)
	output.addPage(page)

with open('updated_pdf.pdf', 'wb') as f:
	output.addJS('app.launchURL("https://google.com/", true);')
	output.write(f)

test.pdf
updated_pdf.pdf

Todo:

JS should be executed only once

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions