How to resize the PDF image watermark and set its location in C#

With the help of Spire.PDF, we can easily add the image watermark and text watermark to the PDF file from code. Starts from Spire.PDF V3.7.292, when we add the image watermarks to the PDF file, we can resize the image and set its location to make the PDF file looks tidy and beautiful by setting the property of page.BackgroundRegion. This article will focus on demonstrate how to add image watermark to an existing PDF file and reset the size and location for the image watermark in C#.

Firstly, check the original PDF file without any image watermark.

How to resize the PDF image watermark and set its location in C#

Step 1: Create a PDF document and load from file.

PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile("Sample.pdf");

Step 2: Get the first page in PDF file.

PdfPageBase page = pdf.Pages[0];

Step 3: Load the image from file and set it as background image.

Image img = Image.FromFile("logo.png")
page.BackgroundImage = img;

Step 4: Set the position and size for the background region.

page.BackgroundRegion = new RectangleF(300, 200, 80, 81);

Step 5: Save the document to file.

pdf.SaveToFile("result.pdf");

Effective screenshot after adding the image watermark and set its size and location.

How to resize the PDF image watermark and set its location in C#

Full codes:

{
    PdfDocument pdf = new PdfDocument();
    pdf.LoadFromFile("Sample.pdf");

    PdfPageBase page = pdf.Pages[0];

    Image img = Image.FromFile("logo.png");
    page.BackgroundImage = img;
   
    page.BackgroundRegion = new RectangleF(300, 200, 80, 81);

    pdf.SaveToFile("result.pdf");
}