How to Stop a PDF from Automatically Printing on Open (Remove JavaScript)
Question details
The user needs to prevent a PDF document from automatically triggering the print dialog as soon as the file is opened.

- Product
- Device & OS
- not provided
- Scenario
- Opening a downloaded or received PDF document using a PDF reader or editor.
- Observed behavior
- The PDF automatically initiates the print process or opens the print dialog because of a document-level JavaScript action calling the print method.
Ensure you trust the source of the PDF before interacting with it, as malicious embedded scripts can pose security risks to your device. You may want to disable JavaScript globally in your PDF viewer before investigating.
Remove Document-Level JavaScript in Acrobat
Use advanced PDF editing tools to inspect the document's scripts and delete the code that forces the automatic print dialog.
Authors sometimes embed a script (like this.print();) to ensure users immediately print a form or ticket. Removing this specific script stops the forced behavior without altering the rest of the document's content.
Open your PDF file in Adobe Acrobat. Navigate to the 'Tools' menu, scroll down to the 'Customize' or 'Action Wizard' section, and select 'JavaScript'.
Click on 'Document JavaScripts' in the toolbar. This will open a dialog box listing all scripts embedded at the document level.
Review the listed scripts for commands such as 'this.print();'. Highlight the script causing the issue and click the 'Delete' button to remove it.
Go to 'File' > 'Save As' to save a new copy of your PDF. Reopen the newly saved file to verify that the automatic printing behavior has completely stopped.

Flatten the PDF by Printing to PDF
Create a completely clean, script-free version of the document by 'printing' it as a new PDF file.
View and Manage PDFs Safely with WPS Office
WPS Office provides a comprehensive and secure PDF reader and editor. It allows you to safely view documents, strip out unwanted embedded scripts by flattening files, and easily manage your PDF tasks without unexpected interruptions.
- 1. Download WPS Office: Visit the official WPS website and download the free WPS Office suite, which includes a powerful PDF toolkit.
- 2. Open the PDF Securely: Launch WPS PDF and open your document. The secure environment helps you manage files without unwanted script executions.
- 3. Flatten and Save: To permanently remove the auto-print script, go to Menu > Print, select 'WPS PDF' as your printer, and save it as a fresh, clean document.
- 4. Edit Your New File: Use WPS PDF's built-in editing tools to add text, highlight content, or merge pages as needed.

Frequently Asked Questions
Why would an author add an auto-print JavaScript to a PDF?
Authors often embed 'this.print();' scripts in documents like event tickets, shipping labels, or official forms to ensure the user immediately prints the document upon opening, streamlining the process.
Is it dangerous to open a PDF with embedded JavaScript?
While auto-print scripts are generally harmless, embedded JavaScript can be used maliciously to execute harmful code on your device. It is recommended to only open interactive PDFs from trusted sources and keep your PDF reader updated.
Can I permanently disable JavaScript in my PDF reader?
Yes. Most major PDF readers, including Adobe Acrobat, allow you to turn off JavaScript globally. In Acrobat, you can do this by going to Edit > Preferences > JavaScript, and unchecking 'Enable Acrobat JavaScript'.
Will removing the JavaScript affect the rest of the PDF?
If you only remove the specific print command (like this.print();), the visual content of the PDF will remain entirely unchanged. However, if you flatten the PDF to remove it, other interactive elements like fillable form fields will also be removed.




