背景と前景
PDFドキュメントに特定の背景や前景の要素を追加するために、IronPDFはaddBackground
およびaddForeground
メソッドを提供します。 これらの方法によって、開発者はあるPDFの内容を別のPDFの背景や前景として使用することができます。 これらのメソッドは、共通のデザインテンプレートに基づいてPDFのグループを生成するのに特に有用です。
addBackground(PdfDocument backgroundPdf);
addForeground(PdfDocument foregroundPdf);
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);
// 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());
// 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の機能とドキュメントをご覧ください。