I know antivirus software (like Kaspersky) can scan executable files for viruses, but can they scan office documents and PDF files for viruses?
- When you download an executable file from the Internet, the antivirus scans it immediately without requiring you to open it.
- Modern antiviruses scan Microsoft Word documents before you open them because of the malicious macros they may embed. Lot of antiviruses behave the same toward PDF files you mentioned for the same reason (Can a PDF file contain a virus?).
- Archived files (
.rar, ...etc) are also scanned automatically without requiring you to open them first as they may contain other malicious executable files.
- Some antiviruses do scan some types of documents (text files for example) only when you try to open them and this approach is called on access scanning.
- An antivirus scans all running programs (including the ones you do not see, background processes)
- When you run a full scan however, all files are scanned without opening them.
Upload a random MS Office/PDF document to, for example, VirusTotal and it will be scanned (freely).
On a basic level, an antivirus engine can scan any file type provided it has the capability to understand the application signature. In the case of Office documents, it has become a standard to scan them for malicious Macros that are used to execute a command compromising the user's machine. The same applies to PDF files which can contain scripts that also infect the machine and make callbacks to remote botnet servers.
AV engines these days scan all but the most obscure file types and some of them can even tell you if a certain file is exploitable (not infected but having a vulnerability that can be exploited by a threat agent). It has become common practice to scan Office documents and PDF files. False positives might arise sometimes though.