在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,
您似乎试图将数据库中的字节写入文件:为什么这会给您带来问题?如果您有字节,只需写下它们:
You seem to be trying to write a byte arry from a database into a file: why is this giving you problems? If you have the bytes, just write them:
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();
如果是字节数组,可以将其写入磁盘,以便将其保存为* pdf文件。
或
要么,你可以将字节写入响应输出流,用户将提示下载并保存文件。
If it is a byte array, you can write it to disk so it becomes saved as *pdf file.
or
either, you can write the bytes to the response output stream and user will be prompt to download and save the file.
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();
您能否看一下这段代码。我从下面给出的链接中得到了它。
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/6810a67f-66d9-4ce4-87e5-06dbbb754730/ [ ^ ]
希望这会对你有帮助。
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.