IronBarcode ハウツー .NET バーコードをPDFとして作成 C#でバーコードをPDFとしてエクスポートする方法 Hairil Hasyimi Bin Omar 更新日:2026年1月10日 IronBarcode をダウンロード NuGet ダウンロード DLL ダウンロード 無料トライアル LLM向けのコピー LLM向けのコピー LLM 用の Markdown としてページをコピーする ChatGPTで開く このページについてChatGPTに質問する ジェミニで開く このページについてGeminiに問い合わせる Grokで開く このページについてGrokに質問する 困惑の中で開く このページについてPerplexityに問い合わせる 共有する Facebook で共有 Xでシェア(Twitter) LinkedIn で共有 URLをコピー 記事をメールで送る This article was translated from English: Does it need improvement? Translated View the article in English IronBarcodeはC#の開発者が3つの方法でバーコードをPDFとしてエクスポートすることを可能にします。 クイックスタート: バーコードを即座にPDFにエクスポート この例では、.NETでIronBarcodeを使用してバーコードをPDFとしてエクスポートするのがどれほど簡単かを示しています。 1行でPDF対応のバーコードを取得できます。これは、保存、ストリーミング、または迅速な送信に理想的です。 今すぐ NuGet で PDF を作成してみましょう: NuGet パッケージ マネージャーを使用して IronBarcode をインストールします PM > Install-Package BarCode このコード スニペットをコピーして実行します。 var pdfBytes = IronBarCode.BarcodeWriter.CreateBarcode("FastPDF", IronBarCode.BarcodeWriterEncoding.Code128).ToPdfBinaryData(); 実際の環境でテストするためにデプロイする 今すぐ無料トライアルでプロジェクトに IronBarcode を使い始めましょう 30日間無料トライアル ### 最小限のワークフロー(5ステップ) C# でバーコードを PDF としてエクスポートするための C# ライブラリをダウンロードする BarCodeをPDFファイルとして書き出す バーコードをPDFバイナリデータとしてエクスポート バーコードをPDFストリームとしてエクスポートする バーコードを PDF ファイルとしてエクスポートするにはどうすればよいですか? なぜ BarCode を PDF ファイルに直接保存するのですか? バーコードを PDF ファイルに直接保存することは、物理的な文書の生成、印刷可能なラベルの作成、または長期保存のためのバーコードのアーカイブが必要な場合に、最も簡単なアプローチです。 この方法は、在庫管理システム、出荷ラベル、文書生成ワークフローなど、PDF形式が異なるプラットフォームやプリンタ間で一貫したレンダリングを保証する場合に特に有用です。 バーコードをPDFファイルとして保存するには、まずBarcodeWriter.CreateBarcodeでGeneratedBarcodeオブジェクトを作成し、SaveAsPdf()メソッドを使用して変換してディスクに保存します。 次のコードスニペットは、これがどのように機能するかを示しています。 :path=/static-assets/barcode/content-code-examples/how-to/ExportBarcodeAsPdfFile.cs using IronBarCode; GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix); myBarcode.SaveAsPdf("myBarcode.pdf"); Imports IronBarCode Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix) myBarcode.SaveAsPdf("myBarcode.pdf") $vbLabelText $csharpLabel より高度なバーコード作成オプションについては、さまざまなデータソースからバーコードを作成するに関する包括的なガイドをご覧ください。 どのようなファイルパスのオプションがありますか? IronBarcodeはPDFファイルの保存に柔軟なファイルパスオプションを提供します。 絶対パス、相対パス、または環境変数を指定できます。 以下は、異なるパスのオプションを示す、より詳細な例です: using IronBarCode; using System; using System.IO; // Create a barcode GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128); // Save to current directory barcode.SaveAsPdf("barcode.pdf"); // Save to absolute path barcode.SaveAsPdf(@"C:\BarcodeExports\product_barcode.pdf"); // Save to relative path barcode.SaveAsPdf(@"..\..\exports\barcode.pdf"); // Save using environment path string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); barcode.SaveAsPdf(Path.Combine(documentsPath, "barcode.pdf")); using IronBarCode; using System; using System.IO; // Create a barcode GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128); // Save to current directory barcode.SaveAsPdf("barcode.pdf"); // Save to absolute path barcode.SaveAsPdf(@"C:\BarcodeExports\product_barcode.pdf"); // Save to relative path barcode.SaveAsPdf(@"..\..\exports\barcode.pdf"); // Save using environment path string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); barcode.SaveAsPdf(Path.Combine(documentsPath, "barcode.pdf")); Imports IronBarCode Imports System Imports System.IO ' Create a barcode Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128) ' Save to current directory barcode.SaveAsPdf("barcode.pdf") ' Save to absolute path barcode.SaveAsPdf("C:\BarcodeExports\product_barcode.pdf") ' Save to relative path barcode.SaveAsPdf("..\..\exports\barcode.pdf") ' Save using environment path Dim documentsPath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) barcode.SaveAsPdf(Path.Combine(documentsPath, "barcode.pdf")) $vbLabelText $csharpLabel この記事では、IronBarcodeを使用してバーコードをPDFにエクスポートする方法について説明します。 IronBarcodeを使用すると、バーコードはファイル、バイナリデータ、またはメモリストリームとしてエクスポートできます。 IronBarcodeの機能の概要については、Getting Start documentationをご覧ください。 どのような場合にファイル エクスポートと他の方法を使い分ける必要がありますか? ファイルエクスポートを選択してください: BarCodeの永久保存が必要です。 レポートや印刷可能な文書の作成 オフライン処理用バッチファイルの作成 ファイルベースのシステムとの統合 バイナリデータやストリームを考慮する 即時対応が必要なウェブアプリケーションを扱う データベースへの保存 ファイルシステムにアクセスせずにAPI経由で送信する メモリ制約環境での処理 バーコードを PDF のバイナリ データとしてエクスポートするにはどうすればよいですか? なぜファイルの代わりにバイナリ データを使用するのですか? バイナリデータのエクスポートは、一時ファイルを作成せずにメモリ内でPDFデータを操作する必要があるシナリオに最適です。 このアプローチは、ウェブアプリケーション、クラウド環境、データベースを使用する場合に特に有効です。 ファイルI/O操作を排除し、データをメモリ内に保持することで、パフォーマンスとセキュリティを向上させます。 PDFバイナリデータとしてエクスポートするには、バーコードを生成してからToPdfBinaryData()メソッドを呼び出します。 これにより、PDFバイナリデータがbyte[]配列として出力されます。 次のコードスニペットは、これがどのように機能するかを示しています。 :path=/static-assets/barcode/content-code-examples/how-to/ExportBarcodeAsPdfBinaryData.cs using IronBarCode; GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix); byte[] myBarcodeByte = myBarcode.ToPdfBinaryData(); Imports IronBarCode Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix) Private myBarcodeByte() As Byte = myBarcode.ToPdfBinaryData() $vbLabelText $csharpLabel エクスポートする前に、バーコードの外観をカスタマイズすることもできます。 PDFエクスポートを強化するためのバーコードスタイルのカスタマイズについては、こちらをご覧ください。 バイナリ PDF データを API に送信するにはどうすればよいですか? バイナリPDFデータは、REST APIを通じて簡単に転送できるため、マイクロサービスアーキテクチャに最適です。 以下は、HTTPリクエストでBarCode PDFデータを送信する実用的な例です: using IronBarCode; using System.Net.Http; using System.Threading.Tasks; public async Task SendBarcodeToAPI() { // Generate barcode and get binary data GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("API-DATA-123", BarcodeEncoding.QRCode); byte[] pdfData = barcode.ToPdfBinaryData(); // Send via HTTP POST using (HttpClient client = new HttpClient()) { ByteArrayContent content = new ByteArrayContent(pdfData); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"); HttpResponseMessage response = await client.PostAsync("https://api.example.com/barcode", content); // Handle response } } using IronBarCode; using System.Net.Http; using System.Threading.Tasks; public async Task SendBarcodeToAPI() { // Generate barcode and get binary data GeneratedBarcode barcode = BarcodeWriter.CreateBarcode("API-DATA-123", BarcodeEncoding.QRCode); byte[] pdfData = barcode.ToPdfBinaryData(); // Send via HTTP POST using (HttpClient client = new HttpClient()) { ByteArrayContent content = new ByteArrayContent(pdfData); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"); HttpResponseMessage response = await client.PostAsync("https://api.example.com/barcode", content); // Handle response } } Imports IronBarCode Imports System.Net.Http Imports System.Threading.Tasks Public Async Function SendBarcodeToAPI() As Task ' Generate barcode and get binary data Dim barcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("API-DATA-123", BarcodeEncoding.QRCode) Dim pdfData As Byte() = barcode.ToPdfBinaryData() ' Send via HTTP POST Using client As New HttpClient() Dim content As New ByteArrayContent(pdfData) content.Headers.ContentType = New System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf") Dim response As HttpResponseMessage = Await client.PostAsync("https://api.example.com/barcode", content) ' Handle response End Using End Function $vbLabelText $csharpLabel バイナリ エクスポートの一般的な使用例とは バイナリエクスポートは、一般的に次のような場面で使用されます: データベースストレージ: PDF バーコードを BLOB データとしてデータベースに保存します。 メール添付:一時ファイルを作成することなく、電子メールに BarCode を添付します。 クラウド・ストレージ:Azure Blob Storage や AWS S3 などのサービスに直接アップロードできます。 インメモリ処理:ディスクI/Oなしで複数の操作を連鎖させる Web APIレスポンス:HTTP レスポンスで PDF データを直接返す その他のバーコード生成テクニックやベストプラクティスについては、さまざまなソースからバーコードを作成するガイドをご覧ください。 また、より高度な PDF 操作シナリオのために、 既存の PDF に BarCode をスタンプする方法についても学ぶことができます。 バーコードを PDF ストリームとしてエクスポートするにはどうすればよいですか? なぜPDFエクスポートにストリームを使用するのですか ストリームは、特に他の.NETライブラリと統合する場合や、データフローをきめ細かく制御する必要がある場合に、PDFデータを扱うための最も柔軟なアプローチを提供します。 ストリームは、バッファリングされた読み書きができるため、メモリ効率が重要な大規模処理に特に有用です。 メモリストリームとしてエクスポートするには、バーコードを生成し、次にToPdfStream()メソッドを呼び出します。 このメソッドはSystem.IO.Streamオブジェクトを返します。 次のコードスニペットは、これがどのように機能するかを示しています。 :path=/static-assets/barcode/content-code-examples/how-to/ExportBarcodeAsPdfStream.cs using IronBarCode; using System.IO; GeneratedBarcode myBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix); Stream myBarcodeStream = myBarcode.ToPdfStream(); Imports IronBarCode Imports System.IO Private myBarcode As GeneratedBarcode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode/", BarcodeEncoding.DataMatrix) Private myBarcodeStream As Stream = myBarcode.ToPdfStream() $vbLabelText $csharpLabel 高度なストリーム操作やその他のエクスポート形式については、exporting barcodes as streams の詳細ガイドを参照してください。 メモリストリームを適切に扱うにはどうすればよいですか? 適切なストリーム処理は、メモリリークを防ぎ、リソースを効率的に使用するために非常に重要です。 以下は、ベストプラクティスを示す包括的な例です: using IronBarCode; using System.IO; public void ProcessBarcodeStream() { // Always use using statements for proper disposal using (Stream pdfStream = BarcodeWriter.CreateBarcode("STREAM-123", BarcodeEncoding.Code39).ToPdfStream()) { // Example 1: Copy to file using (FileStream fileStream = File.Create("output.pdf")) { pdfStream.CopyTo(fileStream); } // Reset stream position for reuse pdfStream.Position = 0; // Example 2: Read into buffer byte[] buffer = new byte[pdfStream.Length]; pdfStream.Read(buffer, 0, buffer.Length); // Example 3: Process with another library // ProcessPdfStream(pdfStream); } } using IronBarCode; using System.IO; public void ProcessBarcodeStream() { // Always use using statements for proper disposal using (Stream pdfStream = BarcodeWriter.CreateBarcode("STREAM-123", BarcodeEncoding.Code39).ToPdfStream()) { // Example 1: Copy to file using (FileStream fileStream = File.Create("output.pdf")) { pdfStream.CopyTo(fileStream); } // Reset stream position for reuse pdfStream.Position = 0; // Example 2: Read into buffer byte[] buffer = new byte[pdfStream.Length]; pdfStream.Read(buffer, 0, buffer.Length); // Example 3: Process with another library // ProcessPdfStream(pdfStream); } } Imports IronBarCode Imports System.IO Public Sub ProcessBarcodeStream() ' Always use using statements for proper disposal Using pdfStream As Stream = BarcodeWriter.CreateBarcode("STREAM-123", BarcodeEncoding.Code39).ToPdfStream() ' Example 1: Copy to file Using fileStream As FileStream = File.Create("output.pdf") pdfStream.CopyTo(fileStream) End Using ' Reset stream position for reuse pdfStream.Position = 0 ' Example 2: Read into buffer Dim buffer As Byte() = New Byte(pdfStream.Length - 1) {} pdfStream.Read(buffer, 0, buffer.Length) ' Example 3: Process with another library ' ProcessPdfStream(pdfStream) End Using End Sub $vbLabelText $csharpLabel バイナリ データよりもストリームを選択する必要があるのはどのような場合ですか? 以下のような場合に、ストリームを選択してください: ストリーム入力を期待する他のライブラリとの統合 コンテンツ全体をメモリにロードすることが実行不可能な、大きなファイルの処理。 ウェブアプリケーションにストリーミング応答を実装する。 他のストリームベースAPIとのチェーン操作について パフォーマンスの最適化のためにバッファされた読み取り/書き込みが必要です。 バイナリデータを選択してください: 変数またはデータベースへの簡単な保存が必要です。 複雑な処理を必要としない素早いシリアライズ。 バイト配列を期待するAPIでの作業 その他のバーコード生成テクニックやベストプラクティスについては、包括的なバーコードチュートリアルをご覧ください。 また、より高度な PDF 操作シナリオのために、 既存の PDF に BarCode をスタンプする方法についても学ぶことができます。 よくある質問 C#でバーコードをPDFにエクスポートするには? IronBarcodeはバーコードをPDFとしてエクスポートする3つの方法を提供します: SaveAsPdf()を使用してファイルに直接保存、ToPdfBinaryData()を使用してバイナリデータに変換、またはメモリにストリーミングします。最も簡単な方法は、BarcodeWriter.CreateBarcode()を使用し、その後にお好みのエクスポート方法を使用することです。 たった1行のコードでPDF BarCodeを生成できますか? はい、IronBarcodeは1行のPDFバーコード生成を可能にします。var pdfBytes = IronBarCode.BarCodeWriter.CreateBarcode("FastPDF", IronBarCode.BarCodeWriterEncoding.Code128).ToPdfBinaryData(); を使用するだけで、即座にPDF対応のバーコードが作成できます。 BarCode を PDF ファイルとして保存する場合、どのようなファイルパスオプションが利用できますか? IronBarcodeは絶対パス、相対パス、環境変数を含む柔軟なファイルパスオプションをサポートしています。カレントディレクトリには "barcode.pdf"、絶対パスには "C:˶BarcodeExportsproduct_barcode.pdf"、システムパスにはPath.Combine() with Environment.SpecialFolderのようなパスでSaveAsPdf()を使用できます。 ストリームを使用せず、BarCode を直接 PDF ファイルに保存する必要があるのはどのような場合ですか? IronBarcodeのSaveAsPdf()メソッドによるPDFファイルへの直接保存は、物理的なドキュメントの生成、印刷可能なラベルの作成、長期保存のためのバーコードのアーカイブに最適です。この方法は、在庫管理システム、出荷ラベル、一貫したPDFレンダリングが必要なドキュメントワークフローに特に便利です。 BarCode データを PDF バイナリデータに変換する方法を教えてください。 IronBarcodeのToPdfBinaryData()メソッドを使用してバーコードをバイナリデータに変換します。最初にBarcodeWriter.CreateBarcode()でGeneratedBarcodeオブジェクトを作成し、次にToPdfBinaryData()を呼び出してPDFをデータベース保存やネットワーク伝送に適したバイト配列として取得します。 BarCode をディスクに保存する代わりに、メモリに直接ストリーミングできますか? はい、IronBarcodeはメモリへのバーコードのストリーミングをサポートしており、物理的なファイルを作成することなくPDFデータを扱うことができます。これは、ディスクI/O操作なしでPDFバーコードを動的に提供する必要があるWebアプリケーションやAPIに最適です。 Hairil Hasyimi Bin Omar 今すぐエンジニアリングチームとチャット ソフトウェアエンジニア すべての優れたエンジニアのように、ハイリルは熱心な学習者です。彼はC#、Python、Javaの知識を磨き、その知識を活用してIron Softwareのチームメンバーに価値を追加しています。ハイリルはマレーシアのマラ工科大学からIron Softwareのチームに参加し、化学およびプロセス工学の学士号を取得しました。 準備はできましたか? Nuget ダウンロード 2,070,733 | バージョン: 2026.2 リリース NuGet 無料版 総ダウンロード数: 2,070,733 ライセンスを見る