损坏的PDF文件将文件写入响应时

时间:2015-03-23 19:59:29

标签: c# asp.net pdf

所以我的服务器上有一个PDF文件,我可以打开它看起来很好。

我想要实现的是将非托管delphi DLL中的PDF加载到ASP.NET中的UnmanagedStream

然后我尝试使用此代码提供文件!

        UnmanagedMemoryStream memoryStream;

        ReportDLL.getStream(out streamPointer, out bufferSize, true);        
        memoryStream = new UnmanagedMemoryStream((Byte*)streamPointer, bufferSize);
        BinaryReader reader = new BinaryReader(memoryStream);

        HttpResponse response = HttpContext.Current.Response;
        response.Clear();
        response.ContentType = "application/pdf";
        response.AddHeader("Content-Disposition", "attachment; filename=Test.pdf");
        response.OutputStream.Write(reader.ReadBytes(bufferSize), 0, bufferSize);

        // End the response to prevent further work by the page processor.
        response.End()

0 个答案:

没有答案