如何将PDF转换为内存流 [英] How to convert a pdf to a memory stream

查看:743
本文介绍了如何将PDF转换为内存流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在MVC4的应用程序。

I am writing an application in MVC4.

我在服务器上的物理pdf文件。我想将其转换为一个内存流并寄回给用户,像这样

I have a physical pdf file on the server. I want to convert this to a memory stream and send it back to the user like so

返回文件(流应用程序/ PDF格式,myPDF.pdf);

return File(stream, "application/pdf", "myPDF.pdf");

但我怎么转换PDF文件到内存流?

but how do I convert a pdf file to a memory stream?

感谢

推荐答案

您不必的MemoryStream 。最简单的方法是使用过载接受的文件名:

You don't need MemoryStream. Easiest way is to use overload that accepts file name:

return File(@"C:\MyFile.pdf", "application/pdf");

另一种解决方案是使用重载,接受字节[]

return File(System.IO.File.ReadAllBytes(@"C:\Myfile.pdf"), "application/pdf");

如果你想使用的FileStream

return File(new FileStream(@"C:\MyFile.pdf", FileMode.Open, FileAccess.Read), "application/pdf");

这篇关于如何将PDF转换为内存流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆