PDFをBase64に変換する
Curtis Chau
Updated: 2026年4月24日
どのように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);
}
}Imports System
Imports SomePdfLibrary ' Make sure to import the library used for handling PDF files
Module Program
Sub Main()
' Create a PdfDocument object for the specified PDF file
Dim pdf As New PdfDocument("MyPDF.pdf")
' Get the binary data (byte array) from the PDF document
Dim byteArray As Byte() = pdf.BinaryData
' Convert the byte array to a Base64 string
Dim base64Result As String = Convert.ToBase64String(byteArray)
' Output the Base64 result
Console.WriteLine("Base64 of PDF: " & base64Result)
End Sub
End Module説明:
PdfDocument初期化:PdfDocumentオブジェクトは、変換したいPDFのファイル名で初期化されます。SomePdfLibraryを使用している実際のライブラリに置き換えてください。BinaryData取得: 指定されたPDFのバイナリデータ(バイト配列として)を取得します。- Base64 変換: バイト配列をBase64文字列に変換するために
Convert.ToBase64Stringメソッドが使用されます。 - 出力Base64文字列: Base64エンコードされた文字列を検証のためにコンソールに出力します。

テクニカルライター
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。
...
詳しく読む