Add background to PDF

Contents
[ ]

Background images can be used to add a watermark, or other subtle design, to documents. In Aspose.PDF for .NET, each PDF document is a collection of pages and each page contains a collection of artifacts. The BackgroundArtifact class can be used to add a background image to a page object.

The following code snippet also work with Aspose.PDF.Drawing library.

The following code snippet shows how to add a background image to PDF pages using the BackgroundArtifact object with C#.

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void AddBackgroundToPdf()
{
    // The path to the documents directory
    string dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
    // Create a new document
    using (var document = new Aspose.Pdf.Document())
    {
        // Image for background artifact object
        using (var image = File.OpenRead(dataDir + "aspose-total-for-net.jpg"))
        {
            // Add a new page to document object
            Page page = document.Pages.Add();
            // Create Background Artifact object
            var background = new Aspose.Pdf.BackgroundArtifact();
            // Specify the image for background artifact object
            background.BackgroundImage = image;
            // Add background artifact to artifacts collection of page
            page.Artifacts.Add(background);
            // Save the updated document
            document.Save(dataDir + "ImageAsBackground_out.pdf");
        }
    }
}