0

How do I convert byte[] into a PDF document in C#? I want to create a PDF file from the byte[] into c:/PDF/test.pdf

David Basarab
  • 72,212
  • 42
  • 129
  • 156
acadia
  • 2,619
  • 18
  • 55
  • 72
  • possible duplicate of [PDF to byte array and vice versa](http://stackoverflow.com/questions/1131116/pdf-to-byte-array-and-vice-versa) – David Basarab May 18 '10 at 16:24

2 Answers2

5

The simplest way is using File.WriteAllBytes:

File.WriteAllBytes(fileName, data);

No need for opening streams, worrying about closing them properly etc - it does it all for you.

That's assuming data already contains the PDF document appropriately, of course. If you haven't already got a PDF, you'll need to tell us what's in the byte[]...

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

If the data is already known to be pdf, it's simple.

System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.Create);
stream.write(data, 0, data.Length);
stream.Close();
Tesserex
  • 17,166
  • 5
  • 66
  • 106