【问题标题】:Writing PDF content on response stream in openrasta在 openrasta 中的响应流上写入 PDF 内容
【发布时间】:2011-12-14 07:07:03
【问题描述】:

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

提前致谢

【问题讨论】:

    标签: pdf rest openrasta


    【解决方案1】:

    您可以使用 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();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-15
      • 1970-01-01
      • 2016-07-29
      • 2016-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多