在 openrasta 的响应流上写入 PDF 内容

发布于 2024-12-21 03:28:49 字数 184 浏览 4 评论 0原文

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

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰ゝ天使的微笑 2024-12-28 03:28:49

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

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();
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文