How to Batch Remove Executable Code from PDF Files
Question details
The user needs to find a way to inspect multiple PDF files and remove potentially harmful executable content, such as JavaScript and embedded files, in a batch process.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Securing multiple PDF documents before distribution or archiving by stripping out embedded scripts and interactive executable elements.
- Observed behavior
- PDF files often contain hidden JavaScript or embedded files that pose security risks and require automated removal across multiple files simultaneously.
Create a dedicated backup folder and copy all your original PDF files into it before applying any batch optimization or preflight profiles, ensuring no original data is accidentally lost.
Use Adobe Acrobat Action Wizard and Preflight Fixups
This is the most efficient method to handle batch processing. By creating a custom Preflight fixup and applying it via the Action Wizard, you can strip executable code from hundreds of PDFs automatically.
Acrobat's Preflight tool is designed for advanced PDF inspection and correction. You can create a specific fixup profile that targets and removes JavaScript, form actions, and embedded files.
Open Adobe Acrobat, navigate to Tools > Print Production > Preflight. Click the 'Options' menu, select 'Create New Preflight Profile', and add fixups specifically for 'Remove JavaScript' and 'Remove embedded files'.
Go back to the Tools menu and select 'Action Wizard'. Click 'New Action' to start configuring your batch process.
In the Action Wizard configuration window, under 'Files to be Processed', click 'Add Folder' and select the directory containing the PDFs you want to clean.
Under 'Choose tools to add', navigate to 'Document Processing' > 'Preflight'. Click the '+' button to add it to the action steps. Uncheck 'Prompt user' and select your newly created custom Preflight profile.
Save the Action with a recognizable name (e.g., 'Remove Executable Code'). Click on the action in the Action Wizard list and press 'Start' to process all files in the selected folder.

Use PDF Optimizer via Save As Other
If you prefer a simpler interface than Preflight, the PDF Optimizer allows you to discard user data and executable actions, which can also be applied in batch using the Action Wizard.
Secure and Manage Your PDFs with WPS Office
If you need a fast and straightforward way to handle PDF security, convert interactive files, or manage document access, WPS Office offers a comprehensive suite of PDF tools that simplify the process without the complexity of advanced preflight software.
- 1. Launch WPS Office: Open the WPS Office application and click on the 'PDF' tab from the home screen.
- 2. Open Your Document: Select and open the PDF file you wish to secure or flatten.
- 3. Navigate to the Protect Tab: Click on the 'Protect' or 'Tools' tab in the top ribbon to access document security features.
- 4. Flatten or Export to PDF: Choose the 'Print' function and select 'Print to PDF' (or use the Flatten feature) to strip out background scripts and interactive embedded elements.
- 5. Save the Secured File: Choose your destination folder and save the newly flattened, secure PDF document.

Frequently Asked Questions
Why do PDF files contain executable code like JavaScript?
PDFs support JavaScript to enable interactive features such as automated form field calculations, dynamic data validation, and multimedia playback. While useful for interactive forms, this feature can also be exploited to execute malicious scripts.
Does flattening a PDF remove JavaScript and executable code?
Yes, flattening a PDF converts all interactive elements, including forms, annotations, and underlying scripts, into standard visual text and images. This process effectively neutralizes and removes hidden executable code.
Will removing embedded files change how the main PDF looks?
No. Embedded files are essentially attachments stored within the PDF container. Removing them strips the attachments but leaves the visual layout, text, and graphics of the primary document completely unaffected.
Can I check if a PDF has JavaScript before batch processing?
Yes, you can manually inspect a PDF by going to Acrobat's Tools > JavaScript > Document JavaScripts. This will list all the scripts embedded at the document level. Preflight can also be run in 'Analyze' mode to detect JavaScript without making changes.




