PDF'i Base64'e Dönüştürme
PDF'i Base64'e nasıl dönüştürebilirim?
PdfDocument nesnesi, Base64 elde etmek için doğrudan bir özelliğe sahip değildir. Ancak, byte dizisini alabilirsiniz; bu da Base64 dizesi elde etmek için kullanılabilir.
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
Açıklama:
PdfDocumentBaşlatma:PdfDocumentnesnesi, dönüştürmek istediğiniz PDF'in dosya adı ile başlatılır.SomePdfLibrary'u kullandığınız gerçek kütüphane ile değiştirin.BinaryDataGeri Alma: Verilen PDF'in ikili verilerini (byte dizisi olarak) geri alır.- Base64 Dönüşümü:
Convert.ToBase64Stringmetodu, byte dizisini Base64 dizesine dönüştürmek için kullanılır. - Base64 Dizesinin Çıktısı: Base64 kodlu dize doğrulama için konsolda yazdırılır.

