ウォーターマークなしで本番環境でテスト。
必要な場所で動作します。
完全に機能する製品を30日間利用できます。
数分でセットアップして稼働します。
製品試用期間中、サポートエンジニアリングチームへのフルアクセス
using IronPdf;
using IronPdf.Engines.Chrome;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Many rendering options to use to customize!
renderer.RenderingOptions.SetCustomPaperSizeInInches(12.5, 20);
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape;
renderer.RenderingOptions.Title = "My PDF Document Name";
renderer.RenderingOptions.EnableJavaScript = true;
renderer.RenderingOptions.WaitFor.RenderDelay(50); // in milliseconds
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen;
renderer.RenderingOptions.FitToPaperMode = FitToPaperModes.Zoom;
renderer.RenderingOptions.Zoom = 100;
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
// Supports margin customization!
renderer.RenderingOptions.MarginTop = 40; //millimeters
renderer.RenderingOptions.MarginLeft = 20; //millimeters
renderer.RenderingOptions.MarginRight = 20; //millimeters
renderer.RenderingOptions.MarginBottom = 40; //millimeters
// Can set FirstPageNumber if you have a cover page
renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a cover page will be appended
// Settings have been set, we can render:
renderer.RenderHtmlFileAsPdf("assets/wikipedia.html").SaveAs("output/my-content.pdf");
Imports IronPdf
Imports IronPdf.Engines.Chrome
' Instantiate Renderer
Dim renderer As New ChromePdfRenderer()
' Many rendering options to use to customize!
renderer.RenderingOptions.SetCustomPaperSizeInInches(12.5, 20)
renderer.RenderingOptions.PrintHtmlBackgrounds = True
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Landscape
renderer.RenderingOptions.Title = "My PDF Document Name"
renderer.RenderingOptions.EnableJavaScript = True
renderer.RenderingOptions.WaitFor.RenderDelay(50) ' in milliseconds
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Screen
renderer.RenderingOptions.FitToPaperMode = FitToPaperModes.Zoom
renderer.RenderingOptions.Zoom = 100
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
' Supports margin customization!
renderer.RenderingOptions.MarginTop = 40 ' millimeters
renderer.RenderingOptions.MarginLeft = 20 ' millimeters
renderer.RenderingOptions.MarginRight = 20 ' millimeters
renderer.RenderingOptions.MarginBottom = 40 ' millimeters
' Can set FirstPageNumber if you have a cover page
renderer.RenderingOptions.FirstPageNumber = 1 ' use 2 if a cover page will be appended
' Settings have been set, we can render:
renderer.RenderHtmlFileAsPdf("assets/wikipedia.html").SaveAs("output/my-content.pdf")
Install-Package IronPdf
IronPDFは、開発者にとってできるだけ柔軟であることを目指しています。
このC# PDF生成チュートリアル例では、内部機能を自動化するAPIを提供することと、制御を可能にするAPIを提供することのバランスを示します。
IronPDFは、ページサイズ、ページマージン、ヘッダー/フッターの内容、コンテンツのスケーリング、CSSルールセット、JavaScriptの実行を含む、生成されたPDFファイルの多くのカスタマイズをサポートしています。
開発者がChromeがウェブページをPDFに変換する方法を制御できるようにしたいと考えています。 ChromePdfRenderer クラスの概要により、これが可能になります。
ChromePdfRenderer クラスで利用可能な設定の例には、余白、ヘッダー、フッター、用紙サイズ、およびフォーム作成の設定が含まれます。
rendererを設定することが含まれます。ChromePdfRenderer クラスは、URLをPDFに変換するために使用されます。using IronPdf;
// Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = true;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from a HTML string using C#
var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
// Export to a file or Stream
pdf.SaveAs("output.pdf");
// Advanced Example with HTML Assets
// Load external html assets: Images, CSS and JavaScript.
// An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
var myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", @"C:\site\assets\");
myAdvancedPdf.SaveAs("html-with-assets.pdf");
Imports IronPdf
' Disable local disk access or cross-origin requests
Installation.EnableWebSecurity = True
' Instantiate Renderer
Dim renderer = New ChromePdfRenderer()
' Create a PDF from a HTML string using C#
Dim pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")
' Export to a file or Stream
pdf.SaveAs("output.pdf")
' Advanced Example with HTML Assets
' Load external html assets: Images, CSS and JavaScript.
' An optional BasePath 'C:\site\assets\' is set as the file location to load assets from
Dim myAdvancedPdf = renderer.RenderHtmlAsPdf("<img src='icons/iron.png'>", "C:\site\assets\")
myAdvancedPdf.SaveAs("html-with-assets.pdf")
Install-Package IronPdf
IronPDFを使用すると、.NETプロジェクト内で単純なHTML文字列から新しいPDFドキュメントを作成でき、C#、F#、およびVB.NETでIronPDFを使用することができます。 ChromePdfRenderer クラスを使用することで、HTML 文字列からレンダリングする PDF ドキュメントが、ピクセル単位で正確に表示されることが保証されます。 IronPDFの強力なHTMLからPDFへの変換機能を使用して、個々のニーズに合わせた高品質なPDFファイルを作成します。
ChromePdfRendererオブジェクトを初期化します。RenderHtmlAsPdfメソッドを使用してください。PdfDocument.SaveAsを使ってPDFを保存してください。詳細については、以下のコード例をご覧ください:
C#でHTML文字列をPDFに変換するための最初のステップは、IronPDFライブラリがプロジェクト内で適切にセットアップされ、動作していることを確認することです。 using IronPdfを含めることで、HTMLからPDFへの変換を実行するためにIronPDFライブラリから必要なクラスに確実にアクセスできるようになります。 次の行、Installation.EnableWebSecurity = trueは、概念的にはローカルディスクへのアクセスやクロスオリジンリクエストを無効化し、安全な動作を確保するために使用されます。 (Note: This line was missing from the example but usually pertains to configuration settings to secure PDF rendering operations.)
この例は、HTMLからPDFへの変換を処理するChromePdfRendererのインスタンスを作成する方法を示しています。 The RenderHtmlAsPdf method is used to convert a simple HTML string ("<h1>Hello World</h1>") into a PDF document. このドキュメントは、SaveAs 方式を使用してディスクに保存されます。
高度な例では、IronPDFが画像、CSS、およびJavaScriptなどの外部アセットを含むHTMLコンテンツを処理できることを示しています。 これらのアセットを読み込むには、オプションの BasePath パラメータを使用し、必要なファイルが含まれるディレクトリを指定します。 外部アセットを含む最終的なPDFは、同じ SaveAs メソッドを使用して保存されます。 このコード例では、IronPDFが基本的および複雑なHTMLコンテンツの両方を処理できる能力を強調しており、プログラムでPDFを生成するための効率的なツールとなっています。
using IronPdf;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from a URL or local file path
var pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/");
// Export to a file or Stream
pdf.SaveAs("url.pdf");
Imports IronPdf
' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
' Create a PDF from a URL or local file path
Private pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/")
' Export to a file or Stream
pdf.SaveAs("url.pdf")
Install-Package IronPdf
IronPDFは、既存のURLからHTMLをPDFドキュメントとしてレンダリングするのを非常に簡単にします。 JavaScript、画像、フォーム、およびCSSに対するサポートが非常に高いレベルです。
クエリ文字列変数を受け入れるASP.NET URLからPDFをレンダリングすると、デザイナーとコーダーの協力による円滑なPDF開発を促進できます。
IronPDFを使用してURLから直接PDFドキュメントを作成します。using IronPdf;
private void Form1_Load(object sender, EventArgs e)
{
//Changes the ASPX output into a pdf instead of HTML
IronPdf.AspxToPdf.RenderThisPageAsPdf();
}
Imports IronPdf
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
'Changes the ASPX output into a pdf instead of HTML
IronPdf.AspxToPdf.RenderThisPageAsPdf()
End Sub
Install-Package IronPdf
IronPDFライブラリを使用すると、Form_Loadイベントに1行のコードを追加するだけで、ASP.NET WebページをHTMLではなくPDFとしてレンダリングできます。
この例は、IronPDFがどのようにして複雑なデータ駆動のPDFを生成するかを示しており、最初にHTMLとして設計およびテストされることでシンプルになります。
IronPDFのASPXからPDFへの変換機能では、ASPXページ内で1つのメソッドを呼び出し、HTMLの代わりにPDFを返すことができます。
PDFを"ブラウザ内表示"にするか、ファイルダウンロードとして動作するようにコーディングすることができます。
using IronPdf;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from an existing HTML file using C#
var pdf = renderer.RenderHtmlFileAsPdf("example.html");
// Export to a file or Stream
pdf.SaveAs("output.pdf");
Imports IronPdf
' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
' Create a PDF from an existing HTML file using C#
Private pdf = renderer.RenderHtmlFileAsPdf("example.html")
' Export to a file or Stream
pdf.SaveAs("output.pdf")
Install-Package IronPdf
IronPDFは、HTMLファイルを高品質なPDFファイルに変換可能な強力な.NETライブラリです。 IronPDFを使用すると、わずか数行でHTMLファイルをPDFにレンダリングできます。また、最新のWeb標準をサポートしているため、生成されるPDFファイルはピクセルパーフェクトとなります。 IronPDFの強力なHTMLファイルからPDFへの変換機能は、ChromePdfRendererクラスを利用することで簡単に活用できます。このクラスは、HTMLからPDFへの変換を容易に処理します。
IronPDF;を使用しています。var renderer = new ChromePdfRenderer();var pdf = renderer.RenderHtmlFileAsPdf("example.html");。pdf.SaveAs("output.pdf");。このコードは、HTMLファイルからレンダリングされた新しいPDFファイルを作成します。これを行うには、まずChromePdfRendererクラスを初期化します。 このクラスは、HTMLファイルの元の品質が変換プロセスで失われないよう確保します。
renderer をインスタンス化すると、RenderHtmlFileAsPdf メソッドを使用して既存の HTML ファイルを PDF に変換できます。 この例では、"example.html"というHTMLファイルがメソッドに渡され、PDFオブジェクトが作成されます。 最後に、生成されたPDFを保存するには、SaveAsメソッドを使用し、希望するファイル名と保存先を指定してください。 このシンプルなプロセスにより、C#アプリケーションでHTMLファイルから簡単にPDFを生成することができます。
using IronPdf;
var PdfOptions = new IronPdf.ChromePdfRenderOptions()
{
CreatePdfFormsFromHtml = true,
EnableJavaScript = false,
Title = "My ASPX Page Rendered as a PDF"
//.. many more options available
};
AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.Attachment, "MyPdfFile.pdf", PdfOptions);
Imports IronPdf
Private PdfOptions = New IronPdf.ChromePdfRenderOptions() With {
.CreatePdfFormsFromHtml = True,
.EnableJavaScript = False,
.Title = "My ASPX Page Rendered as a PDF"
}
AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.Attachment, "MyPdfFile.pdf", PdfOptions)
Install-Package IronPdf
この例では、ユーザーが PDF の PRINT オプションを変更して、フォームを HTML に変換する方法を示しています。
IronPDFの"ASPXからPDFに変換するための多くのオプションが用意されています。
特に重要な 2 つのオプションは次のとおりです。
HTML フォームを対話型の PDF フォームとしてレンダリングするかどうかを、開発者が指定できるようにします。PDFを"ブラウザ上で"表示するか、ファイルとしてダウンロードするかを選択できるようにします。using IronPdf;
using System.IO;
using System.Linq;
// One or more images as IEnumerable. This example selects all JPEG images in a specific 'assets' folder.
var imageFiles = Directory.EnumerateFiles("assets").Where(f => f.EndsWith(".jpg") || f.EndsWith(".jpeg"));
// Converts the images to a PDF and save it.
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("composite.pdf");
// Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails
Imports IronPdf
Imports System.IO
Imports System.Linq
' One or more images as IEnumerable. This example selects all JPEG images in a specific 'assets' folder.
Private imageFiles = Directory.EnumerateFiles("assets").Where(Function(f) f.EndsWith(".jpg") OrElse f.EndsWith(".jpeg"))
' Converts the images to a PDF and save it.
ImageToPdfConverter.ImageToPdf(imageFiles).SaveAs("composite.pdf")
' Also see PdfDocument.RasterizeToImageFiles() method to flatten a PDF to images or thumbnails
Install-Package IronPdf
IronPdf.ImageToPdfConverter.ImageToPdfメソッドを呼び出すことで、素早くPDFドキュメントに変換できます:
また、CombineImagesIntoPdf と ImageToPdfConverter を組み合わせて、複数の画像を 1 つの PDF 文書に変換することもできます:
アプリケーションを向上させるためにIronPDFを使用して画像をPDFに変換することや、IronBarcode、IronOCRなど、Iron Softwareが提供する開発者ツール全スイートについて詳しくは、Iron Softwareのウェブサイトをご覧ください。
System.IO.Directory.EnumerateFiles
ImageToPdfConverter.ImageToPdf
using IronPdf;
using System;
// Step 1. Creating a PDF with editable forms from HTML using form and input tags
// Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
const string formHtml = @"
<html>
<body>
<h2>Editable PDF Form</h2>
<form>
First name: <br> <input type='text' name='firstname' value=''> <br>
Last name: <br> <input type='text' name='lastname' value=''> <br>
<br>
<p>Please specify your gender:</p>
<input type='radio' id='female' name='gender' value= 'Female'>
<label for='female'>Female</label> <br>
<br>
<input type='radio' id='male' name='gender' value='Male'>
<label for='male'>Male</label> <br>
<br>
<input type='radio' id='non-binary/other' name='gender' value='Non-Binary / Other'>
<label for='non-binary/other'>Non-Binary / Other</label>
<br>
<p>Please select all medical conditions that apply:</p>
<input type='checkbox' id='condition1' name='Hypertension' value='Hypertension'>
<label for='condition1'> Hypertension</label><br>
<input type='checkbox' id='condition2' name='Heart Disease' value='Heart Disease'>
<label for='condition2'> Heart Disease</label><br>
<input type='checkbox' id='condition3' name='Stoke' value='Stoke'>
<label for='condition3'> Stoke</label><br>
<input type='checkbox' id='condition4' name='Diabetes' value='Diabetes'>
<label for='condition4'> Diabetes</label><br>
<input type='checkbox' id='condition5' name='Kidney Disease' value='Kidney Disease'>
<label for='condition5'> Kidney Disease</label><br>
</form>
</body>
</html>";
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf");
// Step 2. Reading and Writing PDF form values.
var FormDocument = PdfDocument.FromFile("BasicForm.pdf");
// Set and Read the value of the "firstname" field
var FirstNameField = FormDocument.Form.FindFormField("firstname");
FirstNameField.Value = "Minnie";
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value);
// Set and Read the value of the "lastname" field
var LastNameField = FormDocument.Form.FindFormField("lastname");
LastNameField.Value = "Mouse";
Console.WriteLine("LastNameField value: {0}", LastNameField.Value);
FormDocument.SaveAs("FilledForm.pdf");
Imports IronPdf
Imports System
' Step 1. Creating a PDF with editable forms from HTML using form and input tags
' Radio Button and Checkbox can also be implemented with input type 'radio' and 'checkbox'
Private Const formHtml As String = "
<html>
<body>
<h2>Editable PDF Form</h2>
<form>
First name: <br> <input type='text' name='firstname' value=''> <br>
Last name: <br> <input type='text' name='lastname' value=''> <br>
<br>
<p>Please specify your gender:</p>
<input type='radio' id='female' name='gender' value= 'Female'>
<label for='female'>Female</label> <br>
<br>
<input type='radio' id='male' name='gender' value='Male'>
<label for='male'>Male</label> <br>
<br>
<input type='radio' id='non-binary/other' name='gender' value='Non-Binary / Other'>
<label for='non-binary/other'>Non-Binary / Other</label>
<br>
<p>Please select all medical conditions that apply:</p>
<input type='checkbox' id='condition1' name='Hypertension' value='Hypertension'>
<label for='condition1'> Hypertension</label><br>
<input type='checkbox' id='condition2' name='Heart Disease' value='Heart Disease'>
<label for='condition2'> Heart Disease</label><br>
<input type='checkbox' id='condition3' name='Stoke' value='Stoke'>
<label for='condition3'> Stoke</label><br>
<input type='checkbox' id='condition4' name='Diabetes' value='Diabetes'>
<label for='condition4'> Diabetes</label><br>
<input type='checkbox' id='condition5' name='Kidney Disease' value='Kidney Disease'>
<label for='condition5'> Kidney Disease</label><br>
</form>
</body>
</html>"
' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
renderer.RenderingOptions.CreatePdfFormsFromHtml = True
renderer.RenderHtmlAsPdf(formHtml).SaveAs("BasicForm.pdf")
' Step 2. Reading and Writing PDF form values.
Dim FormDocument = PdfDocument.FromFile("BasicForm.pdf")
' Set and Read the value of the "firstname" field
Dim FirstNameField = FormDocument.Form.FindFormField("firstname")
FirstNameField.Value = "Minnie"
Console.WriteLine("FirstNameField value: {0}", FirstNameField.Value)
' Set and Read the value of the "lastname" field
Dim LastNameField = FormDocument.Form.FindFormField("lastname")
LastNameField.Value = "Mouse"
Console.WriteLine("LastNameField value: {0}", LastNameField.Value)
FormDocument.SaveAs("FilledForm.pdf")
Install-Package IronPdf
IronPDFを使用して、通常のドキュメントと同様に編集可能なPDFドキュメントを作成できます。 PdfFormクラスは、PDFドキュメント内のユーザーが編集可能なフォームフィールドの集合です。 それはPDFレンダーに実装され、フォームまたは編集可能なドキュメントにすることができます。
この例では、IronPDFで編集可能なPDFフォームを作成する方法を示しています。
編集可能なフォームを含むPDFは、文書内の該当箇所に<textarea>タグを追加するだけで、HTMLから作成できます。
PdfDocument.Form.FindFormField メソッドを使用すると、あらゆるフォームフィールドの値を読み書きできます。 そのフィールドの name 属性は、HTML 内のそのフィールドに付与されます。
PdfDocument.Form オブジェクトは、次の 2 つの方法で使用できます:
上記の例では、まずCreateEditablePdfDocumentメソッドを定義します。 このメソッドには、ユーザー名とコメントの入力フィールドを持つシンプルなフォームのHTML構造が含まれています。 HtmlToPdf レンダラーを使用して、この HTML コンテンツを PDF 文書に変換します。
その後、pdfDocument.Form を使用してフォームフィールドにアクセスし、操作を行います。 PDFビューアでドキュメントを開くと表示されるデフォルト値を設定します。 最後に、"EditableForm.pdf"という名前でドキュメントを保存し、埋め込み編集可能フィールドを持つドキュメントを保存または共有できるようにします。
using IronPdf;
using IronSoftware.Drawing;
var pdf = PdfDocument.FromFile("Example.pdf");
// Extract all pages to a folder as image files
pdf.RasterizeToImageFiles(@"C:\image\folder\*.png");
// Dimensions and page ranges may be specified
pdf.RasterizeToImageFiles(@"C:\image\folder\example_pdf_image_*.jpg", 100, 80);
// Extract all pages as AnyBitmap objects
AnyBitmap[] pdfBitmaps = pdf.ToBitmap();
Imports IronPdf
Imports IronSoftware.Drawing
Private pdf = PdfDocument.FromFile("Example.pdf")
' Extract all pages to a folder as image files
pdf.RasterizeToImageFiles("C:\image\folder\*.png")
' Dimensions and page ranges may be specified
pdf.RasterizeToImageFiles("C:\image\folder\example_pdf_image_*.jpg", 100, 80)
' Extract all pages as AnyBitmap objects
Dim pdfBitmaps() As AnyBitmap = pdf.ToBitmap()
Install-Package IronPdf
PDFドキュメントを画像に変換するには、PdfDocumentメソッドを呼び出します。 PDFドキュメントは、PdfDocument.FromFileメソッド、または.NET Coreで利用可能なPDF生成メソッドのいずれかを使用して読み込むことができます。
RasterizeToImageFiles は、PDFの各ページをラスタライズされた画像としてレンダリングします。 最初の引数は、各画像に使用する名前のパターンを指定します。 オプションの引数を使用して、各画像の品質と寸法をカスタマイズできます。 別のオプションでは、メソッドがPDFから選択したページを画像に変換することを可能にします。
掲載されているコード例の24行目では、ToBitMapメソッドが示されています。 任意の PdfDocument オブジェクトに対してこのメソッドを呼び出すことで、PDF を AnyBitmap オブジェクトに素早く変換し、ファイルとして保存したり、必要に応じて操作したりすることができます。
FromFileメソッドで取り込むRasterizeToImageFilesメソッドを使ってPDFを画像に変換するusing IronPdf;
using IronPdf.Signing;
// Cryptographically sign an existing PDF in 1 line of code!
new IronPdf.Signing.PdfSignature("Iron.p12", "123456").SignPdfFile("any.pdf");
/***** Advanced example for more control *****/
// Step 1. Create a PDF
var renderer = new ChromePdfRenderer();
var doc = renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>");
// Step 2. Create a Signature.
// You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
// Read: https://helpx.adobe.com/acrobat/using/digital-ids.html
var signature = new IronPdf.Signing.PdfSignature("Iron.pfx", "123456")
{
// Step 3. Optional signing options and a handwritten signature graphic
SigningContact = "support@ironsoftware.com",
SigningLocation = "Chicago, USA",
SigningReason = "To show how to sign a PDF"
};
//Step 3. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.Sign(signature);
//Step 4. The PDF is not signed until saved to file, steam or byte array.
doc.SaveAs("signed.pdf");
Imports IronPdf
Imports IronPdf.Signing
' Cryptographically sign an existing PDF in 1 line of code!
Call (New IronPdf.Signing.PdfSignature("Iron.p12", "123456")).SignPdfFile("any.pdf")
'''*** Advanced example for more control ****
' Step 1. Create a PDF
Dim renderer = New ChromePdfRenderer()
Dim doc = renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>")
' Step 2. Create a Signature.
' You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
' Read: https://helpx.adobe.com/acrobat/using/digital-ids.html
Dim signature = New IronPdf.Signing.PdfSignature("Iron.pfx", "123456") With {
.SigningContact = "support@ironsoftware.com",
.SigningLocation = "Chicago, USA",
.SigningReason = "To show how to sign a PDF"
}
'Step 3. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.Sign(signature)
'Step 4. The PDF is not signed until saved to file, steam or byte array.
doc.SaveAs("signed.pdf")
Install-Package IronPdf
PDFドキュメントにデジタル署名をすることは、ドキュメント自体に認証を追加する方法を提供して、その整合性を保証するのに役立ちます。 IronPDFでは、新規または既存のPDFファイルに署名する際にいくつかのオプションがあります。これには、証明書でPDFドキュメントにデジタル署名する、署名の手書きのグラフィカルバージョンをPDFに追加する、証明書の画像をPDFにスタンプする、または署名欄をPDFに作成してユーザーの署名を促すことが含まれます。
このプロセスの最初のステップは、署名したいPDFをロードするか作成することです。 この例では、新しい ChromePdfRenderer インスタンスを作成します。 これは、HTMLやCSS、JavaScriptを品質を落とさずにPDFにレンダリングするために使用されるIronPDFの強力なレンダリングエンジンです。 その後、RenderHtmlAsPdf メソッドを使用して、HTML 文字列を署名可能な高品質な PDF 文書としてレンダリングします。 生成されたPDFは、doc変数に保存されます。
次に署名を作成する必要があります。 この例では、PDFドキュメントに証明書で署名します。 PdfSignature は PDF に署名するためのデジタル署名オブジェクトを表しており、署名に使用する .pfx ファイルへのパスと、このファイルにアクセスするためのパスワードが必要です。 3つのオプションのプロパティを用意しています:SigningReasonは文書が署名される理由を指定します。
次に、作成した PdfSignature オブジェクトを使用して、PDF ドキュメントに署名します。 Sign メソッドを呼び出すことで、たった1行のコードでPDFドキュメントに署名を適用できます。このメソッドを使用すると、PDFドキュメントに複数の署名証明書を適用することが可能です。
最後に、SaveAs メソッドを使用して署名済みの PDF 文書を保存します。これにより、PDF が指定されたファイル場所に保存されます。
using IronPdf;
using System.Collections.Generic;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Join Multiple Existing PDFs into a single document
var pdfs = new List<PdfDocument>();
pdfs.Add(PdfDocument.FromFile("A.pdf"));
pdfs.Add(PdfDocument.FromFile("B.pdf"));
pdfs.Add(PdfDocument.FromFile("C.pdf"));
var pdf = PdfDocument.Merge(pdfs);
pdf.SaveAs("merged.pdf");
// Add a cover page
pdf.PrependPdf(renderer.RenderHtmlAsPdf("<h1>Cover Page</h1><hr>"));
// Remove the last page from the PDF and save again
pdf.RemovePage(pdf.PageCount - 1);
pdf.SaveAs("merged.pdf");
// Copy pages 5-7 and save them as a new document.
pdf.CopyPages(4, 6).SaveAs("excerpt.pdf");
foreach (var eachPdf in pdfs)
{
eachPdf.Dispose();
}
Imports IronPdf
Imports System.Collections.Generic
' Instantiate Renderer
Private renderer = New ChromePdfRenderer()
' Join Multiple Existing PDFs into a single document
Private pdfs = New List(Of PdfDocument)()
pdfs.Add(PdfDocument.FromFile("A.pdf"))
pdfs.Add(PdfDocument.FromFile("B.pdf"))
pdfs.Add(PdfDocument.FromFile("C.pdf"))
Dim pdf = PdfDocument.Merge(pdfs)
pdf.SaveAs("merged.pdf")
' Add a cover page
pdf.PrependPdf(renderer.RenderHtmlAsPdf("<h1>Cover Page</h1><hr>"))
' Remove the last page from the PDF and save again
pdf.RemovePage(pdf.PageCount - 1)
pdf.SaveAs("merged.pdf")
' Copy pages 5-7 and save them as a new document.
pdf.CopyPages(4, 6).SaveAs("excerpt.pdf")
For Each eachPdf In pdfs
eachPdf.Dispose()
Next eachPdf
Install-Package IronPdf
IronPDFは、PDFの読み取りと編集のための50以上の機能を提供します。 最も人気があるのは、PDFの結合、ページのクローン、および回転されたコンテンツからのテキスト抽出です。
IronPDFはまた、ユーザーがウォーターマークを追加したり、ページを回転させたり、注釈を追加したり、PDFページにデジタル署名をしたり、新しいPDFドキュメントを作成したり、カバーページを添付したり、PDFサイズをカスタマイズしたり、PDFファイルを生成およびフォーマットする際に多くのことができます。 さらに、PDFをJPG、BMP、JPEG、GIF、PNG、TIFFなどのすべての従来の画像ファイル形式に変換することが可能です。
C# PDF編集チュートリアルを読んで、プロジェクト要件に最適に合ったPDFドキュメントを変更するためにIronPDFをフル活用する方法を学びます。
FromFileメソッドを使用して複数のPDFファイルをインポートするusing IronPdf;
// Open an Encrypted File, alternatively create a new PDF from Html
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");
// Get file metadata
System.Collections.Generic.List<string> metadatakeys = pdf.MetaData.Keys(); // returns {"Title", "Creator", ...}
// Remove file metadata
pdf.MetaData.RemoveMetaDataKey("Title");
metadatakeys = pdf.MetaData.Keys(); // return {"Creator", ...} // title was deleted
// Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto";
pdf.MetaData.Keywords = "SEO, Friendly";
pdf.MetaData.ModifiedDate = System.DateTime.Now;
// The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption();
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");
pdf.SecuritySettings.AllowUserAnnotations = false;
pdf.SecuritySettings.AllowUserCopyPasteContent = false;
pdf.SecuritySettings.AllowUserFormData = false;
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights;
// Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret"; // password to edit the pdf
pdf.SecuritySettings.UserPassword = "sharable"; // password to open the pdf
pdf.SaveAs("secured.pdf");
Imports System
Imports IronPdf
' Open an Encrypted File, alternatively create a new PDF from Html
Private pdf = PdfDocument.FromFile("encrypted.pdf", "password")
' Get file metadata
Private metadatakeys As System.Collections.Generic.List(Of String) = pdf.MetaData.Keys() ' returns {"Title", "Creator", ...}
' Remove file metadata
pdf.MetaData.RemoveMetaDataKey("Title")
metadatakeys = pdf.MetaData.Keys() ' return {"Creator", ...} // title was deleted
' Edit file metadata
pdf.MetaData.Author = "Satoshi Nakamoto"
pdf.MetaData.Keywords = "SEO, Friendly"
pdf.MetaData.ModifiedDate = DateTime.Now
' The following code makes a PDF read only and will disallow copy & paste and printing
pdf.SecuritySettings.RemovePasswordsAndEncryption()
pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key")
pdf.SecuritySettings.AllowUserAnnotations = False
pdf.SecuritySettings.AllowUserCopyPasteContent = False
pdf.SecuritySettings.AllowUserFormData = False
pdf.SecuritySettings.AllowUserPrinting = IronPdf.Security.PdfPrintSecurity.FullPrintRights
' Change or set the document encryption password
pdf.SecuritySettings.OwnerPassword = "top-secret" ' password to edit the pdf
pdf.SecuritySettings.UserPassword = "sharable" ' password to open the pdf
pdf.SaveAs("secured.pdf")
Install-Package IronPdf
IronPDFは開発者に強力なPDFセキュリティオプションを提供し、PDFメタデータ、パスワード、権限などのカスタマイズと設定をサポートします。 IronPDFのパスワード、セキュリティ、およびメタデータオプションを使用することで、PDF文書のニーズに合ったカスタム権限とセキュリティレベルを作成できます。 これは、SecuritySettings や MetaData といったクラスの使用によって実現されています。 いくつかのオプションには、PDFドキュメントを印刷不可能に制限すること、読み取り専用に設定すること、128ビット暗号化、およびPDFドキュメントのパスワード保護が含まれます。
カスタムメタデータを設定するには、MetaData クラスを実装して各種 PDF メタデータオプションにアクセスし、それらをカスタマイズした値で設定します。 これには、著者、キーワード、変更データなどを変更することが含まれます。 カスタムセキュリティ設定を行うには、カスタムユーザーおよびオーナーパスワードの設定、印刷権限の設定、読み取り専用モードの設定などがあります。
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");.System.Collections.Generic.List metadatakeys = pdf.MetaData.Keys; .var metadatakeys = pdf.MetaData.Keys;.pdf.MetaData.Author = "Satoshi Nakamoto";pdf.SecuritySettings.MakePdfDocumentReadOnly("secret-key");。PDFドキュメントのセキュリティをカスタマイズするために、まず既存のPDFをロードするか新しいものを作成する必要があります。 ここでは、パスワード保護された既存のPDFドキュメントをロードし、PDFドキュメントを開くために必要なパスワードを入力しました。 PDFが読み込まれると、pdf.MetaData.Keys を使用してPDFの現在のメタデータを取得します。 既存のPDFメタデータ値を削除するには、RemoveMetaDataKeyメソッドを使用してください。 新しいメタデータ値の設定を開始するには、pdf.MetaData.Keywords)を使用し、そこに新しい値を割り当ててください。 Title や Keywords などのメタデータフィールドは文字列値を、ModifiedData フィールドは日時値をそれぞれ受け取ります。
次に、SecuritySettings クラスを使用して新しいセキュリティ設定を設定しました。 ご覧の通り、ここで設定できるさまざまな設定があります。 これにより、作業するPDFドキュメントごとに権限とセキュリティレベルを完全に制御できます。 これらの設定にアクセスするには、pdf.SecuritySettings の後に調整したい設定を指定するだけです。例えば、MakePdfDocumentReadOnly メソッドを使用すると、PDF ドキュメントを読み取り専用に設定し、コンテンツを 128 ビットで暗号化します。 SecuritySettings のその他の選択肢には以下が含まれます:
AllowUserAnnotations: Controls whether or not users can annotate the PDF.AllowUserPrinting: Controls printing permissions for the document.AllowUserFormData: Sets the permissions for whether users can fill in forms.OwnerPassword: Sets the owner password for the PDF, which is used to disable or enable the other security settings.UserPassword: Sets the user password for the PDF, which must be entered in order to open or print the document.PDFドキュメントのカスタムメタデータ、パスワード、およびセキュリティ設定を設定したら、pdf.SaveAsメソッドを使用して、PDFを指定した場所に保存します。
using IronPdf;
// Stamps a Watermark onto a new or existing PDF
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center);
pdf.SaveAs("watermarked.pdf");
Imports IronPdf
' Stamps a Watermark onto a new or existing PDF
Private renderer = New ChromePdfRenderer()
Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
pdf.ApplyWatermark("<h2 style='color:red'>SAMPLE</h2>", 30, IronPdf.Editing.VerticalAlignment.Middle, IronPdf.Editing.HorizontalAlignment.Center)
pdf.SaveAs("watermarked.pdf")
Install-Package IronPdf
IronPDFは、HTMLでPDFドキュメントに"ウォーターマーク"を追加する方法を提供します。
ApplyStamp メソッドを使用すると、開発者は PDF ファイルに HTML ベースの透かしを追加できます。上記の例に示すように、透かしの HTML コードは、このメソッドの最初の引数として指定します。 ApplyStamp への追加引数により、透かしの回転、不透明度、および位置を制御できます。
透かしの配置をより細かく制御するには、ApplyWatermark メソッドの代わりに ApplyStamp メソッドを使用してください。 例えば、ApplyStamp を使用して:
Image、またはHTML透かしを追加するPdfDocumentを作成するか、既存のPdfDocumentファイルを使用してください。ApplyStampメソッドを呼び出して、PDFに透かしを追加します。SaveAsを呼び出してPDFファイルをエクスポートします。プロジェクトにIronPDFライブラリをインストールしていることを確認してください。 詳細な手順についてはIronPDF NuGetパッケージページをご覧ください。
コードの説明:
IronPdf ライブラリをインポートします。PdfDocument.FromFile を使用して、既存の PDF のファイルパスを指定し、PDF ドキュメントを作成または読み込みます。ApplyStamp メソッドは、PDFに透かしを重ねるために使用されます。 このメソッドは詳細なカスタマイズを可能にします:
rotationDegrees: 透かしの回転角度(度単位)を指定します。left および top: 左上隅からの距離で、透かしの X 座標と Y 座標を指定します。opacity: 透かしの透明度を決定します。pageRange: どのページに透かしを入れるかを指定し、多様な配置戦略を可能にします。SaveAs メソッドは、変更された PDF を新しいファイルとしてエクスポートします。結論として、IronPDFのApplyStampメソッドを使用すると、HTMLを用いてPDFドキュメントへの透かし入れを精密に制御することができます。 このアプローチは柔軟性があり、位置、スタイルのカスタマイズ、特定のページへのウォーターマークの適用などさまざまなカスタマイズニーズに対応します。
using IronPdf;
// With IronPDF, we can easily merge 2 PDF files using one as a background or foreground
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
pdf.AddBackgroundPdf(@"MyBackground.pdf");
pdf.AddForegroundOverlayPdfToPage(0, @"MyForeground.pdf", 0);
pdf.SaveAs("complete.pdf");
Imports IronPdf
' With IronPDF, we can easily merge 2 PDF files using one as a background or foreground
Private renderer = New ChromePdfRenderer()
Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
pdf.AddBackgroundPdf("MyBackground.pdf")
pdf.AddForegroundOverlayPdfToPage(0, "MyForeground.pdf", 0)
pdf.SaveAs("complete.pdf")
Install-Package IronPdf
IronPDF で PDF ドキュメントを作成してレンダリングするときに、特定の背景と前景を使用する必要がある場合があります。 このような場合、既存の PDF またはレンダリングされた PDF を別の PDF ドキュメントの背景または前景として使用できます。 これは、デザインの一貫性とテンプレート化に特に役立ちます。
この例では、PDF ドキュメントを別の PDF ドキュメントの背景または前景として使用する方法を示します。
C# では、複数ページの PDF を IronPdf.PdfDocument オブジェクトとして読み込むか作成することで、これを行うことができます。
PdfDocument.AddBackgroundPdf を使用して背景を追加できます。 背景の挿入方法の詳細については、IronPdf.PdfDocumentの背景ドキュメントを参照してください。 いくつかのバックグラウンド挿入方法とそのオーバーライドについて説明します。 これにより、作業中の PDF の各ページに背景が追加されます。 背景は別の PDF ドキュメントのページからコピーされます。
PdfDocument.AddForegroundOverlayPdfToPage を使用すると、"オーバーレイ"とも呼ばれる前景を追加できます。 フォアグラウンド挿入手法の詳細については、IronPdf.PdfDocument オーバーレイのドキュメントを参照してください。
このコードは、IronPDF を使用してベース PDF の上に追加のデザイン要素を統合する方法を示しています。 より高度なテクニックや追加オプションについては、必ず公式ドキュメントを参照してください。
製品、統合、またはライセンスの問い合わせであろうと、Ironの製品開発チームはすべての質問に対応します。Ironと対話を始め、このライブラリをプロジェクトで最大限に活用してください。
質問をする
IronPDFは、.NET Chromiumエンジンを使用してHTMLページをPDFファイルにレンダリングします。PDFを配置したり設計するために複雑なAPIを使用する必要はなく、IronPDFは標準のウェブドキュメントHTML、ASPX、JS、CSS、画像をサポートしています。
ハウツー チュートリアルを読むIronPDFは、C#および.NETアプリケーションとデータストレージソリューションへの自動的にPDFからコンテンツを読み取ることを可能にします。レガシーPDFドキュメントストレージからコンテンツをインポート、移行、インデックス化し、ドキュメント管理およびビジネスプロセスアプリケーションに統合します。
APIリファレンスを読むマージ、スプリット、PDFの編集まで、開発スキルを使って、正しいタイミングで正しいPDFを出力します。IronPDFは、成長する機能セットを手元に直接提供し、C# / VB.NETプロジェクト内で提供します。
明確なドキュメントIronPDFは、PDFの生成と操作ツールを迅速にあなたの手に届け、完全なインテリセンスサポートとVisual Studioインストーラーを備えています。Visual Studioを使用してNuGetから直接インストールするか、DLLをダウンロードするかのいずれかで、すぐにセットアップが完了します。DLLは1つだけで、依存関係はありません。
PM > Install-Package IronPDF DLL をダウンロード
C# PDF ASP.NET ASPX
C#やVB.NETでの1行のコードを使用して、HTMLの代わりにASP.NET ASPXページをPDFドキュメントに変換する方法を学びます…
JacobのASPX-To-PDFの例を見る
C# PDF HTML
多くの人にとって、これは追加のAPIを学ぶ必要がなく、複雑な設計システムをナビゲートする必要がないため、.NETからPDFファイルを生成する最も効率的な方法です。
JeanのHTML-To-PDFの例を見る
VB PDF ASP.NET
VB.NETアプリケーションやウェブサイトでPDFドキュメントを作成および編集する方法を学びましょう。無料のチュートリアルとコード例付きです。
VeronicaのVB.NET PDFチュートリアルを見る
Ironのチームは、.NETソフトウェアコンポーネント市場で10年以上の経験があります。