PDFDEN

Can a PDF Have a Virus?

Updated September 22, 2026

Yes. A PDF can carry malware, but not the way a program does. The danger sits in the extras a PDF is allowed to hold: scripts, attached files and links. You can check a PDF for JavaScript in your browser without opening it in a reader, then sanitize the PDF to remove the active parts.

Show PDF JavaScript: See any JavaScript hidden in a PDF. Free, and your file never leaves your device.

Open Show PDF JavaScript

Steps

  1. Open Show PDF JavaScript and drop in the file. It is read in your browser and never uploaded.

  2. Read the report. Every script is listed with where it is attached, such as "runs when the document opens". Nothing is run.

  3. If anything looks unexpected, open Sanitize PDF and drop in the same file.

  4. Keep JavaScript, embedded files and XFA selected. Tick external links too if you do not trust where the file came from.

  5. Download the sanitized copy and open that one instead of the original.

How a PDF virus works

A PDF is a document format, not a program, so it cannot run on its own. It needs a reader, and the risk depends on what that reader agrees to do.

Malicious PDFs usually use one of four routes. JavaScript can run when the file opens or when you click something. Embedded files can hide a program or a macro document inside the PDF. Links and launch actions can send you to a phishing page or ask the reader to open another file. The fourth is a crafted font or image that attacks a bug in an old or unpatched reader.

How to check if a PDF is safe

Start with where it came from. An unexpected invoice or delivery notice from someone you do not know is the classic lure.

Then look inside without opening it in a desktop reader. Show PDF JavaScript lists every script in the file and where it is attached. Ordinary documents rarely need scripts. Fillable forms sometimes use small ones to check fields or add up totals, which is normal.

Check for attachments as well. PDF Attachments lists any files stored inside the PDF, so you can see an attached program before anything opens it.

Show PDF JavaScript: See any JavaScript hidden in a PDF. Free, and your file never leaves your device.

Open Show PDF JavaScript

How to remove JavaScript from a PDF

Sanitize PDF removes JavaScript and auto-run actions, embedded files and media, XFA form data and metadata. You choose which. It can also remove external links. The visible pages stay the same, so the cleaned copy reads exactly like the original.

To strip comments, highlights and other markup as well, run the file through Remove Annotations. It keeps links and form fields unless you turn that off.

What sanitizing does not do

Sanitizing is not a virus scan. It removes the parts of a PDF that can act. It does not inspect fonts and images for crafted data aimed at a reader bug.

The best defence against that kind of attack is an up-to-date reader. Browser PDF viewers run inside the browser sandbox and support only a small part of PDF scripting, which makes them a safer place to open a file you are unsure about. For files you really do not trust, an antivirus scan is still worth running.

Frequently asked questions

Can a PDF file contain a virus?

Yes. A PDF can carry malicious JavaScript, an attached program, or data crafted to attack a bug in a PDF reader. It needs a reader to do anything, so an up-to-date reader lowers the risk a lot.

Can you get a virus just by opening a PDF?

It is possible with an outdated reader or one that runs scripts freely. Keep your reader updated, and open doubtful files in a browser viewer, which runs inside the browser sandbox.

How do I check a PDF for JavaScript?

Drop it into Show PDF JavaScript. It lists every script and where it is attached, without running any of them, and the file stays on your device.

How do I remove JavaScript from a PDF?

Use Sanitize PDF with the JavaScript option selected. It removes document scripts, auto-run actions and launch actions, and saves a clean copy.

Is a sanitized PDF guaranteed safe?

No. Sanitizing removes scripts, attachments and other active content, but it is not an antivirus scan and does not check fonts or images for exploit data. Use it alongside an updated reader.

Do I have to upload the PDF to check it?

No. Both tools run in your browser. The file is read on your device and never sent to a server.

Tools for this job

Related guides