C#num; PDFへのエクスポート コード例チュートリアル

チャクニット・ビン
チャクニット・ビン
2023年1月25日
更新済み 2024年12月10日
共有:
This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPDFは、C# PDFライブラリであり、C#を使用してHTMLをPDFとして保存できます。 また、C# / VB 開発者がプログラムによってPDFドキュメントを編集することも可能です。

IronPDFを始めましょう

今日から無料トライアルでIronPDFをあなたのプロジェクトで使い始めましょう。

最初のステップ:
green arrow pointer



PDFを保存するためのオプション

ディスクにPDFを保存する方法

PDFをディスクに保存するには、PdfDocument.SaveAs メソッドを使用します。

このメソッドはパスワード保護の追加をサポートしていることがわかります。 以下の記事をチェックして、エクスポートされたPDFにデジタル署名する方法について詳しく学んでください: 'PDF文書にデジタル署名.'

メモリストリームにPDFファイルを保存する方法(System.IO.MemoryStream

IronPdf.PdfDocument.Stream プロパティは、System.IO.MemoryStream を使用してPDFをメモリに保存します。

バイナリデータに保存する方法

IronPdf.PdfDocument.BinaryData プロパティは、PDF ドキュメントをメモリ内のバイナリデータとしてエクスポートします。

これは、PDFをByteArrayとして出力します。C#ではbyte []として表現されます。

Webサーバーからブラウザーへの配信方法

PDFをウェブに提供するには、HTMLではなくバイナリデータとして送信する必要があります。

MVC PDFエクスポート

// Send MyPdfDocument.Stream to this method
return new FileStreamResult(stream, "application/pdf")
{
    FileDownloadName = "file.pdf"
};
// Send MyPdfDocument.Stream to this method
return new FileStreamResult(stream, "application/pdf")
{
    FileDownloadName = "file.pdf"
};
' Send MyPdfDocument.Stream to this method
Return New FileStreamResult(stream, "application/pdf") With {.FileDownloadName = "file.pdf"}
$vbLabelText   $csharpLabel

ASP.NET PDFエクスポート

byte [] Binary = MyPdfDocument.BinaryData;
Response.Clear();
Response.ContentType = "application/octet-stream";
Context.Response.OutputStream.Write(Binary, 0, Binary.Length);
Response.Flush();      
byte [] Binary = MyPdfDocument.BinaryData;
Response.Clear();
Response.ContentType = "application/octet-stream";
Context.Response.OutputStream.Write(Binary, 0, Binary.Length);
Response.Flush();      
Dim Binary() As Byte = MyPdfDocument.BinaryData
Response.Clear()
Response.ContentType = "application/octet-stream"
Context.Response.OutputStream.Write(Binary, 0, Binary.Length)
Response.Flush()
$vbLabelText   $csharpLabel
チャクニット・ビン
ソフトウェアエンジニア
ChaknithはIronXLとIronBarcodeで作業しています。彼はC#と.NETに深い専門知識を持ち、ソフトウェアの改善と顧客サポートを支援しています。ユーザーとの対話から得た彼の洞察は、より良い製品、文書、および全体的な体験に貢献しています。