PDF'yi Base64'e Dönüştür
PDF'i Base64'e nasıl dönüştürebilirim?
PdfDocument nesnesi, Base64'ü doğrudan almak için bir özellik içermez. Ancak, byte dizisini alabilirsiniz ve bu diziyi kullanarak Base64 stringini elde edebilirsiniz.
using System;
using IronPdf;
class Program
{
static void Main()
{
// Load the specified PDF file into a PdfDocument object
var pdf = PdfDocument.FromFile("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 IronPdf
Module Program
Sub Main()
' Load the specified PDF file into a PdfDocument object
Dim pdf = PdfDocument.FromFile("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 ModuleImports System
Imports IronPdf
Module Program
Sub Main()
' Load the specified PDF file into a PdfDocument object
Dim pdf = PdfDocument.FromFile("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 ModuleAçıklama:
PdfDocumentBaşlatma:PdfDocumentnesnesi, dönüştürmek istediğiniz PDF'nin dosya adındanPdfDocument.FromFilekullanılarak yüklenir.BinaryDataAlma: Verilen PDF'nin ikili verilerini (bir byte dizisi olarak) alır.- Base64 Dönüşümü: Byte dizisini Base64 stringine dönüştürmek için
Convert.ToBase64Stringyöntemi kullanılır. - Çıktı Base64 Dizisi: Base64 kodlu dizgi konsola doğrulama için yazdırılır.
Curtis Chau, Bilgisayar Bilimleri alanında Lisans Derecesine (Carleton Üniversitesi) sahip ve Node.js, TypeScript, JavaScript ve React konularında uzmanlaşmış ön uç geliştirmeyle ilgileniyor. Sezgisel ve estetik açıdan hoş kullanıcı arayüzleri oluşturma tutkunu, Curtis modern çerçevelerle çalışmayı ve iyi yapılandırılmış, görsel olarak çekici kılavuzlar oluşturmayı seviyor.