I’m currently using an html embed tag to display a pdf file that is saved on the local server. Is there a wayo to display a pdf file on my page without having to save it to the local file system of the server? I just wand to pass it to the view from the controller in such a way that it can be displayed as a pdf in the page without having it stored on the file system directly.
Alternatively, is there a way to call a method to delete the pdf file from the server once the user has navigated away from the page they are viewing? How do I tell if th euser has navicated away from the page and how do i cause that to trigger a method that will delete the file?
I created a MVC class called
PdfResultthat returns a byte array as a PDF file.The purpose is as follows (can’t upload the source code, sorry):
PdfResultinherits fromFileStreamResultContent-Typeheader toapplication/pdfContent-Dispositionto eitherattachmentorinline, and set an appropriate file nameStream— if your data is a byte array, then write it to aMemoryStream.See https://stackoverflow.com/a/16673120/272072 for a good example of how to do this.
Then, your embed code just needs to point to the action method, as if it was a PDF file.
Here’s an example: