Skip to content

Javascript code added via addJS gets executed twice #482

@andrewisplinghoff

Description

@andrewisplinghoff

When using addJS with PyPDF 1.26.0 on Python 3.6.1 to add Javascript logic to a PDF, this Javascript gets executed twice when opening the PDF instead of once. When using the following sample code, the message box gets shown twice when opening the file in Adobe Reader XI on Windows 7 instead of only once as expected:

from PyPDF2 import PdfReader, PdfWriter


def extract(input_pdf, output_pdf, page):
    reader = PdfReader(input_pdf)
    writer = PdfWriter()
    page = reader.pages[page - 1]
    writer.add_page(pdf_page)
    writer.add_js('app.alert("Startup");')
    with open(output_pdf, "wb") as f:
        writer.write(f)

Sample usage:

extract("my_file.pdf", "my_file_withjs.pdf", 1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    is-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions