1

I want to render a pdf in Iframe. So if I do a GET request to http://localhost/pdf/2, it should return PDF content in the response stream. The other way can be redirecting user to full URL of the PDF file which I don't want to do.

Thanks in advance

IsmailS
  • 10,797
  • 21
  • 82
  • 134
prashant
  • 2,181
  • 2
  • 22
  • 37

1 Answers1

0

you can use the InMemoryFile and InMemoryDownloadableFile classes. An example:

private class AttachmentFile : InMemoryDownloadableFile
    {
        public AttachmentFile(byte[] file, string filename, string contenttype)
        {
            OpenStream().Write(file, 0, file.Length);
            this.FileName = filename;
            this.ContentType = new MediaType(contenttype);
        }
    }

    private class InlineFile : InMemoryFile
    {
        public InlineFile(byte[] file, string filename, string contenttype)
        {
            OpenStream().Write(file, 0, file.Length);
            this.FileName = filename;
            this.ContentType = new MediaType(contenttype);
        }
    }

    [HttpOperation(HttpMethod.GET)]
    public object Get(string filename)
    {

            bool inline = false; //server attachments inline or as download 
            try
            {
                inline = Convert.ToBoolean(Params["INLINE"]);
            }
            catch { }

            string contenttype = set contentttype...
            byte[] attachment = read file....

            if (inline)
                return new InlineFile(attachment, filename, contenttype);
            else return new AttachmentFile(attachment, filename, contenttype);   
        }
        else return new OperationResult.Forbidden();
    }
Rob Segerink
  • 106
  • 1
  • 3