You are writing the file as text, but you should be writing the raw bytes. A .PDF file is a binary file, not a text file, so in effect, you're filling it with the wrong data in your first code sample.
System.IO.File.WriteAllBytes is documented at http://msdn.microsoft.com/en-us/library/system.io.file.writeallbytes.aspx if you have more questions.
answered Jan 1 '13 at 15:00
65.3k1313 gold badges120120 silver badges162162 bronze badges