Open Pdf In Iframe Passing Byte Data Example
I need to host a api on a server where my pdf files resides. Then i call api from my code by passing the file to get the pdf and then i will display it to the browser.How my api will return a pdf n how i can consume in my app is something on which i struck. (using IFrame) as my requirement was to show pdf in popup. Hope this will help you.
If you're reading the stream using the Read function then chances are you're only reading part of it as streams deliver their data in chunks so what you have written to disc is only part of the file. Either keep using the Read method and appending to the buffer until the entire stream is read or use a method that reads the stream in entirety (if one exists), or one way is to use File.Create to create a stream that writes to the desired file on your disc, then simply use the CopyTo method of the stream that has come back from the webapi to copy it to the stream you got from FileCreate. That will handle all the chunking for you. I have sample code for this but not on me right now, you can use the above to give it a go or google for a solution, and failing that I can dig the code out when I have it in front of me. Your API will return something like return new FileStreamResult(pdfStream, ' application/pdf') where pdfStream is a stream of your PDF, either from a PDF generator that returns the PDF as an in-memory stream, or a stream from a file if it is on the disk. If you want to retrieve the PDF from this api and show it in the browser you need to read the stream, then re-write the stream to the client.
When answering a question please: • Read the question carefully. • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar. • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem.
Insults are not welcome. • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.