Click here to Skip to main content
11,790,816 members (49,587 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: .NET3.5 C# ASP.NET
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); 

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

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

thanks in advance,
Posted 29-May-11 22:26pm
Edited 29-May-11 22:31pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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);
(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)
moral_2011 at 30-May-11 5:33am
Thank You It Is working With Me now
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

MemoryStream ms = new MemoryStream(pdfBytearray); 
Response.ContentType = "application/pdf"; 
Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf"); 
Response.Buffer = true; 
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

If it is a byte array, you can write it to disk so it becomes saved as *pdf file.
either, you can write the bytes to the response output stream and user will be prompt to download and save the file.

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

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

Hope this will help you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 385
1 ppolymorphe 339
2 Richard MacCutchan 118
3 Maciej Los 70
4 George Swan 70
0 OriginalGriff 1,154
1 Maciej Los 825
2 KrunalRohit 686
3 ppolymorphe 660
4 CPallini 621

Advertise | Privacy | Mobile
Web04 | 2.8.1509028.1 | Last Updated 30 May 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100