我正在尝试将存储在sql列中的文件的内容转换为pdf.
我使用以下代码:
byte[] bytes;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, fileContent);
bytes = ms.ToArray();
System.IO.File.WriteAllBytes("hello.pdf", bytes);
Run Code Online (Sandbox Code Playgroud)
生成的pdf在某种意义上是腐败的,当我在notepad ++中打开pdf时,我看到一些垃圾标题(无论fileContent如何都是相同的).垃圾标题是NUL SOH NUL NUL NUL ....