Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用PDFsharp将PDF文档保存到Response.OutputStream_C#_Asp.net_Pdfsharp - Fatal编程技术网

C# 使用PDFsharp将PDF文档保存到Response.OutputStream

C# 使用PDFsharp将PDF文档保存到Response.OutputStream,c#,asp.net,pdfsharp,C#,Asp.net,Pdfsharp,我试图将源文件的副本直接保存到响应输出流中。但是,由于这段代码,浏览器窗口的背景是黑色的。如果不使用内存流,我怎么做 public static void CreateCollage(IEnumerable<Stamp> stamps, Stream input) { using (PdfDocument outDoc = new PdfDocument()) using (PdfDocument inputDoc = PdfReader.Open(inpu

我试图将源文件的副本直接保存到响应输出流中。但是,由于这段代码,浏览器窗口的背景是黑色的。如果不使用内存流,我怎么做

public static void CreateCollage(IEnumerable<Stamp> stamps, Stream input)
{

    using (PdfDocument outDoc = new PdfDocument())
        using (PdfDocument inputDoc = PdfReader.Open(input, PdfDocumentOpenMode.Import))
        {
            for (int i = 0; i < inputDoc.PageCount; i++)
            {
                var page = inputDoc.Pages[i];
                var pageOut = outDoc.AddPage(page);

                foreach (var stamp in stamps.Where(s => s.xyp.page == (i + 1)))
                    InsertData(pageOut, stamp, page.Width.Value, page.Height.Value);
            }
            outDoc.Save(context.Response.OutputStream, true);
        }
}
publicstaticvoidcreatecollage(IEnumerable stamps,流输入)
{
使用(PdfDocument outDoc=new PdfDocument())
使用(PdfDocument inputDoc=PdfReader.Open(输入,PdfDocumentOpenMode.Import))
{
对于(int i=0;is.xyp.page==(i+1))中的var stamp)
插入数据(分页、戳记、page.Width.Value、page.Height.Value);
}
outDoc.Save(context.Response.OutputStream,true);
}
}
如果使用Save()函数,则会出现错误:

不支持指定的方法

在System.Web.HttpResponseStream.get_Position()中 在PdfSharp.Pdf.IO.PdfWriter.WriteFileHeader(PdfDocument文档)中
在d:\Users\yudina\Desktop\pdfsharp\pdfsharp\src\pdfsharp\Pdf.IO\PdfWriter.cs中:第488行

您不调用
outDoc.Close()
并且任何内容都不会写入
输出流
,因此,如果没有内存流,我无法实现这一点。调用
Close()
时会发生什么?你试过了吗?您可以创建
MemoryStream
,但仍然必须调用
Close()
Save()
,否则将不会向流中写入任何内容。似乎您必须创建
MemoryStream
,因为
HttpResponseStream
不支持更改流中的位置。好的,谢谢大家:)太糟糕了。。