C#でPDFスタンパーを追加する方法
PDFにテキストや画像をスタンプすることは、既存のPDFドキュメントに追加のコンテンツをオーバーレイすることを意味します。 このコンテンツは通常"スタンプ"と呼ばれ、テキスト、画像、またはこれらの組み合わせです。 通常、ユーザーはスタンプを使用してPDFに情報、ラベル、透かし、または注釈を追加します。
- TextStamper: TextStamperはPDFに説明的なテキストを追加するためのソリューションです。 既存のドキュメントを強化したり、同じページにテキストを配置したり、他のPDFドキュメントの詳細を組み込んだり、ファイル説明や情報でファイルをカスタマイズできます。
- ImageStamper: ImageStamperはPDF内の画像を配置するためのツールです。 ファイル説明のためのロゴや、既存文書のためのイラスト、同じページや他のPDF文書の視覚要素であれ、このスタンプは画像のシームレスな統合を確保します。
- HtmlStamper: HtmlStamperはカスタマイズを次のレベルに引き上げ、HTMLコンテンツをPDFにスタンプすることができます。 これには、インタラクティブなコンテンツ、説明、ファイル仕様などの動的要素の作成が含まれ、従来のPDFカスタマイズを超えた柔軟性を提供します。
- BarcodeStamperでバーコードをスタンプ: BarcodeStamperはPDFにバーコードを追加するプロセスを簡素化します。 署名された文書、仮ファイル、またはファイル添付の追跡目的のために、このスタンプはPDFにバーコードを効率的に統合します。
- BarcodeStamperでQRコードをスタンプ: BarcodeStamperはQRコードもPDFに配置することを専門としています。 インタラクティブなコンテンツやファイル添付の作成に最適で、このスタンプを使用すると、同じページや他のPDF文書にQRコードを埋め込むことができ、追加情報への簡易アクセスを保証します。
これらの専門的なスタンプクラスは、ユーザーがさまざまな要素でPDFドキュメントを容易に強化することを促進し、基本的なテキストから精巧なHTMLデザインや動的バーコードまでを網羅します。 この記事では、主要な3つのスタンプ機能を探ります: TextStamperでテキストを追加、ImageStamperで画像を配置、およびHtmlStamperでHTMLを統合。 HTMLStamperは非常に強力で、すべてのHTML機能を使用でき、CSSスタイルを使用することで、スタンピングプロセスに別の柔軟性を追加します。
PDFにテキストと画像をスタンプする方法
- テキストと画像をスタンプするためのC#ライブラリをダウンロードします。
- 希望するスタンプクラスを作成および構成します。
- 'ApplyStamp'メソッドを使用して、PDFにスタンプを適用します。
- 'ApplyMultipleStamps'メソッドを使用して、複数のスタンプを適用します。
- スタンプを適用する特定のページを指定します。
PDFでのテキストスタンプの設定と適用
最初に、PDFでのテキストスタンプをサポートするためにTextStamperクラスからオブジェクトを作成します。 このクラスのオブジェクトには、テキストスタンパーの表示方法を指定するためのすべての設定が含まれています。 textStamperオブジェクトを 'ApplyStamp'メソッドに渡します。 Textプロパティは、PDFに表示される内容を定義します。
さらに、フォントファミリー、フォントスタイル、スタンプの配置場所を指定できます。このカスタマイズは、インタラクティブな要素、ファイル説明、および同じまたは他のPDFでの既存のコンテンツにまで及びます。 その後、実際のファイル名でPDFをエクスポートします。
設定を完了すると、指定されたファイル名で出力PDFファイルをエクスポートし、すべての設定をエンカプセル化してドキュメントにプロフェッショナルなタッチを提供します。
using IronPdf;
using IronPdf.Editing;
// Initialize the PDF renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Create a PDF document from HTML content
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create a TextStamper object and configure its properties
TextStamper textStamper = new TextStamper()
{
Text = "Text Stamper!",
FontFamily = "Bungee Spice",
UseGoogleFont = true,
FontSize = 30,
IsBold = true,
IsItalic = true,
VerticalAlignment = VerticalAlignment.Top,
};
// Apply the text stamp to the PDF document
pdf.ApplyStamp(textStamper);
// Save the modified PDF document
pdf.SaveAs("stampText.pdf");using IronPdf;
using IronPdf.Editing;
// Initialize the PDF renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Create a PDF document from HTML content
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create a TextStamper object and configure its properties
TextStamper textStamper = new TextStamper()
{
Text = "Text Stamper!",
FontFamily = "Bungee Spice",
UseGoogleFont = true,
FontSize = 30,
IsBold = true,
IsItalic = true,
VerticalAlignment = VerticalAlignment.Top,
};
// Apply the text stamp to the PDF document
pdf.ApplyStamp(textStamper);
// Save the modified PDF document
pdf.SaveAs("stampText.pdf");Imports IronPdf
Imports IronPdf.Editing
' Initialize the PDF renderer
Private renderer As New ChromePdfRenderer()
' Create a PDF document from HTML content
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create a TextStamper object and configure its properties
Private textStamper As New TextStamper() With {
.Text = "Text Stamper!",
.FontFamily = "Bungee Spice",
.UseGoogleFont = True,
.FontSize = 30,
.IsBold = True,
.IsItalic = True,
.VerticalAlignment = VerticalAlignment.Top
}
' Apply the text stamp to the PDF document
pdf.ApplyStamp(textStamper)
' Save the modified PDF document
pdf.SaveAs("stampText.pdf")PDFでの画像スタンプの設定と適用
テキストスタンパーと同様に、ImageStamperクラスからオブジェクトを作成し、その後ImageStamper Apply Methodを使用して画像をドキュメントに適用します。 このメソッドの第二パラメーターは、ページインデックスも受け入れ、スタンプを単一または複数のページに適用できるようにします。 この特定のインスタンスは、PDFの最初のページに特に画像をスタンプとして適用するようにシステムに指示できます。
すべてのページインデックスはゼロベースのインデックスに従います。
using IronPdf;
using IronPdf.Editing;
// Initialize the PDF renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Create a PDF document from HTML content
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create an ImageStamper object with the image URL
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
VerticalAlignment = VerticalAlignment.Top,
};
// Apply the image stamp to the first page of the PDF document
pdf.ApplyStamp(imageStamper, 0);
// Save the modified PDF document
pdf.SaveAs("stampImage.pdf");using IronPdf;
using IronPdf.Editing;
// Initialize the PDF renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Create a PDF document from HTML content
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create an ImageStamper object with the image URL
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
VerticalAlignment = VerticalAlignment.Top,
};
// Apply the image stamp to the first page of the PDF document
pdf.ApplyStamp(imageStamper, 0);
// Save the modified PDF document
pdf.SaveAs("stampImage.pdf");Imports IronPdf
Imports IronPdf.Editing
' Initialize the PDF renderer
Private renderer As New ChromePdfRenderer()
' Create a PDF document from HTML content
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create an ImageStamper object with the image URL
Private imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With {.VerticalAlignment = VerticalAlignment.Top}
' Apply the image stamp to the first page of the PDF document
pdf.ApplyStamp(imageStamper, 0)
' Save the modified PDF document
pdf.SaveAs("stampImage.pdf")複数スタンプの適用
ドキュメントに複数のスタンプを追加するために、スタンパーの配列を渡してIronPDFで複数のスタンプを適用する方法を使用します。 これにより、テキスト、画像、ラベルなどさまざまな要素を一度に追加することができます。 この例では、異なるテキストと配置で2つのテキストスタンパーが作成され、pdf.ApplyMultipleStampsによって両方のスタンプがPDFに適用され、最終文書はmultipleStamps.pdfとして保存されます。 この方法は、さまざまなスタンプを追加するプロセスを簡素化し、同じページ、別のPDF、または空白ページにかかわらず、PDFを複数の要素で強化する便利な方法を提供します。
using IronPdf;
using IronPdf.Editing;
// Initialize the PDF renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Create a PDF document from HTML content
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create two TextStamper objects with different configurations
TextStamper stamper1 = new TextStamper()
{
Text = "Text stamp 1",
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
};
TextStamper stamper2 = new TextStamper()
{
Text = "Text stamp 2",
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Right,
};
// Add the stampers to an array
Stamper[] stampersToApply = { stamper1, stamper2 };
// Apply multiple stamps to the PDF document
pdf.ApplyMultipleStamps(stampersToApply);
// Save the modified PDF document
pdf.SaveAs("multipleStamps.pdf");using IronPdf;
using IronPdf.Editing;
// Initialize the PDF renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Create a PDF document from HTML content
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create two TextStamper objects with different configurations
TextStamper stamper1 = new TextStamper()
{
Text = "Text stamp 1",
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Left,
};
TextStamper stamper2 = new TextStamper()
{
Text = "Text stamp 2",
VerticalAlignment = VerticalAlignment.Top,
HorizontalAlignment = HorizontalAlignment.Right,
};
// Add the stampers to an array
Stamper[] stampersToApply = { stamper1, stamper2 };
// Apply multiple stamps to the PDF document
pdf.ApplyMultipleStamps(stampersToApply);
// Save the modified PDF document
pdf.SaveAs("multipleStamps.pdf");Imports IronPdf
Imports IronPdf.Editing
' Initialize the PDF renderer
Private renderer As New ChromePdfRenderer()
' Create a PDF document from HTML content
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create two TextStamper objects with different configurations
Private stamper1 As New TextStamper() With {
.Text = "Text stamp 1",
.VerticalAlignment = VerticalAlignment.Top,
.HorizontalAlignment = HorizontalAlignment.Left
}
Private stamper2 As New TextStamper() With {
.Text = "Text stamp 2",
.VerticalAlignment = VerticalAlignment.Top,
.HorizontalAlignment = HorizontalAlignment.Right
}
' Add the stampers to an array
Private stampersToApply() As Stamper = { stamper1, stamper2 }
' Apply multiple stamps to the PDF document
pdf.ApplyMultipleStamps(stampersToApply)
' Save the modified PDF document
pdf.SaveAs("multipleStamps.pdf")PDF文書上のスタンプ位置を指定する
スタンプの配置を定義するために、3x3グリッドを水平3列、垂直3行で利用します。 横方向の配置には、左、中央、右があり、縦方向の配置には、上、中、下があります。 各位置での正確さを増すために水平および垂直オフセットを調整できます。 この概念の視覚的表現については、以下の画像を参照してください。
PDFスタンパーの位置
- HorizontalAlignment: ページに対するスタンプの水平配置。
- VerticalAlignment: ページに対するスタンプの垂直配置。
- HorizontalOffset: 水平オフセット。 デフォルト値は0で、デフォルトの単位はIronPdf.Editing.MeasurementUnit.Percentageです。 正の値は右へのオフセットを示し、負の値は左へのオフセットを示します。
- VerticalOffset: 垂直オフセット。 デフォルト値は0で、デフォルトの単位はIronPdf.Editing.MeasurementUnit.Percentageです。 正の値は下へのオフセットを示し、負の値は上へのオフセットを示します。
HorizontalOffsetおよびVerticalOffsetプロパティを指定するために、詳細な測定のために指定長クラスをインスタンス化します。 デフォルトのLengthの測定単位はパーセンテージですが、インチ、ミリメートル、センチメートル、ピクセル、ポイントなどの測定単位も使用できます。
using IronPdf.Editing;
// Create an ImageStamper object with an image URL
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
// Specify offsets for precise positioning
HorizontalOffset = new Length(10), // 10% offset to the right
VerticalOffset = new Length(10), // 10% offset downward
};using IronPdf.Editing;
// Create an ImageStamper object with an image URL
ImageStamper imageStamper = new ImageStamper(new Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg"))
{
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
// Specify offsets for precise positioning
HorizontalOffset = new Length(10), // 10% offset to the right
VerticalOffset = new Length(10), // 10% offset downward
};Imports IronPdf.Editing
' Create an ImageStamper object with an image URL
Private imageStamper As New ImageStamper(New Uri("https://ironpdf.com/img/svgs/iron-pdf-logo.svg")) With {
.HorizontalAlignment = HorizontalAlignment.Center,
.VerticalAlignment = VerticalAlignment.Top,
.HorizontalOffset = New Length(10),
.VerticalOffset = New Length(10)
}PDFでHTMLスタンプを設定して適用する
テキストと画像の両方をスタンプするために使用できる別のスタンプクラスがあります。 HtmlStamperクラスによるHTML統合は、CSSスタイリングでHTMLデザインをレンダリングし、PDF文書にスタンプします。 InnerHtmlBaseUrlプロパティは、CSSや画像ファイルなどのHTML文字列アセットのベースURLを指定するために使用されます。
HtmlStamperクラスはPDFに適用されています。 このスタンプオブジェクトには画像とテキストが含まれており、PDFにスタンプされるHTMLフラグメント内でこれらを定義できます。 すべてのJavaScript、CSSおよび画像ファイルへの外部参照は、内部のHtmlプロパティに対して相対的になります。 このコードはHTMLコンテンツで言及されている特定のファイル仕様に従って、PDFをカスタマイズすることを可能にします。 最後に、変更されたPDFがファイル名 'stampHtml.pdf'で保存されます。
using IronPdf;
using IronPdf.Editing;
// Initialize the PDF renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Create a PDF document from HTML content
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create an HtmlStamper object and configure its properties
HtmlStamper htmlStamper = new HtmlStamper()
{
Html = @"<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg'>
<h1>Iron Software</h1>",
VerticalAlignment = VerticalAlignment.Top,
};
// Apply the HTML stamp to the PDF document
pdf.ApplyStamp(htmlStamper);
// Save the modified PDF document
pdf.SaveAs("stampHtml.pdf");using IronPdf;
using IronPdf.Editing;
// Initialize the PDF renderer
ChromePdfRenderer renderer = new ChromePdfRenderer();
// Create a PDF document from HTML content
PdfDocument pdf = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>");
// Create an HtmlStamper object and configure its properties
HtmlStamper htmlStamper = new HtmlStamper()
{
Html = @"<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg'>
<h1>Iron Software</h1>",
VerticalAlignment = VerticalAlignment.Top,
};
// Apply the HTML stamp to the PDF document
pdf.ApplyStamp(htmlStamper);
// Save the modified PDF document
pdf.SaveAs("stampHtml.pdf");Imports IronPdf
Imports IronPdf.Editing
' Initialize the PDF renderer
Private renderer As New ChromePdfRenderer()
' Create a PDF document from HTML content
Private pdf As PdfDocument = renderer.RenderHtmlAsPdf("<h1>Example HTML Document!</h1>")
' Create an HtmlStamper object and configure its properties
Private htmlStamper As New HtmlStamper() With {
.Html = "<img src='https://ironpdf.com/img/svgs/iron-pdf-logo.svg'>
<h1>Iron Software</h1>",
.VerticalAlignment = VerticalAlignment.Top
}
' Apply the HTML stamp to the PDF document
pdf.ApplyStamp(htmlStamper)
' Save the modified PDF document
pdf.SaveAs("stampHtml.pdf")HTMLスタンパーオプション
上記で説明したオプションに加えて、下記のものはスタンパークラスに利用可能です。
- Opacity: スタンプを透明にすることができます。 0は完全に見えず、100は完全に不透明です。
- Rotation: 指定された0〜360度で時計回りにスタンプを回転させます。
- MaxWidth: 出力スタンプの最大幅。
- MaxHeight: 出力スタンプの最大高さ。
- MinWidth: 出力スタンプの最小幅。
- MinHeight: 出力スタンプの最小高さ。
- Hyperlink: このスタンパーのスタンプ要素にオンクリックハイパーリンクを設けます。 注: リンク(a)タグによって作成されたHTMLリンクは、最終出力でスタンピングによって保存されません。
- Scale: スタンプに百分比スケールを適用して、それを大きくまたは小さくします。 デフォルトは100(パーセント)で、効果はありません。
- IsStampBehindContent: 内容の後ろにスタンプを適用するには、trueに設定します。 内容が不透明である場合、スタンプは見えないことがあります。
- WaitFor: さまざまなイベントまたはある一定時間を待つための便利なラッパー。
- Timeout: レンダリングタイムアウトを秒単位で指定します。 デフォルト値は60です。
IronPDFのスタンパーオプションは、高度なカスタマイズを提供し、ユーザーが透明度、正確な回転、制御された寸法でPDFを強化することを可能にします。 ハイパーリンクやスケールのような機能は、インタラクティブな要素のすべてを取り入れ、ファイル仕様に従うことを容易にし、コンテンツを際立たせます。 IsStampBehindContentオプションはスタンプを戦略的に配置し、異なるフィールドではなく同じオブジェクトの一部となることを保証します。 同時に、WaitFor機能は効率的にレンダリングイベントを管理し、IronPDFはPDFのカスタマイズに原ページの回転を含む多用途のツールを提供します。
結論
結論として、IronPDFのスタンパー機能は、PDFドキュメントを強化するための多用途でユーザーフレンドリーなソリューションを提供します。 単純なテキストラベルの追加、画像の統合、HTMLとCSSの力をHtmlStamperで活用するなど、IronPDFは幅広いカスタマイズニーズに対応します。
テキストおよび画像スタンプの適用に関する実践的な例と使いやすさは、さまざまな技術的専門知識を持つユーザーにアクセスできるようにします。 不透明度、回転、縮尺を含むスタンパーオプションは、PDFを容易にカスタマイズしようとするユーザー向けの包括的なツールキットに寄与します。 IronPDFのスタンパー機能は、信頼性があり効率的なツールとして際立ち、ユーザーがPDFドキュメントを簡単に向上させることができます。
基本的および高度なニーズのためにPDFを難なく向上するIronPDFによるPDFの強化の習得は組み込みテキストおよび画像の抽出、PDFフォームの簡単な取り扱い、効率的なPDFファイルのマージまたは分割、およびカスタムヘッダーとフッターでのPDFのフォーマットなどをプログラムで含む。 質問または機能リクエストについては、IronPDFサポートチームがサポートに応じます。
よくある質問
PDFスタンピングとは何か、C#でどのように使用できるか?
PDFスタンピングは、既存のPDFドキュメントにテキスト、画像、HTMLなどのコンテンツを追加することを意味します。C#では、IronPDFのTextStamperやImageStamperのクラスを使用してこれらの要素を効率的に適用できます。
PDFカスタマイズのために利用可能なスタンパークラスは何か?
IronPDFは、TextStamper(テキスト用)、ImageStamper(画像用)、HtmlStamper(HTMLコンテンツ用)、BarcodeStamper(バーコード用およびQRコード用)など、いくつかの専門的なスタンパークラスを提供します。
C#を使用してPDFにテキストスタンプを適用するにはどうすればよいですか?
テキストスタンプを適用するには、TextStamperオブジェクトを作成し、テキストコンテンツやフォントなどのプロパティを設定してから、ApplyStampメソッドを使用してPDFに適用します。
HTMLコンテンツをPDFドキュメントに埋め込むことはできますか?
はい、IronPDFのHtmlStamperを使用すると、HTMLコンテンツをPDFドキュメントに埋め込み、動的でスタイルのある要素を追加することができます。
PDFページにスタンプの配置をどのように制御できますか?
IronPDFでは、配置を3x3グリッドシステムで制御し、水平および垂直のオフセットで正確に調整できます。
PDFスタンプのカスタマイズにはどのようなオプションがありますか?
IronPDFでは、不透明度、回転、スケーリング、ハイパーリンク、既存コンテンツの背後にスタンプをレイヤー化する機能など、PDFスタンプをカスタマイズするオプションがあります。
1つのPDFドキュメントに複数の種類のスタンプを適用する方法は?
IronPDFでは、ApplyMultipleStampsメソッドを使用して、テキストや画像などさまざまな種類のスタンプを1つのPDFドキュメントに効率的に適用します。
PDFにQRコードを追加することは可能ですか?
はい、IronPDFのBarcodeStamperを使用して、対話的および情報提供の目的でPDFにQRコードを追加できます。
PDFスタンピングにおいてスタンパー抽象クラスはどのような役割を果たしますか?
IronPDFのスタンパー抽象クラスは、スタンピング操作の共通の機能を提供し、専門的なスタンパークラスを作成するための基盤です。
C#を使用してPDFに画像スタンプを適用するにはどうすればよいですか?
ImageStamperオブジェクトを作成し、そのプロパティを設定して、'ApplyStamp'メソッドを使用し、オプションでページインデックスを指定して、PDFドキュメントに画像スタンプを適用します。
IronPDF は、PDF Stamper クラスの使用において .NET 10 をサポートしていますか?
はい、IronPDFは.NET 10と完全に互換性があります。ライブラリは.NET 10に加え、.NET 9、.NET 8、.NET Core、.NET Standard、.NET Frameworkなどの以前のバージョンもサポートしています。つまり、 TextStamper 、 ImageStamper 、 HtmlStamper 、 BarcodeStamperを含むすべてのスタンパークラスは、.NET 10プロジェクトで変更なしで動作します。






