IT story

C # 4.0 : pdf를 byte []로 또는 그 반대로 변환

hot-time 2021. 1. 6. 20:26
반응형

C # 4.0 : pdf를 byte []로 또는 그 반대로 변환


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.
System.IO.File.WriteAllBytes(pdfFilePath, bytes);

가장 쉬운 방법:

byte[] buffer;
using (Stream stream = new IO.FileStream("file.pdf"))
{
   buffer = new byte[stream.Length - 1];
   stream.Read(buffer, 0, buffer.Length);
}

using (Stream stream = new IO.FileStream("newFile.pdf"))
{
   stream.Write(buffer, 0, buffer.Length);
}

아니면이 라인을 따라 뭔가 ...

참조 URL : https://stackoverflow.com/questions/2451864/c-sharp-4-0-convert-pdf-to-byte-and-vice-versa

반응형