在新标签页中打开PDF

Luk*_*101 0 c# google-chrome servicestack angularjs internet-explorer-11

我需要使用servicestack在新窗口中打开PDF.我有一个PDF的MemoryStream,能够将PDF下载到浏览器.我的问题是我无法想出如何在新标签中打开PDF.我已经使用此代码从服务堆栈下载pdf.

public class PDfResult : IDisposable, IStreamWriter, IHasOptions
{
    private readonly Stream _responsestream = null;
    public IDictionary<string, string> Options { get; set; }

    public PDfResult(Stream responseStream)
    {
        _responsestream = responseStream;
        Options = new Dictionary<string, string>
        {
            {"Content-Type", "application/pdf"},
            {"Content-Disposition", "attachment; filename=\"mypdf.pdf\";"}
        };
    }

    public void WriteTo(Stream responseStream)
    {
        if (_responsestream == null)
            return;

        _responsestream.WriteTo(responseStream);
        responseStream.Flush();
    }

    public void Dispose()
    {
        _responsestream.Dispose();
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我使用的锚标签:

<a class="btn" href="api/myapi?rosType=blank&amp;rId=0&amp;rType=Daily&amp;Pages=1&amp;Weeks=1" target="_blank">Generate PDF</a>
Run Code Online (Sandbox Code Playgroud)

Man*_*iya 5

您正在使用内容处置作为附件.把它改成像这样的内联

    Options = new Dictionary<string, string>
    {
        {"Content-Type", "application/pdf"},
        {"Content-Disposition", "inline; filename=\"mypdf.pdf\";"}
    };
Run Code Online (Sandbox Code Playgroud)

这将在浏览器窗口中打开pdf文件.但请注意,您的浏览器必须具有可以打开pdf文件的插件.