What I’m trying to do: My app creates a Word document using the docx package. I’m able to download the document to the browser. However, I would rather view the document on my app rather than download it. I found how to make a pdf viewer, but I need to find a way to do this with a Word document. Any help would be appreciated.
Anything you do on the client is being done in the browser, either through native browser capabilities, or through Javascript. Anvil doesn’t support viewing Word docs, so they haven’t already done the work for you. You’d have to find some Javascript library that allowed you to do so.
Some cursory Google searches showed a variety of approaches, from using an iframe to embed the Google Docs viewer, to using Javascript to convert the Word doc to HTML, to converting the Word doc to PDF and using that in the browser.
That last approach seems to be the most recommended one if you are already processing the Word doc on the server.
Here’s a link to a library that supposedly converts a .docx file to HTML if you want to try that route: Javascript Word viewer
And another: https://viewerjs.org/
An approach my school uses is to convert files to PDF via Google’s Drive API and then show those in an iframe. This isn’t in Anvil but in our learning management system. But all those pieces are in Anvil and could be put together.