Guide · Updated 18 November 2026

Can a PDF have a virus?

A PDF looks like a printed page, but it can carry more than text and pictures: scripts that run when it opens, other files packed inside it, and links. Office files can carry macros. Most attachments are harmless, so it helps to know which signs deserve a second look.

Short answer

Yes. A PDF can contain JavaScript, other files attached inside it and links to websites, and attackers use these to deliver malware or send you to a fake login page. Word, Excel and PowerPoint files can carry macros, small programs that run inside Office. Keep your PDF reader and Office updated, be wary of unexpected attachments, and look inside a file before you open it. A file check is not antivirus, though, and a clean result doesn't prove a file is safe.

Can PDF files contain viruses?

Yes. A PDF can hold more than the pages you see:

  • JavaScript, which PDF readers can run for things like form calculations, and which attackers can misuse
  • other files attached inside the PDF, such as a document, a ZIP or a program
  • links and buttons that open a website, often a fake login page
  • actions that run when the file opens

Security people usually call this PDF malware rather than a virus, but the worry is the same.

Can you get a virus from opening a PDF?

It's possible, but most attacks need help from somewhere else: an out-of-date PDF reader with a known flaw, or you clicking a link, opening an attached file or allowing a script. That's why CISA, the US cybersecurity agency, starts its tips on email attachments with two habits: confirm unexpected attachments with the sender, and keep your software updated.

PDFs are also the most common phishing attachment. Hoxhunt, a company that trains staff to spot phishing, says PDFs made up 23.7% of attachment-based phishing reported to it in the first half of 2025.

Can Word, Excel and PowerPoint files have viruses?

Yes, and macros are the classic way in. A macro is a small program saved inside an Office file. Files ending in .docm, .xlsm and .pptm are made to hold them, and older .doc, .xls and .ppt files can too.

Microsoft changed the default in 2022. Office on Windows now blocks macros in files from the internet and shows a "Security Risk" banner with no button to enable them. Phishing emails often try to talk you around this with steps to unblock the file. If an attachment comes with instructions for turning off a security warning, that's the warning sign.

Office files can also link to things outside the file: other workbooks, pictures loaded from a website, or files on someone's computer. These are usually innocent, but a link you didn't expect is worth a look.

What to look for before you open an attachment

Sign Why it matters
You weren't expecting it Most attacks arrive as a surprise "invoice", "voicemail" or "document to sign"
The PDF contains JavaScript Rare in ordinary documents outside forms
The PDF has files attached inside it A PDF that carries a program or ZIP has no innocent reason to
A macro-enabled Office file (.docm, .xlsm, .pptm) Can run code once macros are on
It asks you to enable content, unblock or log in The attack needs your help
A QR code or "view document" link instead of content Takes you to a website, often a fake login page

How to look inside a PDF or Office file first

  1. Drop the file into our metadata checker. It reads the file in your browser without opening it in Word or Acrobat, and nothing is uploaded. For PDFs it flags JavaScript and files attached inside. For Office files it lists embedded files, links to other workbooks and links to files on the author's computer.
  2. For a closer look at a PDF, the PDF metadata remover shows the names of attached files and can remove them along with other hidden content.
  3. If something looks off, confirm with the sender through another channel, such as a phone call, before you open the file in your usual app.

A file that hides text for AI tools is another warning sign; see hidden AI prompts in files.

What a file check can't tell you

Whether the file is safe. Our checker isn't antivirus. It doesn't compare files with known malware, it doesn't run them, and it can't see inside password-protected or encrypted parts. A file with no scripts or attachments can still lead you to a fake website, and a scammer can send a perfectly clean PDF with a fake bank number on it, as covered in how to spot a fake invoice.

So use it to decide whether to look closer, and keep the basics on: an updated PDF reader and Office, your email provider's attachment scanning, and antivirus software. This guide is general information, not security advice.

FAQ

Questions, answered

Can a PDF contain malware?

Yes. A PDF can carry scripts, attached files and links that lead to malware or a fake login page. Opening one usually only causes harm through a flaw in an out-of-date PDF reader. More often, a dangerous PDF asks you to do something: click a link, open an attached file or allow a script. Keeping your reader updated closes most of the known holes.

Is it safe to open a PDF in the browser?

Browsers keep their built-in PDF viewers updated along with the browser, which helps. But a PDF can still show you a link to a fake login page or a QR code, and no viewer protects you from typing your password into the wrong site.

Can a Word document have a virus?

Yes, mainly through macros. Files ending in .docm, .xlsm or .pptm are made to hold macros, and older .doc and .xls files can too. On Windows, Office now blocks macros in files from the internet by default, so don't unblock a file because an email tells you to.

Does WhatsInMyFile scan for viruses?

No. Our checker shows what's inside a file, like scripts, attached files and links, but it doesn't compare files with known malware or tell you a file is safe. For that, use antivirus software and your email provider's protection.

What should I do if I opened a suspicious attachment?

Disconnect from the internet if something odd is happening, run a full antivirus scan, and change any password you typed after opening it, from another device. At work, tell your IT team right away; they'd much rather hear early.