Skip to main content

Can a PDF Have a Virus? How to Spot and Remove Hidden Threats

By the PDFCharger team · · 5 min read

PDFs feel safe. They're "just documents", you can't edit them easily, and everyone sends them. That's exactly why attackers like them. So can a PDF have a virus? Yes, it can. But a PDF doesn't infect your computer just by sitting in your Downloads folder, and most dangerous PDFs work in a handful of predictable ways. Once you know them, they're much easier to avoid.

How a PDF can be dangerous

A PDF isn't a program, but the format can hold a lot more than text and pictures. These are the features attackers misuse:

1. Hidden scripts

PDFs can contain JavaScript. It's meant for things like calculating totals in a form, but scripts can also try to exploit bugs in the PDF reader to run harmful code on your computer. This is the closest thing to a classic "PDF virus", and it mainly works against outdated readers.

2. Actions that run automatically

A PDF can include an open action: something that happens the moment the file opens, like running a script, opening a web page or launching another file. Pages can have their own automatic actions too. Most of the time they're harmless, but they're also how an attack starts without you clicking anything.

3. Files hidden inside the PDF

A PDF can carry attachments, just like an email. Attackers hide a malicious program or a macro-enabled document inside, then use the PDF's text to persuade you to open it: "To view the full invoice, open the attached file."

4. Links to fake websites

This is by far the most common trick today. The PDF contains no malware at all, just a convincing page with a button: "View document", "Sign now", "Your payment is waiting". The link leads to a fake login page that steals your password. Because the PDF itself is technically clean, it often gets past email filters.

5. Deliberately broken files

Some PDFs are built with malformed internal structure designed to crash a specific reader in a way that lets the attacker run code. Keeping your software up to date is the main defence here.

Warning signs of a malicious PDF

Be suspicious when:

  • You weren't expecting it, especially an "invoice", "payment notice", "shipping document" or "shared file" from someone you don't know.
  • The message is urgent: "Pay today", "Your account will be closed", "Final notice".
  • The PDF is mostly a button or a link, with little real content.
  • It asks you to "enable content", open an attached file, or log in to see the document.
  • Your reader shows a warning that the file wants to open another file, run a program or connect to a website. Say no unless you're sure.
  • The file name looks odd, such as invoice.pdf.exe or document.pdf.html. The last extension is what the file really is.

How to open PDFs more safely

  • Keep your PDF reader and browser updated. Most PDF attacks rely on old, known bugs.
  • Turn off JavaScript in your desktop PDF reader if you don't fill in interactive forms. Most readers have this in their settings.
  • Open unexpected PDFs in your web browser. Browsers' built-in PDF viewers run in a sandbox and support fewer of the risky features.
  • Hover over links before clicking and check where they really go.
  • Scan files you're unsure about with your antivirus software.
  • When in doubt, contact the sender using a phone number or address you already know, not one from the PDF.

How to remove risky content from a PDF

If you need to keep a PDF or pass it on, for example forwarding a document to colleagues, you can strip out the parts that can do something. PDFCharger's Sanitize PDF does this in your browser, so the file is never uploaded:

  1. Open Sanitize PDF and add the file.
  2. Choose what to remove. Each item has its own checkbox, and all but the last are ticked by default:
    • JavaScript, including scripts that run when the document or a page opens;
    • attachments hidden inside the file;
    • links;
    • interactive form fields, by flattening them into plain content;
    • metadata, such as the author and editing software;
    • comments and other annotations (off by default).
  3. Sanitize and download the cleaned copy. Keep the original in case you need it.

The tool edits the file's structure directly to delete these parts. It doesn't run the scripts in order to remove them.

A few trade-offs to know about:

  • Removing links removes all of them, including useful ones. Untick that option if you trust the links.
  • Flattening forms keeps what's been typed in but means the fields can't be filled in any more.
  • Password-protected PDFs need to be unlocked first. Sanitize PDF can't clean a file it can't read.

For an even deeper clean, the Deep Metadata Sanitizer also removes hidden layers, editing history and leftover data from earlier versions of the file. That's more about privacy than malware, but it's worth running before you publish a document.

What sanitizing can't do

Sanitizing removes the active parts of a PDF. It isn't antivirus software, and it can't make every file safe:

  • It doesn't change what the page says. A phishing PDF that tells you to call a fake support number will still say that after cleaning.
  • It can't fix every malformed file. A PDF built to crash a particular reader might still do so. Updated software is the protection there.
  • It only cleans the PDF. If you've already opened an attachment or entered your password on a fake site, cleaning the PDF afterwards won't undo that. Change your password and run a full antivirus scan.

The short version

  • A PDF can be dangerous through scripts, automatic actions, hidden attachments, phishing links or deliberately broken files.
  • Phishing links are the most common threat, and they don't need any "virus" at all.
  • Keep your reader updated, be wary of unexpected PDFs, and never log in through a link inside one.
  • To clean a PDF before keeping or sharing it, remove its scripts, attachments, links and form fields with Sanitize PDF, right in your browser.

Every step in this guide was checked against the tools on PDFCharger on the date shown above. Found something out of date? Tell us

Also from the Charger family

Need audio tools too?

AudioCharger brings the same free, private, in-browser experience to audio and video — convert, trim, add effects and more.

Try AudioCharger ↗