1

我想在 Iframe 中呈现 pdf。因此,如果我向http://localhost/pdf/2发出 GET 请求,它应该在响应流中返回 PDF 内容。另一种方法可以将用户重定向到我不想做的 PDF 文件的完整 URL。

提前致谢

4

1 回答 1

0

您可以使用 InMemoryFile 和 InMemoryDownloadableFile 类。一个例子:

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();
    }
于 2011-12-18T14:14:51.263 回答