You would need to pull in the PDF or Doc file into a server module, where you could then parse it with a library. Here is a link to the list of packages available on the server modules. https://anvil.works/docs/server/packages
If a package you need is missing you can request it to be installed. Note: not all packages are available on the free tier.
For PDF’s PyPDF2 is available. You can find the PyPI page here. For Doc files I don’t know but I’m sure there are numerous packages out there if one is not already installed.