securityprivacyPDF format

Can a PDF Contain a Virus? How Malicious PDFs Actually Work

CT

CasperPDF Team

CasperPDF

October 13, 2026·8 min read

The Short Answer

Yes, a PDF can be malicious. But for most people today, the danger usually isn't a hidden virus that infects your computer the moment you open the file. It's a perfectly ordinary-looking document designed to trick you into clicking a link, scanning a QR code, or typing a password somewhere you shouldn't.

Both threats are real, and they need different defences. Understanding which one you're facing is most of the battle.

PDFs are trusted. Invoices, contracts, delivery notices and HR documents all arrive as PDFs, so one more rarely raises suspicion. They also open on every device, and email filters tend to treat them as low-risk documents rather than programs.

Attackers know this. Security vendors consistently rank PDFs among the most common malicious email attachments, at around one in five in recent industry reports. And the same reports point to a clear shift: most malicious PDFs no longer try to exploit your software at all. They carry phishing links or QR codes instead.

How a PDF Can Do More Than Display Text

A PDF isn't just a picture of a page. The format supports a surprising amount of active behaviour, and each feature is a potential attack path:

  • JavaScript. PDFs can contain scripts, originally intended for things like form validation and calculations. A script can be set to run automatically when the document opens, through an entry called OpenAction.
  • Launch actions. A PDF can ask the viewer to open another file or program. In 2010, security researcher Didier Stevens showed a PDF could use this to run an executable embedded inside itself. Adobe responded by fixing the warning dialog and later disabling the feature by default.
  • Embedded files. A PDF can carry attachments, including executables or Office documents with macros, which a script or a convincing message then tries to get you to open.
  • Links and forms. Clickable links and form fields can send you, or the data you type, to an attacker's website.

None of these features is malicious on its own. The risk comes from what a viewer allows them to do, and how up to date that viewer is.

The Two Kinds of Malicious PDF

1. Exploit PDFs: attacking the software

These target a bug in your PDF reader. A specially crafted file triggers a flaw in how the reader parses fonts, images or scripts, and that flaw lets the attacker run code on your machine. When it works, simply opening the file can be enough.

This happens even to well-built viewers. In 2024, a bug catalogued as CVE-2024-4367 in PDF.js, the PDF engine built into Firefox and used by many websites, let a crafted font in a PDF run JavaScript in the viewer. It was fixed quickly, but anyone using an outdated version stayed exposed. At the extreme end, the 2021 "FORCEDENTRY" spyware attack on iPhones used a file disguised as an image that was actually a PDF, exploiting the image decoder without the victim tapping anything.

The good news: exploits depend on unpatched software. Once a flaw is public, it's usually fixed within days, so these attacks overwhelmingly succeed against people who don't update.

2. Phishing PDFs: attacking you

These contain no exploit at all. The PDF is a lure, often an "invoice", a "voicemail", a "document shared with you" or a "contract awaiting signature", with a button or QR code that leads to a fake login page.

They're effective precisely because there's nothing technically wrong with the file. Antivirus has nothing to detect, and the document opens safely in any viewer. The attack only works if you follow the link and enter your details.

QR codes deserve a special mention. Scanning one moves you from a protected work computer to your phone, where links are harder to inspect and corporate security tools often aren't watching. That's exactly why attackers like them.

Warning Signs of a Malicious PDF

You can't spot an exploit by looking, but most phishing PDFs give themselves away:

  • It came unexpectedly, or from a sender you don't usually deal with, even if the name looks familiar.
  • It's mostly a button. A "document" whose main content is "Click to view", "Review document" or a QR code is a lure, not a document.
  • It asks you to log in. A genuine PDF never needs you to sign in to read what's already inside it.
  • It's password-protected, with the password in the email. Attackers do this deliberately. An encrypted file can't be scanned by email filters, so encryption here is a red flag rather than a sign of security. (We explain what PDF passwords actually protect in PDF encryption explained.)
  • It invokes signatures or urgency. Fake "please sign" requests are among the most common lures. If you're expecting a real signing request, go to the service directly rather than through the PDF's link. Our guide to whether it's safe to sign documents online covers what legitimate signing looks like.
  • Your viewer warns you. A prompt asking to run a script, open a file or launch a program should almost always be declined.

How to Stay Safe

The protections that matter are simple:

Keep your viewer and browser updated. This single habit defeats most exploit PDFs, because they target known, already-patched bugs. Turn on automatic updates for your browser and any desktop PDF reader.

Prefer a browser to open unknown PDFs. Modern browsers open PDFs inside the same security sandbox they use for websites, support only a limited set of PDF scripting, and don't launch external programs. Browser viewers can still have bugs, as CVE-2024-4367 showed, but a sandboxed and auto-updating viewer is a much smaller target than an outdated desktop reader.

Turn off JavaScript in desktop readers if you don't need it. In Adobe Acrobat and Reader it's under Preferences → JavaScript. Most people never use PDF scripting, and disabling it blocks a large share of exploit techniques.

Never follow a PDF's link to sign in. Type the website address yourself, or use a bookmark. This one rule defeats nearly every phishing PDF.

Be careful with QR codes in documents. Before visiting a scanned link, check the address your phone shows you. If a document only "works" by scanning a code, treat it as suspicious.

Think before uploading a suspicious file to an online scanner. Malware-scanning services are useful, but some share submitted files with security researchers and paying customers. That's fine for an obvious junk attachment, but not for a confidential contract that just might be malicious. The trade-off is the same one we describe in the hidden risks of uploading PDFs to online tools.

When in doubt, convert it to images. Re-rendering each page as a flat image keeps how the document looks while discarding scripts, actions, links and attachments. Security teams use the same idea, called content disarm and reconstruction, to neutralise risky documents. The trade-off is that the result has no selectable text.

Frequently Asked Questions

Can you get a virus just by opening a PDF?

It's possible, but only if the PDF exploits an unpatched bug in your viewer. With an up-to-date browser or reader, simply opening a PDF is very unlikely to infect you. The far more common danger is a phishing PDF that tricks you into clicking a link or entering a password.

Are PDFs safer to open in a browser than in Adobe Reader?

Generally, yes, especially for files you weren't expecting. Browsers open PDFs in a sandbox, update automatically, and support far fewer of the active features exploits rely on. An up-to-date desktop reader with JavaScript turned off is also reasonably safe; the real risk is an outdated one.

Does a password-protected PDF mean it's safe?

No. A password only controls who can open the file. Attackers often encrypt malicious PDFs specifically so email filters can't scan them, then put the password in the message. An unexpected encrypted PDF with the password next to it deserves more suspicion, not less.

The Bottom Line

A PDF can be dangerous, but the threat has changed shape. Exploits that infect you on opening still exist, but they rely on outdated software, and keeping your browser and reader updated shuts most of them down. Today's most common malicious PDF is simply a convincing lure with a link or QR code, and the defence there is a habit, not a tool: never sign in through a document, treat unexpected "click to view" files with suspicion, and when something feels off, go to the source directly.

Related Posts