PDF'yi Base64'e Dönüştür
PDF'yi Base64'e nasıl dönüştürürüm?
PdfDocument nesnesi, Base64'ü almak için doğrudan bir özellik içermez. Ancak, Base64 dizesini elde etmek için kullanılabilecek bayt dizisini alabilirsiniz.
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 dosyasının adıyla başlatılır.SomePdfLibraryifadesini, kullandığınız gerçek kütüphane ile değiştirin.BinaryDataAlma: Belirtilen PDF'nin ikili verilerini (bayt dizisi olarak) alır.- Base64 Dönüştürme:
Convert.ToBase64Stringyöntemi, bayt dizisini bir Base64 dizesine dönüştürmek için kullanılır. - Çıktı Base64 Dizisi: Base64 kodlu dizgi konsola doğrulama için yazdırılır.

