ダヴィッド・ジョーンズとAgorusがIron Suiteで新たな効率を生み出す
ミラン・ヨヴァノヴィッチがIronPDFを使用
チームが製品をデモ
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に変換します。
ChromePdfRenderer
using IronPdf;
var renderer = new ChromePdfRenderer();
var pdf = renderer.RenderHtmlFileAsPdf("example.html");
pdf.SaveAs("output.pdf");
このコードは、HTMLファイルからレンダリングされた新しいPDFファイルを作成します。そのためには、まずIronPDFライブラリをインストールし、using IronPdf行を通じてプロジェクト内に含める必要があります。次に、HTMLコンテンツをPDFとしてレンダリングする機能を提供するChromePdfRendererクラスを初期化します。 このクラスは、HTMLファイルの元の品質が変換プロセスで失われないよう確保します。
using IronPdf
レンダラーがインスタンス化されたら、RenderHtmlFileAsPdfメソッドを使用して既存のHTMLファイルをPDFに変換することができます。 この例では、HTMLファイル "example.html" がメソッドに渡され、PDFオブジェクトが作成されます。 最後に、生成されたPDFを保存するためにSaveAsメソッドを使用し、希望するファイル名と場所を指定します。 このシンプルなプロセスにより、C#アプリケーションでHTMLファイルから簡単にPDFを生成することができます。
RenderHtmlFileAsPdf
SaveAs
IronPDFでHTMLファイルを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")
IronPDFを使用すると、.NETプロジェクト内で単純なHTML文字列から新しいPDFドキュメントを作成でき、C#、F#、およびVB.NETでIronPDFを使用することができます。 ChromePdfRendererクラスを使用することで、HTML文字列からレンダリングされたPDFドキュメントがピクセルパーフェクトに仕上がることを確認できます。 IronPDFの強力なHTMLからPDFへの変換機能を使用して、個々のニーズに合わせた高品質なPDFファイルを作成します。
RenderHtmlAsPdf
PdfDocument.SaveAs
詳細については、以下のコード例をご覧ください:
C#でHTML文字列をPDFに変換するための最初のステップは、IronPDFライブラリがプロジェクト内で適切にセットアップされ、動作していることを確認することです。 using IronPdfを含めることで、HTMLからPDFへの変換を行うために必要なIronPDFライブラリのクラスにアクセスできるようにします。 次の行、Installation.EnableWebSecurity = trueは概念的に、ローカルディスクアクセスやクロスオリジンリクエストを無効にするために使用され、安全な操作を保証しています。 (注:この行は例からは欠落していましたが、通常はPDFレンダリング操作を保護する設定に関係します。)
Installation.EnableWebSecurity = true
この例では、HTMLをPDFに変換することを処理するChromePdfRendererのインスタンスを作成する方法を示しています。 The RenderHtmlAsPdf method is used to convert a simple HTML string ("<h1>Hello World</h1>") into a PDF document. このドキュメントはSaveAsメソッドを使用してディスクに保存されます。
"<h1>Hello World</h1>"
高度な例では、IronPDFが画像、CSS、およびJavaScriptなどの外部アセットを含むHTMLコンテンツを処理できることを示しています。 これらのアセットをロードするために、オプションのBasePathパラメータを使用して、必要なファイルを含むディレクトリを指定します。 外部アセットを含む生成されたPDFは、同じSaveAsメソッドを使用して保存されます。 このコード例では、IronPDFが基本的および複雑なHTMLコンテンツの両方を処理できる能力を強調しており、プログラムでPDFを生成するための効率的なツールとなっています。
BasePath
IronPDFを使用してC#で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")
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
IronPDFライブラリを使用することで、ASP.NETウェブページは、Form_Loadイベントに1行のコードを追加するだけでHTMLの代わりにPDFにレンダリングできます。
Form_Load
この例は、IronPDFがどのようにして複雑なデータ駆動のPDFを生成するかを示しており、最初にHTMLとして設計およびテストされることでシンプルになります。
IronPDFのASPXからPDFへの変換機能では、ASPXページ内で1つのメソッドを呼び出し、HTMLの代わりにPDFを返すことができます。
PDFを「ブラウザ内表示」にするか、ファイルダウンロードとして動作するようにコーディングすることができます。
IronPDFでASPXページをPDFとしてレンダリングする方法を学ぶ
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");
IRON VB CONVERTER ERROR developers@ironsoftware.com
IronPDFは、開発者にとってできるだけ柔軟であることを目指しています。
このC# PDF生成チュートリアル例では、内部機能を自動化するAPIを提供することと、制御を可能にするAPIを提供することのバランスを示します。
IronPDFは、ページサイズ、ページマージン、ヘッダー/フッターの内容、コンテンツのスケーリング、CSSルールセット、JavaScriptの実行を含む、生成されたPDFファイルの多くのカスタマイズをサポートしています。
開発者がChromeがウェブページをPDFに変換する方法を制御できるようにしたいと考えています。 ChromePdfRendererクラス概要がお使いいただけます。
ChromePdfRendererクラスで利用可能な設定の例には、マージン、ヘッダー、フッター、用紙サイズ、フォーム作成の設定が含まれます。
IronPDFを使用したピクセルパーフェクトな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)
This example demonstrates how the user can change PDF print options to turn a form into HTML.
IronPDF's ASPX to PDF Conversion Guide functionality has many options available for rendering HTML to PDF from a string or a file.
Two options of particular importance are:
Discover How to Convert ASPX to PDF with IronPDF
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
コンピューターにある単一の画像C:\images\example.pngを指定して、そのファイルパスと共にIronPdf.ImageToPdfConverter.ImageToPdfメソッドを呼び出すことで、素早くPDFドキュメントに変換できます。
C:\images\example.png
IronPdf.ImageToPdfConverter.ImageToPdf
ImageToPdfConverter.ImageToPdfと共にSystem.IO.Directory.EnumerateFilesを使用して、複数の画像を単一のPDFドキュメントに変換することもできます。
ImageToPdfConverter.ImageToPdf
System.IO.Directory.EnumerateFiles
To explore more about converting images to PDFs using IronPDF for enhancing your applications, or to discover the entire suite of developer tools offered by Iron Software, including IronBarcode, IronOCR, and more, visit the Iron Software website.
IronPDFで画像をPDFに変換する方法を学ぶ
using IronPdf; // Initiate PDF Renderer var renderer = new ChromePdfRenderer(); // Add a header to every page easily renderer.RenderingOptions.FirstPageNumber = 1; // use 2 if a cover page will be appended renderer.RenderingOptions.TextHeader.DrawDividerLine = true; renderer.RenderingOptions.TextHeader.CenterText = "{url}"; renderer.RenderingOptions.TextHeader.Font = IronSoftware.Drawing.FontTypes.Helvetica; renderer.RenderingOptions.TextHeader.FontSize = 12; renderer.RenderingOptions.MarginTop = 25; //create 25mm space for header // Add a footer too renderer.RenderingOptions.TextFooter.DrawDividerLine = true; renderer.RenderingOptions.TextFooter.Font = IronSoftware.Drawing.FontTypes.Arial; renderer.RenderingOptions.TextFooter.FontSize = 10; renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}"; renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}"; renderer.RenderingOptions.MarginTop = 25; //create 25mm space for footer // Mergeable fields are: // {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
Imports IronPdf ' Initiate PDF Renderer Private renderer = New ChromePdfRenderer() ' Add a header to every page easily renderer.RenderingOptions.FirstPageNumber = 1 ' use 2 if a cover page will be appended renderer.RenderingOptions.TextHeader.DrawDividerLine = True renderer.RenderingOptions.TextHeader.CenterText = "{url}" renderer.RenderingOptions.TextHeader.Font = IronSoftware.Drawing.FontTypes.Helvetica renderer.RenderingOptions.TextHeader.FontSize = 12 renderer.RenderingOptions.MarginTop = 25 'create 25mm space for header ' Add a footer too renderer.RenderingOptions.TextFooter.DrawDividerLine = True renderer.RenderingOptions.TextFooter.Font = IronSoftware.Drawing.FontTypes.Arial renderer.RenderingOptions.TextFooter.FontSize = 10 renderer.RenderingOptions.TextFooter.LeftText = "{date} {time}" renderer.RenderingOptions.TextFooter.RightText = "{page} of {total-pages}" renderer.RenderingOptions.MarginTop = 25 'create 25mm space for footer ' Mergeable fields are: ' {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title}
PDFドキュメントにヘッダーとフッターを追加する方法は2つあります。 クラシックなテキスト形式として動的データをマージするオプションで追加できます。 また、HTMLコンテンツを通じて動的ヘッダーとフッターをレンダリングできるように、より柔軟なHTML形式で追加することもできます。
今日は、PDFドキュメントにクラシックなテキストヘッダーとフッターを追加する方法を、いくつかの簡単な手順で見ていきます。 PDFドキュメントにカスタマイズしたヘッダーとフッターを追加する最初のステップは、using IronPdf;ステートメントを使用してプロジェクトにIronPDFライブラリが含まれていることを確認することです。 次に、ChromePdfRendererをインスタンス化します。これにより、HTMLコンテンツをピクセル完璧なPDFドキュメントにレンダリングする機能が提供されます。
次に、ヘッダー設定を構成します。 FirstPageNumberプロパティを使用すると、開始ページ番号を指定できます。必要に応じて表紙に対応できます。 TextHeaderプロパティを使用して、区切り線の描画、テキストの中央配置(この場合はドキュメントURL)、フォントの種類とサイズの選択、ページ上部にヘッダー用のマージンの作成など、外観をカスタマイズできます。
FirstPageNumber
TextHeader
ヘッダーを構成した後、TextFooterプロパティを使用してフッターを設定します。 ヘッダーと同様に、区切り線の描画、フォントの種類とサイズの選択、現在の日付、時刻、総ページ数を含むページ番号などの動的コンテンツを含めることができます。 最後に、フッターを収容するためにページの下部にマージンを作成します。
TextFooter
これらの手順に従うことで、PDFドキュメントに情報豊かなヘッダーとフッターを追加し、そのプロフェッショナリズムと読解性を向上させることができます。
IronPDFでヘッダーとフッターを追加する方法を発見する
using IronPdf; using System; // Instantiate Renderer var renderer = new IronPdf.ChromePdfRenderer(); // Build a footer using html to style the text // mergeable fields are: // {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title} renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter() { MaxHeight = 15, //millimeters HtmlFragment = "<center><i>{page} of {total-pages}<i></center>", DrawDividerLine = true }; // Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content. renderer.RenderingOptions.MarginBottom = 25; //mm // Build a header using an image asset // Note the use of BaseUrl to set a relative path to the assets renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter() { MaxHeight = 20, //millimeters HtmlFragment = "<img src='logo.png'>", BaseUrl = new Uri(@"C:\assets\images\").AbsoluteUri }; // Use sufficient MarginTop to ensure that the HtmlHeader does not overlap with the main PDF page content. renderer.RenderingOptions.MarginTop = 25; //mm
Imports IronPdf Imports System ' Instantiate Renderer Private renderer = New IronPdf.ChromePdfRenderer() ' Build a footer using html to style the text ' mergeable fields are: ' {page} {total-pages} {url} {date} {time} {html-title} & {pdf-title} renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter() With { .MaxHeight = 15, .HtmlFragment = "<center><i>{page} of {total-pages}<i></center>", .DrawDividerLine = True } ' Use sufficient MarginBottom to ensure that the HtmlFooter does not overlap with the main PDF page content. renderer.RenderingOptions.MarginBottom = 25 'mm ' Build a header using an image asset ' Note the use of BaseUrl to set a relative path to the assets renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With { .MaxHeight = 20, .HtmlFragment = "<img src='logo.png'>", .BaseUrl = (New Uri("C:\assets\images\")).AbsoluteUri } ' Use sufficient MarginTop to ensure that the HtmlHeader does not overlap with the main PDF page content. renderer.RenderingOptions.MarginTop = 25 'mm
HTMLヘッダーとフッターは、PDFドキュメント用の動的なヘッダーとフッターを作成するための柔軟な方法を提供します。 この方法でヘッダーとフッターを追加することにより、開発者はヘッダーとフッターの外観を完全にコントロールできます。これらは独立したHTMLドキュメントとしてレンダリングされ、それぞれ独自のアセットとスタイルシートを含むことができます。
最初に、ChromePdfRendererクラスのインスタンスを作成する必要があります。このクラスはHTMLコンテンツをピクセルパーフェクトなPDFドキュメントにレンダリングします。
次に、HtmlHeaderFooterクラスを使用してフッターを定義します。ここでMaxHeight、フッターのHTMLコンテンツ(我々の場合はページ番号を含む)、および画像解像度のための基本URLを指定します。 フッターは中央にページ情報を表示するようにスタイリングされています。
HtmlHeaderFooter
MaxHeight
フッターとPDFのメインコンテンツの重なりを避けるために、MarginBottomプロパティを使用して下マージンを設定します。 同様に、HtmlHeaderFooterクラスを使用して画像(たとえばロゴ)を含むヘッダーを作成します。 ここでは、画像アセットを含むディレクトリへのBaseUrlを設定しており、レンダリング中に適切な画像解像度を確保しています。
MarginBottom
BaseUrl
最後に、MarginTopプロパティを使用して上マージンを設定し、ヘッダーとコンテンツの重なりを防ぎます。 この例は、IronPDFを使用してPDFドキュメントにカスタムHTMLヘッダーとフッターを実装するのがいかに簡単であるかを示しています。
MarginTop
IronPDFでPDFにHTMLヘッダーとフッターを追加する方法を学ぶ
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
IronPDFは、PDFの読み取りと編集のための50以上の機能を提供します。 The most popular are merging PDFs, cloning pages, and extracting text from rotated content.
IronPDFはまた、ユーザーがウォーターマークを追加したり、ページを回転させたり、注釈を追加したり、PDFページにデジタル署名をしたり、新しいPDFドキュメントを作成したり、カバーページを添付したり、PDFサイズをカスタマイズしたり、PDFファイルを生成およびフォーマットする際に多くのことができます。 さらに、PDFをJPG、BMP、JPEG、GIF、PNG、TIFFなどのすべての従来の画像ファイル形式に変換することが可能です。
C# PDF編集チュートリアルを読んで、プロジェクト要件に最適に合ったPDFドキュメントを変更するためにIronPDFをフル活用する方法を学びます。
IronPDFを使った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")
IronPDFは開発者に強力なPDFセキュリティオプションを提供し、PDFメタデータ、パスワード、権限などのカスタマイズと設定をサポートします。 IronPDFのパスワード、セキュリティ、およびメタデータオプションを使用すると、PDFドキュメントのニーズに合わせたカスタムの権限とセキュリティレベルを作成できます。 これは、SecuritySettingsおよびMetaDataクラスなどのクラスを使用して行われます。 いくつかのオプションには、PDFドキュメントを印刷不可能に制限すること、読み取り専用に設定すること、128ビット暗号化、およびPDFドキュメントのパスワード保護が含まれます。
SecuritySettings
MetaData
カスタムメタデータの設定は、MetaDataクラスを実装してさまざまなPDFメタデータオプションにアクセスし、カスタマイズした値でそれらを設定することによって機能します。 これには、著者、キーワード、変更データなどを変更することが含まれます。 カスタムセキュリティ設定を行うには、カスタムユーザーおよびオーナーパスワードの設定、印刷権限の設定、読み取り専用モードの設定などがあります。
var pdf = PdfDocument.FromFile("encrypted.pdf", "password");
System.Collections.Generic.List<string> 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.metadataField(例: pdf.MetaData.Keywords)を使用し、そこに新しい値を割り当てるだけです。 タイトルやキーワードなどのメタデータフィールドは文字列値を受け取り、ModifiedDataフィールドはdatetime値を受け取ります。
pdf.MetaData.Keys
RemoveMetaDataKey
pdf.MetaData.metadataField
pdf.MetaData.Keywords
次に、SecuritySettingsクラスを使用して新しいセキュリティ設定を行いました。 ご覧の通り、ここで設定できるさまざまな設定があります。 これにより、作業するPDFドキュメントごとに権限とセキュリティレベルを完全に制御できます。 これらの設定にアクセスするには、pdf.SecuritySettingsを使用した後に、調整したい設定を指定するだけです。例えば、MakePdfDocumentReadOnlyメソッドはPDFドキュメントを読み取り専用にし、128ビットで内容を暗号化します。 SecuritySettingsのその他のオプションには以下が含まれます:
pdf.SecuritySettings
MakePdfDocumentReadOnly
カスタムメタデータ、パスワード、およびセキュリティ設定をPDFドキュメントに設定したら、pdf.SaveAsメソッドを使用してPDFを指定された場所に保存します。
pdf.SaveAs
IronPDFで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")
IronPDFは、HTMLでPDFドキュメントに「ウォーターマーク」を追加する方法を提供します。
ApplyStampメソッドを使用すると、開発者はHTMLベースのウォーターマークをPDFファイルに追加できます。上記の例のように、ウォーターマークのHTMLコードはメソッドの最初の引数として渡されます。 ApplyStampへの追加の引数は、ウォーターマークの回転、不透明度、および位置を制御します。
ApplyStamp
ApplyStampメソッドをApplyWatermarkメソッドの代わりに使用して、ウォーターマークの配置をより詳細に制御します。 例えば、ApplyStampを使用して:
ApplyWatermark
PdfDocument
プロジェクトにIronPDFライブラリをインストールしていることを確認してください。 詳細な手順についてはIronPDF NuGetパッケージページをご覧ください。
コードの説明:
IronPdf
PdfDocument.FromFile
rotationDegrees
left
top
opacity
pageRange
結論として、IronPDFのApplyStampメソッドは、HTMLを使用したPDFドキュメントのウォーターマーク作成について正確な制御を提供します。 このアプローチは柔軟性があり、位置、スタイルのカスタマイズ、特定のページへのウォーターマークの適用などさまざまなカスタマイズニーズに対応します。
IronPDFを使用したカスタムウォーターマークを探索する
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")
You may want to use a specific background and foreground as you create and render your PDF documents in IronPDF. In such a case, you can use an existing or rendered PDF as the background or foreground for another PDF document. This is particularly useful for design consistency and templating.
This example shows you how to use a PDF document as the background or foreground of another PDF document.
You can do this in C# by loading or creating a multi-page PDF as an IronPdf.PdfDocument object.
IronPdf.PdfDocument
You can add backgrounds using PdfDocument.AddBackgroundPdf. For more details on background insertion methods, refer to the IronPDF.PdfDocument background documentation; it describes several background insertion methods and their overrides. This adds a background to each page of your working PDF. The background is copied from a page in another PDF document.
PdfDocument.AddBackgroundPdf
You can add foregrounds, also known as "Overlays," using PdfDocument.AddForegroundOverlayPdfToPage. For detailed information on foreground insertion methods, consult the IronPDF.PdfDocument overlay documentation.
PdfDocument.AddForegroundOverlayPdfToPage
This code illustrates how to integrate additional design elements on top of a base PDF using IronPDF. Always refer to the official documentation for more advanced techniques and additional options.
Explore our Guide on Adding Backgrounds and Foregrounds
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")
IronPDFを使用して、通常のドキュメントと同様に編集可能なPDFドキュメントを作成できます。 PdfFormクラスは、PDFドキュメント内のユーザー編集可能なフォームフィールドの集合です。 それはPDFレンダーに実装され、フォームまたは編集可能なドキュメントにすることができます。
PdfForm
この例では、IronPDFで編集可能なPDFフォームを作成する方法を示しています。
HTMLに<form>、<input>、<textarea>タグをドキュメントのパーツに追加することで、編集可能なフォーム付きのPDFを簡単に作成できます。
<form>
<input>
<textarea>
PdfDocument.Form.FindFormFieldメソッドを使用して、任意のフォームフィールドの値を読み書きできます。 フィールドの名前は、HTMLでそのフィールドに付けられた'name'属性と同じになります。
PdfDocument.Form.FindFormField
PdfDocument.Formオブジェクトは二通りの方法で使用できます:
PdfDocument.Form
上記の例では、まずIronPdfライブラリをインポートし、CreateEditablePdfDocumentメソッドを定義します。 このメソッドには、ユーザー名とコメントの入力フィールドを持つシンプルなフォームのHTML構造が含まれています。 HtmlToPdfレンダラーを使用して、このHTMLコンテンツをPDFドキュメントに変換します。
CreateEditablePdfDocument
HtmlToPdf
次にpdfDocument.Formを使用して、フォームフィールドにアクセスし、操作します。 PDFビューアでドキュメントを開くと表示されるデフォルト値を設定します。 最後に、"EditableForm.pdf"という名前でドキュメントを保存し、埋め込み編集可能フィールドを持つドキュメントを保存または共有できるようにします。
pdfDocument.Form
IronPDFのハウツーガイドで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()
PDF ドキュメントを画像に変換するには、PdfDocument オブジェクトで IronPDF の RasterizeToImageFiles メソッドを呼び出します。 PDF ドキュメントは PdfDocument.FromFile メソッドまたは利用可能な .NET Core 用のPDF生成メソッドのいずれかを使用して読み込むことができます。
RasterizeToImageFiles
RasterizeToImageFiles は PDF の各ページをラスター化された画像としてレンダリングします。 最初の引数は、各画像に使用する名前のパターンを指定します。 オプションの引数を使用して、各画像の品質と寸法をカスタマイズできます。 別のオプションでは、メソッドがPDFから選択したページを画像に変換することを可能にします。
注目のコード例の24行目は、ToBitMap メソッドを実演しています。 このメソッドを任意の PdfDocument オブジェクトで呼び出して、PDFをすばやく AnyBitmap オブジェクトに変換し、ファイルに保存したり必要に応じて操作できます。
ToBitMap
AnyBitmap
FromFile
IronPDFで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")
製品、統合、またはライセンスの問い合わせであろうと、Ironの製品開発チームはすべての質問に対応します。Ironと対話を始め、このライブラリをプロジェクトで最大限に活用してください。
新しいAPIの学習、専有ソフトウェア、または時間のかかるプログラミングパターンを学ぶ時間を無駄にしないでください。IronPDFには、C#用の完全にライセンス供与されたGoogle Chromeレンダリングエンジンが含まれており、JavaScript、AJAX、画像、SVG、Webフォント、およびCSSを完全にサポートしてHTMLページまたは文字列をPDFドキュメントに変換できます。
IronPDFは、C#および.NETアプリケーションとデータストレージソリューションへの自動的にPDFからコンテンツを読み取ることを可能にします。レガシーPDFドキュメントストレージからコンテンツをインポート、移行、インデックス化し、ドキュメント管理およびビジネスプロセスアプリケーションに統合します。
マージ、スプリット、PDFの編集まで、開発スキルを使って、正しいタイミングで正しいPDFを出力します。IronPDFは、成長する機能セットを手元に直接提供し、C# / VB.NETプロジェクト内で提供します。
既存のHTML、ASPXフォーム、MVCビュー、画像ファイルをPDFに直接変換するようにIronPDFを指定します。これにより、既存のアセットとウェブページを利用して、PDF形式でデータをレンダリングできます。
さらに C#, .NET, VB, ASPX, ASP.NET, .NET Core
IronPDFは、PDFの生成と操作ツールを迅速にあなたの手に届け、完全なインテリセンスサポートとVisual Studioインストーラーを備えています。Visual Studioを使用してNuGetから直接インストールするか、DLLをダウンロードするかのいずれかで、すぐにセットアップが完了します。DLLは1つだけで、依存関係はありません。
無料のコミュニティ開発ライセンス。商用ライセンスは$749から。
C# PDF ASP.NET ASPX
C#やVB.NETでの1行のコードを使用して、HTMLの代わりにASP.NET ASPXページをPDFドキュメントに変換する方法を学びます…
C# PDF HTML
多くの人にとって、これは追加のAPIを学ぶ必要がなく、複雑な設計システムをナビゲートする必要がないため、.NETからPDFファイルを生成する最も効率的な方法です。
VB PDF ASP.NET
VB.NETアプリケーションやウェブサイトでPDFドキュメントを作成および編集する方法を学びましょう。無料のチュートリアルとコード例付きです。
Ironのチームは、.NETソフトウェアコンポーネント市場で10年以上の経験があります。
私たちの開発チームにサポートチケットをオープンしてください。
コード例とチュートリアルを表示します。
開発用は無料。ライセンスは$749から。
5分でセットアップ完了。
無料で始める
トライアルフォームが正常に送信されました。試用キーはメールに届いているはずです。もし届いていない場合はsupport@ironsoftware.comにご連絡ください。
試用キーはメールに届いているはずです。もし届いていない場合はsupport@ironsoftware.comにご連絡ください。
無料で始めましょう
ウォーターマークなしで本番環境でテスト。必要な場所で動作します。
完全に機能する製品を30日間利用できます。数分でセットアップして稼働します。
製品試用期間中、サポートエンジニアリングチームへのフルアクセス
ありがとうございます。ライセンシングチームと話したい場合:
試用版キーはメールにあります。もしない場合は、お問い合わせくださいsupport@ironsoftware.com
ライセンスは749ドルから。 質問がありますか? お問い合わせください。
義務のない相談を予約
下記のフォームを記入するか、sales@ironsoftware.comにメールしてください。
あなたの詳細は常に守秘されます。
30分間の個別デモを予約してください。
試用ライセンスキーがメールで送信されました。
著作権 © Iron Software 2013-2025