IRONSOFTWAREHOME
Backgrounds & Foregrounds

import com.ironsoftware.ironpdf.*;  
import java.io.IOException;  
import java.nio.file.Paths;

// Load background and foreground PDFs from the filesystem (or create them programmatically)  
PdfDocument backgroundPdf = PdfDocument.fromFile(Paths.get("assets/MyBackground.pdf"));  
PdfDocument foregroundPdf = PdfDocument.fromFile(Paths.get("assets/MyForeground.pdf"));  
  
// Render content (HTML, URL, etc) as a PDF Document  
PdfDocument pdf = PdfDocument.renderUrlAsPdf("https://www.nuget.org/packages/IronPdf");  
  
// Add the background and foreground PDFs to the newly-rendered document.  
pdf.addBackgroundPdf(backgroundPdf);  
pdf.addForegroundPdf(foregroundPdf);  
  
pdf.saveAs(Paths.get("assets/BackgroundForegroundPdf.pdf"));
mvn install
Backgrounds & Foregrounds

Backgrounds & Foregrounds

For adding specific background or foreground elements to your PDF documents, IronPDF provides the addBackground and addForeground methods. These methods enable developers to use the content of one PDF as the background or the foreground of another PDF. These methods are particularly useful for generating groups of PDFs based on a common design template.

Since these methods work with PdfDocument objects, developers can source them from existing files using the fromFile method, or generate them anew using one of the available PDF rendering methods.

addBackground and addForeground will utilize the first page of multipage PDF documents as the background or foreground by default. To use a different page from PDFs containing multiple pages, add the index of the desired page as the second argument to the method call.

For overlaying a PDF as the background or foreground on specific pages of a working PDF, specify the pages to be overlaid using a PageSelection object. The example below shows how to do this for a single page and for a range of pages of a PDF document.

For watermarking your PDF documents, use the addWatermark method as an alternative to using addBackground for easier control over background positioning and opacity.

For more information on PDF manipulation, visit IronPDF's Features and Documentation.

Learn to Edit PDF Backgrounds & Foregrounds in Java
View on GitHub

Ready to Get Started?

Version:2026.8just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Java Maven Library for PDF
Install with Maven

Version: 2026.8

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.8.2</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.8.2
or
Java PDF JAR
Download JAR

Version: 2026.8

Manually install into your project