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
Asked
Active
Viewed 1.2k times
0
-
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 Answers
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
-
-
@ammadkhan: Then that's a *completely* different question. (There's no real conversion going on in this question, despite the way it's phrased. It's just about writing the existing PDF to disk.) – Jon Skeet Nov 12 '22 at 07:52
-
can you plz guide how it can be done any link or source to solve this problem I am facing – ammad khan Nov 12 '22 at 09:53
-
1@ammadkhan: No; please don't spam comment threads with unrelated questions. – Jon Skeet Nov 12 '22 at 10:25
-
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