IRONSOFTWAREHOME
Backgrounds & Foregrounds
import {PdfDocument} from "@ironsoftware/ironpdf";

(async () => {
// Render a URL as a PDF
    const pdf = await PdfDocument.fromUrl("https://www.wikipedia.org/");

    // Add a background PDF
    const bgpdf = await PdfDocument.open("MyBackground.pdf");
    await pdf.addBackgroundFromAnotherPdf(bgpdf);

    // Add a foreground overlay PDF to the first page
    const fgpdf = await PdfDocument.open("MyForeground.pdf");
    await pdf.addForegroundFromAnotherPdf(fgpdf, 0, 0);
    
    // Save the merged PDF to a file
    await pdf.saveAs("Complete.pdf");
})();
NuGet Download
Install-Package @ironsoftware/ironpdf
Backgrounds & Foregrounds

Backgrounds & Foregrounds

You can easily add a background or foreground overlay to either a newly rendered or an existing PDF document.

In the code example below, we begin by rendering a PDF from a specified URL. This PDF serves as the base document. Next, we open another PDF document named MyBackground.pdf to use as a background layer.

To add a background, simply pass the background PDF to the addBackgroundFromAnotherPdf method. This action effectively positions the content of MyBackground.pdf behind the content of the URL-rendered PDF.

Additionally, we open another PDF document named MyForeground.pdf to be used as a foreground overlay. To include a foreground overlay PDF on the first page (page index 0) of the existing PDF, we utilize the addForegroundFromAnotherPdf method. This overlay is then displayed on top of the existing content.

Finally, the merged PDF document, which includes the base PDF, background layer, and foreground overlay, is saved as Complete.pdf..

Explore PDF Background & Foreground Examples Here
View on GitHub

Ready to Get Started?

Version:2026.8just released

Key in blue circle

Get your free 30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge related to IronPDF Product Demo

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