IronPDF ハウツー Azure Blob Storageから画像を使用してPDFを生成する AzureブロブストレージイメージでPDFをC#でレンダリングする カーティス・チャウ 更新日:2026年1月10日 IronPDF をダウンロード NuGet ダウンロード DLL ダウンロード Windows 版 無料トライアル 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 C#でAzure Blob Storageの画像を使ってPDFをレンダリングするには、BLOBデータをバイナリとして取得し、base64文字列に変換してHTMLのimgタグに埋め込み、IronPdfのChromePdfRendererを使ってHTMLをPDFに変換します。 Azure Blob Storage は、Microsoft Azure が提供するクラウドベースのストレージサービスです。 HTTP または HTTPS 経由でアクセス可能な、テキストまたはバイナリデータなどの大量の非構造化データを保存します。 C#でPDFを扱う場合、IronPdfは、Azure Blob Storageのようなクラウドサービスに保存されたものを含め、様々な画像形式やソースを扱うための強力な機能を提供します。 Azure Blob Storageに保存された画像を使用するには、直接のファイル参照ではなく、バイナリデータ形式を扱う必要があります。 解決策は、画像をbase64文字列に変換し、imgタグに埋め込むことです。 このアプローチは、IronPDFのHTMLからPDFへの変換機能とシームレスに連携し、画質とフォーマットを維持します。 今すぐ NuGet で PDF を作成してみましょう: NuGet パッケージ マネージャーを使用して IronPDF をインストールします PM > Install-Package IronPdf このコード スニペットをコピーして実行します。 var blobBase64 = Convert.ToBase64String(new BlobContainerClient("conn","cont").GetBlobClient("img.jpg").DownloadContent().Value.Content.ToArray()); new IronPdf.ChromePdfRenderer().RenderHtmlAsPdf($"<img src=\"data:image/jpeg;base64,{blobBase64}\" />").SaveAs("blobImage.pdf"); 実際の環境でテストするためにデプロイする 今すぐ無料トライアルでプロジェクトに IronPDF を使い始めましょう 30日間無料トライアル 最小限のワークフロー(5ステップ) Azureブロブに保存された画像をレンダリングするIronPdfをダウンロードする。 ブロブを取得するプロセスを処理する バイトを base64 に変換するには、ToBase64String メソッドを使用します。 imgタグにbase64の情報を含めてください。 HTMLをPDFにレンダリング Azureブロブ画像をHTMLに変換するにはどうすればよいですか? . Blob を含むコンテナで Azure Storage アカウントを設定し、C# プロジェクトで認証と接続を処理します。 IronPDFと一緒にAzure.Storage.Blobs NuGetパッケージを使用してください。 複雑な認証シナリオについては、安全なブロブアクセスのためのIronPDFのHTTPリクエストヘッダ機能をご覧ください。 画像をストリームとしてダウンロードするには、DownloadToStreamAsyncメソッドを使用します。 ストリームデータをBase64に変換し、HTMLのimgタグに埋め込む。 imageTag変数をHTML文書にマージしてください。 このテクニックは、動的に読み込まれるクラウドストレージの画像を使用してレポートや文書を作成する場合に効果的です。 using Azure.Storage.Blobs; using System; using System.IO; using System.Threading.Tasks; public async Task ConvertBlobToHtmlAsync() { // Define your connection string and container name string connectionString = "your_connection_string"; string containerName = "your_container_name"; // Initialize BlobServiceClient with the connection string BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString); // Get the BlobContainerClient for the specified container BlobContainerClient blobContainer = blobServiceClient.GetBlobContainerClient(containerName); // Get the reference to the blob and initialize a stream BlobClient blobClient = blobContainer.GetBlobClient("867.jpg"); using var stream = new MemoryStream(); // Download the blob data to the stream await blobClient.DownloadToAsync(stream); stream.Position = 0; // Reset stream position // Convert the stream to a byte array byte[] array = stream.ToArray(); // Convert bytes to base64 var base64 = Convert.ToBase64String(array); // Create an img tag with the base64-encoded string var imageTag = $"<img src=\"data:image/jpeg;base64,{base64}\"/><br/>"; // Use the imageTag in your HTML document as needed } using Azure.Storage.Blobs; using System; using System.IO; using System.Threading.Tasks; public async Task ConvertBlobToHtmlAsync() { // Define your connection string and container name string connectionString = "your_connection_string"; string containerName = "your_container_name"; // Initialize BlobServiceClient with the connection string BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString); // Get the BlobContainerClient for the specified container BlobContainerClient blobContainer = blobServiceClient.GetBlobContainerClient(containerName); // Get the reference to the blob and initialize a stream BlobClient blobClient = blobContainer.GetBlobClient("867.jpg"); using var stream = new MemoryStream(); // Download the blob data to the stream await blobClient.DownloadToAsync(stream); stream.Position = 0; // Reset stream position // Convert the stream to a byte array byte[] array = stream.ToArray(); // Convert bytes to base64 var base64 = Convert.ToBase64String(array); // Create an img tag with the base64-encoded string var imageTag = $"<img src=\"data:image/jpeg;base64,{base64}\"/><br/>"; // Use the imageTag in your HTML document as needed } $vbLabelText $csharpLabel 複数の画像や異なるフォーマットを扱う場合は、JPG、PNG、SVG、GIFを含むさまざまな画像タイプに対するIronPDFのサポートを活用してください。 base64エンコーディング方式は、これらすべてのフォーマットで汎用的に機能します。 さまざまな画像フォーマットで作業する Azure Blob Storageは様々な画像フォーマットに対応しており、IronPDFは適切にエンコードされた画像フォーマットに対応しています。 以下は、MIMEタイプを動的に決定する強化された例です: public string GetImageMimeType(string blobName) { var extension = Path.GetExtension(blobName).ToLower(); return extension switch { ".jpg" or ".jpeg" => "image/jpeg", ".png" => "image/png", ".gif" => "image/gif", ".svg" => "image/svg+xml", ".webp" => "image/webp", _ => "image/jpeg" // default fallback }; } public async Task<string> CreateImageTagFromBlob(BlobClient blobClient) { using var stream = new MemoryStream(); await blobClient.DownloadToAsync(stream); stream.Position = 0; var base64 = Convert.ToBase64String(stream.ToArray()); var mimeType = GetImageMimeType(blobClient.Name); return $"<img src=\"data:{mimeType};base64,{base64}\" alt=\"{Path.GetFileNameWithoutExtension(blobClient.Name)}\"/>"; } public string GetImageMimeType(string blobName) { var extension = Path.GetExtension(blobName).ToLower(); return extension switch { ".jpg" or ".jpeg" => "image/jpeg", ".png" => "image/png", ".gif" => "image/gif", ".svg" => "image/svg+xml", ".webp" => "image/webp", _ => "image/jpeg" // default fallback }; } public async Task<string> CreateImageTagFromBlob(BlobClient blobClient) { using var stream = new MemoryStream(); await blobClient.DownloadToAsync(stream); stream.Position = 0; var base64 = Convert.ToBase64String(stream.ToArray()); var mimeType = GetImageMimeType(blobClient.Name); return $"<img src=\"data:{mimeType};base64,{base64}\" alt=\"{Path.GetFileNameWithoutExtension(blobClient.Name)}\"/>"; } $vbLabelText $csharpLabel HTMLをPDFに変換するにはどうすればよいですか? . <!コードの概念を示す図またはスクリーンショット --> ChromePdfRendererのRenderHtmlAsPdfメソッドを使用して、imageTagをPDFに変換します。 IronPdfのChromeレンダリングエンジンは変換中も画質と位置を維持します。 最適な結果を得るためには、レンダリングオプションを設定して、PDF出力の品質をコントロールしてください。 以下は、RenderHtmlAsPdfを呼び出す方法です: :path=/static-assets/pdf/content-code-examples/how-to/images-azure-blob-storage-html-to-pdf.cs using IronPdf; // Instantiate Renderer var renderer = new ChromePdfRenderer(); // Create a PDF from a HTML string using C# var pdf = renderer.RenderHtmlAsPdf(imageTag); // Export to a file pdf.SaveAs("imageToPdf.pdf"); $vbLabelText $csharpLabel "htmlContent"変数を調整し、imageTagで実際のHTMLコンテンツを含めます。 完全な作業例 ここでは、エラー処理と最適化を含む、Azure Blob Storageの取得とIronPdfレンダリングを組み合わせた包括的な例を示します: using Azure.Storage.Blobs; using IronPdf; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading.Tasks; public class AzureBlobToPdfConverter { private readonly string _connectionString; private readonly ChromePdfRenderer _renderer; public AzureBlobToPdfConverter(string connectionString) { _connectionString = connectionString; _renderer = new ChromePdfRenderer(); // Configure rendering options for better image quality _renderer.RenderingOptions.ImageQuality = 100; _renderer.RenderingOptions.DpiResolution = 300; } public async Task<PdfDocument> ConvertBlobImagesToPdfAsync(string containerName, List<string> blobNames) { var htmlBuilder = new StringBuilder(); htmlBuilder.Append("<html><body style='margin: 20px;'>"); var blobServiceClient = new BlobServiceClient(_connectionString); var containerClient = blobServiceClient.GetBlobContainerClient(containerName); foreach (var blobName in blobNames) { try { var blobClient = containerClient.GetBlobClient(blobName); var imageTag = await CreateImageTagFromBlob(blobClient); htmlBuilder.Append(imageTag); htmlBuilder.Append("<br/><br/>"); // Add spacing between images } catch (Exception ex) { // Log error and continue with other images Console.WriteLine($"Error processing blob {blobName}: {ex.Message}"); } } htmlBuilder.Append("</body></html>"); // Convert the complete HTML to PDF return _renderer.RenderHtmlAsPdf(htmlBuilder.ToString()); } private async Task<string> CreateImageTagFromBlob(BlobClient blobClient) { using var stream = new MemoryStream(); await blobClient.DownloadToAsync(stream); stream.Position = 0; var base64 = Convert.ToBase64String(stream.ToArray()); var mimeType = GetImageMimeType(blobClient.Name); return $"<img src=\"data:{mimeType};base64,{base64}\" " + $"alt=\"{Path.GetFileNameWithoutExtension(blobClient.Name)}\" " + $"style=\"max-width: 100%; height: auto;\"/>"; } private string GetImageMimeType(string blobName) { var extension = Path.GetExtension(blobName).ToLower(); return extension switch { ".jpg" or ".jpeg" => "image/jpeg", ".png" => "image/png", ".gif" => "image/gif", ".svg" => "image/svg+xml", ".webp" => "image/webp", _ => "image/jpeg" }; } } using Azure.Storage.Blobs; using IronPdf; using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Threading.Tasks; public class AzureBlobToPdfConverter { private readonly string _connectionString; private readonly ChromePdfRenderer _renderer; public AzureBlobToPdfConverter(string connectionString) { _connectionString = connectionString; _renderer = new ChromePdfRenderer(); // Configure rendering options for better image quality _renderer.RenderingOptions.ImageQuality = 100; _renderer.RenderingOptions.DpiResolution = 300; } public async Task<PdfDocument> ConvertBlobImagesToPdfAsync(string containerName, List<string> blobNames) { var htmlBuilder = new StringBuilder(); htmlBuilder.Append("<html><body style='margin: 20px;'>"); var blobServiceClient = new BlobServiceClient(_connectionString); var containerClient = blobServiceClient.GetBlobContainerClient(containerName); foreach (var blobName in blobNames) { try { var blobClient = containerClient.GetBlobClient(blobName); var imageTag = await CreateImageTagFromBlob(blobClient); htmlBuilder.Append(imageTag); htmlBuilder.Append("<br/><br/>"); // Add spacing between images } catch (Exception ex) { // Log error and continue with other images Console.WriteLine($"Error processing blob {blobName}: {ex.Message}"); } } htmlBuilder.Append("</body></html>"); // Convert the complete HTML to PDF return _renderer.RenderHtmlAsPdf(htmlBuilder.ToString()); } private async Task<string> CreateImageTagFromBlob(BlobClient blobClient) { using var stream = new MemoryStream(); await blobClient.DownloadToAsync(stream); stream.Position = 0; var base64 = Convert.ToBase64String(stream.ToArray()); var mimeType = GetImageMimeType(blobClient.Name); return $"<img src=\"data:{mimeType};base64,{base64}\" " + $"alt=\"{Path.GetFileNameWithoutExtension(blobClient.Name)}\" " + $"style=\"max-width: 100%; height: auto;\"/>"; } private string GetImageMimeType(string blobName) { var extension = Path.GetExtension(blobName).ToLower(); return extension switch { ".jpg" or ".jpeg" => "image/jpeg", ".png" => "image/png", ".gif" => "image/gif", ".svg" => "image/svg+xml", ".webp" => "image/webp", _ => "image/jpeg" }; } } $vbLabelText $csharpLabel パフォーマンスの考慮事項 . 大きな画像や複数のblobを扱う場合は、asyncとマルチスレッド技術を実装して、パフォーマンスを向上させてください。 同じブロブを繰り返しダウンロードしないように、キャッシュ機構を追加してください。 本番環境、特にAzureデプロイメントについては、IronPdfのAzureデプロイメントガイドでベストプラクティスと推奨設定を確認してください。 メモリを大量に消費する操作には、IronPdfのメモリストリーム機能を使用して、リソースの使用量を最適化してください。 セキュリティと認証 Azure Blob Storageにアクセスする際に、適切な認証を確保すること。 セキュリティを強化するために、保護されたリソースにアクセスするときは、カスタムHTTPヘッダーを実装してください。 Azure blob イメージを含む機密文書には、PDF パスワード保護の実装を検討してください。 よくある問題のトラブルシューティング BLOBストレージの統合に関する問題が発生した場合は、IronPdfのAzureトラブルシューティングガイドを参照して、一般的な問題の解決策を確認してください。 画像固有の問題については、画像レンダリング・ドキュメントが、さまざまなシナリオの処理に関する詳細なガイダンスを提供しています。 よくある質問 Azure Blob Storageに保存された画像でPDFを生成するには? Azure Blob Storageの画像を使ってPDFを生成するには、BLOBデータをバイナリとして取得し、それをbase64文字列に変換してHTMLのimgタグに埋め込み、IronPDFのChromePdfRendererを使ってHTMLをPDFに変換します。この方法はIronPDFのHTMLからPDFへの変換機能とシームレスに動作し、画質を維持します。 Azure BlobイメージをPDFにレンダリングする最も速い方法は? BlobContainerClientでblobを取得し、Convert.ToBase64String()でbase64に変換し、imgタグに埋め込み、IronPDFのChromePdfRenderer().RenderHtmlAsPdf()メソッドでレンダリングする。 PDFでAzure Blob Storageイメージのファイル参照を直接使用できないのはなぜですか? Azure Blob Storageでは、直接ファイルを参照するのではなく、バイナリデータ形式を扱う必要があります。解決策は画像をbase64文字列に変換してimgタグに埋め込み、それをIronPDFのHTMLからPDFへの変換機能で処理することです。 PDFでAzure Blobイメージを扱うには、どのNuGetパッケージが必要ですか? PDFレンダリング用のIronPDFと一緒にブロブストレージ操作用のAzure.Storage.Blobs NuGetパッケージが必要です。IronPDFはBase64画像を埋め込んだHTMLをPDFドキュメントに変換するChromePdfRendererを提供します。 PDFを生成する際、セキュアなAzure Blobアクセスの認証をどのように処理すればよいですか? C# プロジェクトで、適切な認証と接続を使用して Azure Storage アカウントを設定します。複雑な認証シナリオについては、IronPDFのHTTPリクエストヘッダ機能を使用して、PDFレンダリング時のセキュアなブロブアクセスを処理することができます。 カーティス・チャウ 今すぐエンジニアリングチームとチャット テクニカルライター Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。 準備はできましたか? Nuget ダウンロード 17,570,948 | バージョン: 2026.2 リリース NuGet 無料版 総ダウンロード数: 17,570,948 ライセンスを見る