【问题标题】:Save PDF stream into folder将 PDF 流保存到文件夹中
【发布时间】:2014-03-04 18:05:30
【问题描述】:

我正在创建一个 Stream,我可以将其下载为 PDF 文件,也可以将其作为 Filestream 返回为 PDF 格式。

但我想将此流保存到 PDF 文件格式的文件夹中。

我正在使用一些代码将流创建为::

public void PrintInvoice(long ID)
        {

            ReportDocument rd = new ReportDocument();
            rd.Load(AppDomain.CurrentDomain.BaseDirectory+(@"\Reports\InvoiceDocument.rpt"));
            Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            stream.Seek(0, SeekOrigin.Begin);
            return File(stream, "application/pdf", "TestCrystal.pdf");     
        }

如何将形成的流保存到文件夹中为 PDF 文件格式? 我想在客户端机器上保存 PDF 文件。

【问题讨论】:

  • 在服务器上?还是在客户端机器上?如果您的意图是在客户端计算机上,那么忘记它,它无法完成。如果它在服务器上,请告诉我。
  • 我想将 PDF 文件保存在客户端机器上。

标签: c# asp.net-mvc stream pdf-generation filestream


【解决方案1】:

在服务器上保存文件 -

using (MemoryStream ms = new MemoryStream())
{
     stream.CopyTo(ms);
     System.IO.File.WriteAllBytes(Server.MapPath("~/Report1.pdf"), ms.ToArray());
}

在客户端保存文件 -

选项1 - Using ActiveX, you Save file on Client machine without user interaction

选项2 - Using Silverlight, you can put the file in IsolatedStorage available on client machine

很遗憾,由于安全问题,您无法使用 JQuery/JavaScript 保存文件。还有许多其他选项,例如 Java Applets 等。

我不明白您为什么要从服务器端将文件保存在客户端计算机上。让用户承担这个责任,我的意思是让用户单击一个链接并从服务器获取文件并将其保存在他感兴趣的位置。如果服务器尝试在客户端计算机上保存/访问文件,您不认为这是安全问题。因此,我建议您重新考虑您的实施并提出不同的工作流程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-15
    • 2013-05-15
    • 2022-06-29
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    相关资源
    最近更新 更多