背景と前景
特定の背景または前景要素をPDFドキュメントに追加するために、IronPDFはaddBackground
およびaddForeground
メソッドを提供しています。 これらの方法によって、開発者はあるPDFの内容を別のPDFの背景や前景として使用することができます。 これらのメソッドは、共通のデザインテンプレートに基づいてPDFのグループを生成するのに特に有用です。
addBackground(PdfDocument backgroundPdf);
addForeground(PdfDocument foregroundPdf);
これらのメソッドは PdfDocument
オブジェクトで動作するため、開発者は fromFile
メソッドを使用して既存のファイルからそれらを取得するか、利用可能なPDFレンダリングメソッドの1つを使用して新たに生成することができます。
「addBackground
」および「addForeground
」は、複数ページのPDFドキュメントの最初のページをデフォルトで背景または前景として使用します。 複数ページを含むPDFから異なるページを使用するには、メソッド呼び出しの第二引数として目的のページのインデックスを追加します。
// Use the third page of the background PDF as the background of every page
// in the working PDF
pdf.addBackground(backgroundPdf, 2);
// Use the second page of the foreground PDF as the foreground of every page
// of the working PDF
pdf.addForeground(foregroundPdf, 1);
作業中のPDFの特定のページに背景または前景としてPDFをオーバーレイする場合、オーバーレイするページを PageSelection
オブジェクトを使用して指定します。 以下の例では、PDFドキュメントの単一ページおよびページ範囲でこれを行う方法を示しています。
// Add the background to page 5 of the working PDF
pdf.addBackground(backgroundPdf, PageSelection.singlePage(6));
// Add a different background on pages 7 through 16 of the working PDF
pdf.addBackground(backgroundPdf, PageSelection.pageRange(6, 15));
// Add another background to just the first page.
pdf.addBackground(backgroundPdf, PageSelection.firstPage());
PDF ドキュメントにウォーターマークを追加するには、背景の位置や不透明度を簡単に制御するために、addBackground
を使用する代わりに addWatermark
メソッドを使用してください。
PDF操作の詳細については、以下をご覧ください。IronPdfの機能とドキュメント.