PDF'yi Base64'e Dönüştür

This article was translated from English: Does it need improvement?
Translated
View the article in English

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
$vbLabelText   $csharpLabel

Açıklama:

  • PdfDocument Başlatma: PdfDocument nesnesi, dönüştürmek istediğiniz PDF dosyasının adıyla başlatılır. SomePdfLibrary ifadesini, kullandığınız gerçek kütüphane ile değiştirin.
  • BinaryData Alma: Belirtilen PDF'nin ikili verilerini (bayt dizisi olarak) alır.
  • Base64 Dönüştürme: Convert.ToBase64String yö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.
Curtis Chau
Teknik Yazar

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ı...

Daha Fazla Oku
Başlamaya Hazır mısınız?
Nuget İndirmeler 19,014,616 | Sürüm: 2026.5 just released
Still Scrolling Icon

Hâlâ Kaydırıyor Musunuz?

Hızlıca kanıt ister misiniz? PM > Install-Package IronPdf
bir örnek çalıştır HTML'nizi bir PDF'ye dönüştüğünü izleyin.