gpt4 book ai didi

C# 4.0 : Convert pdf to byte[] and vice versa

转载 作者:IT王子 更新时间:2023-10-29 03:48:18 26 4
gpt4 key购买 nike

如何将 pdf 文件转换为 byte[],反之亦然?

最佳答案

// 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.
// note that for Linux, you will not need the c: part
// just swap out the example folder here with your actual full file path
string pdfFilePath = "c:/pdfdocuments/myfile.pdf";
byte[] bytes = System.IO.File.ReadAllBytes(pdfFilePath);

// munge bytes with whatever pdf software you want, i.e. http://sourceforge.net/projects/itextsharp/
// bytes = MungePdfBytes(bytes); // MungePdfBytes is your custom method to change the PDF data
// ...
// make sure to cleanup after yourself

// and save back - System.IO.File.WriteAll* makes sure all bytes are written properly - this will overwrite the file, if you don't want that, change the path here to something else
System.IO.File.WriteAllBytes(pdfFilePath, bytes);

关于C# 4.0 : Convert pdf to byte[] and vice versa,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2451864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com