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);
}
}
Imports System
Imports SomePdfLibrary ' Make sure to import the library used for handling PDF files
Friend Class Program
Shared Sub Main()
' Create a PdfDocument object for the specified PDF file
Dim pdf = New PdfDocument("MyPDF.pdf")
' Get the binary data (byte array) from the PDF document
Dim byteArray = pdf.BinaryData
' Convert the byte array to a Base64 string
Dim base64Result = Convert.ToBase64String(byteArray)
' Output the Base64 result
Console.WriteLine("Base64 of PDF: " & base64Result)
End Sub
End Class
$vbLabelText
$csharpLabel
설명:
PdfDocument초기화:PdfDocument객체는 변환하려는 PDF의 파일 이름으로 초기화됩니다.SomePdfLibrary을 실제로 사용 중인 라이브러리 이름으로 대체하십시오.BinaryData검색: 주어진 PDF의 바이너리 데이터(바이트 배열 형태)를 검색합니다.- Base64 변환:
Convert.ToBase64String메서드는 바이트 배열을 Base64 문자열로 변환하는 데 사용됩니다. - Base64 문자열 출력: Base64로 인코딩된 문자열이 확인을 위해 콘솔에 출력됩니다.
시작할 준비 되셨나요?
Nuget 다운로드 19,014,616 | 버전: 2026.5 just released

