在MVC应用程序中使用PDF文件 [英] use PDF file in MVC application

查看:95
本文介绍了在MVC应用程序中使用PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将PDF,任何文档文件作为二进制格式上传到数据库

并在我的MVC应用程序中将其查看到浏览器中



请帮助我任何想法或任何代码提供给我



哪里文件文件将从二进制转换为html视图页

I want to upload PDF, any document file as a binary format to database
and view it into a browser in my MVC application

Please help me any Ideas or any code provide me

Where document file will convert from binary to html view page

推荐答案

您希望编写一个HTTP处理程序来处理包含该对象的DB id的请求,并使用正确的标头返回该对象的字节。这已经在整个网络上被广泛报道,我确信这个网站上会有文章。你看了吗?
You want to write a HTTP Handler that handles requests that contain the DB id of the object, and returns the bytes of the object, with the right header. This has been covered ad nauseum all over the web, I am certain this site will have articles on it. Did you look ?


你可以将pdf文件转换成字节数组通过以下代码



Your can convert pdf file in to byte array By following code

byte[] array = new byte[file.ContentLength];
file.InputStream.Read(array, 0, array.Length);





通过以下代码,您可以重新检查文件





By following code you can recheck the file

System.IO.File.WriteAllBytes(@"c:\test.pdf", array);





很容易将字节数组存储到数据库中。

并且还读取字节数组并导出如下...





store the byte array to database easily.
and also read the byte array and export as follows ...

Response.Clear(); 
MemoryStream ms = new MemoryStream(pdfBytearray); 
Response.ContentType = "application/pdf"; 
Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf"); 
Response.Buffer = true; 
ms.WriteTo(Response.OutputStream); 
Response.End(); 







以下是refferance链接



http:// stackoverflow.com/questions/1324597/how-to-render-an-asp-net-mvc-view-in-pdf-format?rq=1 [ ^ ] < br $> b $ b

http://stackoverflow.com/questions/7747796/displaying-pdf-files-in-a-web-page-from-a-sql-database-directly-without-needing [ ^ ]



http://www.c-sharpcorner.com/UploadFile/013102/save-and-read-pdf-file-using-sql- server-and-C-Sharp / [ ^ ]



在c#中将字节数组转换为pdf [ ^ ]




Following is the refferance link

http://stackoverflow.com/questions/1324597/how-to-render-an-asp-net-mvc-view-in-pdf-format?rq=1[^]

http://stackoverflow.com/questions/7747796/displaying-pdf-files-in-a-web-page-from-a-sql-database-directly-without-needing[^]

http://www.c-sharpcorner.com/UploadFile/013102/save-and-read-pdf-file-using-sql-server-and-C-Sharp/[^]

Convert a byte array to pdf in c#[^]


这篇关于在MVC应用程序中使用PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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