本文介绍了在c#中将字节数组转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,





我需要一些帮助才能将字节数组来自DataBase转换为pdf。有人能给我一个C#中的例子吗?以下是我到目前为止使用System.IO的


Dear All,


I need some help in converting a byte array "Which Came From DataBase" to pdf. Could someone give me an example of how in C#? Here is what I have so far,

using System.IO;

string sFile = "c:\testpdf.pdf"; //Path
FileStream fs = File.Create(sFile);
BinaryWriter bw = new BinaryWriter(fs); 







我用这个将Pdf文件转换成字节数组:






And I have Used This To Convert The Pdf File Into Byte Array:

FileUpload1.SaveAs(filePathName);
byte[] picArray= System.IO.File.ReadAllBytes(filePathName);





提前感谢,



thanks in advance,

推荐答案

File.WriteAllBytes(@"C:\testpdf.pdf", myArrayOfBytes);

(您应该知道这可能会失败 - 权限问题通常会阻止写入HDD的根目录 - 请尝试使用子目录)

(You should be aware that this is likely to fail - permissions problems often prevent writes to the root directory of a HDD - try using a subdirectory instead)


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(); 


Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "inline;filename=data.pdf");
Response.BufferOutput = true;
byte[] pdf;
Response.AddHeader("Content-Length", response.Length.ToString());
Response.BinaryWrite(pdf);
Response.End();





您能否看一下这段代码。我从下面给出的链接中得到了它。



[]



希望这会对你有帮助。



Can you please have a look at this code. I got it from the link given below.

http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/6810a67f-66d9-4ce4-87e5-06dbbb754730/[^]

Hope this will help you.


这篇关于在c#中将字节数组转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 00:28
查看更多