C#4.0:将PDF转换为byte [],反之亦然 [英] C# 4.0: Convert pdf to byte[] and vice versa
本文介绍了C#4.0:将PDF转换为byte [],反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何转换PDF文件到一个byte [],反之亦然?
解决方案
//从加载文件的字节在C#中非常容易。内置的System.IO.File.ReadAll *方法照顾,确保每一个字节正确读取的。
字节[]字节= System.IO.File.ReadAllBytes(myfile.pdf);
// munge与任何PDF软件你想
// ...
//好自己
//确保清理和字节救回来 - System.IO.File.WriteAll *确保所有字节正确写入。
System.IO.File.WriteAllBytes(myfile.pdf,字节);
How do I convert a pdf file to a byte[] and vice versa?
解决方案
// loading bytes from a file is very easy in C#. The built in System.IO.File.ReadAll* methods take care of making sure every byte is read properly.
byte[] bytes = System.IO.File.ReadAllBytes("myfile.pdf");
// munge bytes with whatever pdf software you want
// ...
// make sure to cleanup after yourself
// and save back - System.IO.File.WriteAll* makes sure all bytes are written properly.
System.IO.File.WriteAllBytes("myfile.pdf", bytes);
这篇关于C#4.0:将PDF转换为byte [],反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文