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

JS Executing Twice #1425

Closed
hassan-righthand opened this issue Nov 7, 2022 · 2 comments · Fixed by #1439
Closed

JS Executing Twice #1425

hassan-righthand opened this issue Nov 7, 2022 · 2 comments · Fixed by #1439

Comments

@hassan-righthand
Copy link

hassan-righthand commented Nov 7, 2022

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

@pubpub-zz
Copy link
Collaborator

@hassan-righthand
I'm a little confused about your results : your results seems to show that the results are using a patched version of PyPDF2 1.26
can you provide the pdf.py file you are using.

@pubpub-zz
Copy link
Collaborator

After further test I may have found the issue.
With the latest version the scripts does not seem to be executed. Root cause had been identified.
Work in progress

pubpub-zz added a commit to pubpub-zz/pypdf that referenced this issue Nov 13, 2022
fixes py-pdf#1425 and py-pdf#482

Also Introduces a new API opening in order to open a doc on a page or destination
pubpub-zz added a commit to pubpub-zz/pypdf that referenced this issue Nov 20, 2022
MartinThoma pushed a commit that referenced this issue Nov 20, 2022
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

Successfully merging a pull request may close this issue.

2 participants