PDF를 Base64로 변환

This article was translated from English: Does it need improvement?
Translated
View the article in English
PDF 파일을 Base64로 변환하려면 어떻게 해야 하나요?

PdfDocument 객체에는 Base64 값을 직접 얻을 수 있는 속성이 없습니다. 하지만 바이트 배열을 얻을 수 있으며, 이 배열을 사용하여 Base64 문자열을 얻을 수 있습니다.

using System;
using SomePdfLibrary; // Make sure to import the library used for handling PDF files

class Program
{
    static void Main()
    {
        // Create a PdfDocument object for the specified PDF file
        var pdf = new PdfDocument("MyPDF.pdf");

        // Get the binary data (byte array) from the PDF document
        var byteArray = pdf.BinaryData;

        // Convert the byte array to a Base64 string
        var base64Result = Convert.ToBase64String(byteArray);

        // Output the Base64 result
        Console.WriteLine("Base64 of PDF: " + base64Result);
    }
}
using System;
using SomePdfLibrary; // Make sure to import the library used for handling PDF files

class Program
{
    static void Main()
    {
        // Create a PdfDocument object for the specified PDF file
        var pdf = new PdfDocument("MyPDF.pdf");

        // Get the binary data (byte array) from the PDF document
        var byteArray = pdf.BinaryData;

        // Convert the byte array to a Base64 string
        var base64Result = Convert.ToBase64String(byteArray);

        // Output the Base64 result
        Console.WriteLine("Base64 of PDF: " + base64Result);
    }
}
$vbLabelText   $csharpLabel

설명:

  • PdfDocument 초기화: PdfDocument 객체는 변환하려는 PDF 파일 이름으로 초기화됩니다. SomePdfLibrary 부분을 사용 중인 실제 라이브러리 이름으로 바꾸세요.
  • BinaryData 검색: 주어진 PDF의 바이너리 데이터(바이트 배열)를 검색합니다.
  • Base64 변환: Convert.ToBase64String 메서드는 바이트 배열을 Base64 문자열로 변환하는 데 사용됩니다.
  • Base64 문자열 출력: Base64로 인코딩된 문자열이 확인을 위해 콘솔에 출력됩니다.
커티스 차우
기술 문서 작성자

커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다.

커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다.

시작할 준비 되셨나요?
Nuget 다운로드 17,527,568 | 버전: 2026.2 방금 출시되었습니다