Skip to main content

BackgroundImage

Version: 11.0

cete.dynamicpdf.pageelements.backgroundimage

BackgroundImage​

Represents a background image.

public class BackgroundImage : TaggablePageElement, ISerializable
Public Class BackgroundImage
Inherits TaggablePageElement
Implements ISerializable

Inheritance: Object → PageElement → TaggablePageElement → BackgroundImage

Implements: ISerializable

Examples​

The following example will place an image on the page making it the background for that page.

Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements

Module MyModule

Sub Main()
' Create a PDF Document
Dim MyDocument As Document = New Document

' Create a Page and add it to the document
Dim MyPage As Page = New Page
MyDocument.Pages.Add(MyPage)

' Create a background image
Dim MyBackgroundImage As BackgroundImage = New BackgroundImage("C:\MyImage.jpg")

' Place the image with in the page margins
MyBackgroundImage.UseMargins = True

' Add the background image to the page
MyPage.Elements.Add(MyBackgroundImage)

' Save the PDF
MyDocument.Draw("C:\MyDocument.pdf")

End Sub
End Module
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;

public class Example
{
public static void CreatePDF(string outputPath, string imagePath)
{
// Create a PDF Document
Document document = new Document();

// Create a page and add it to the document
Page page = new Page();
document.Pages.Add(page);

// Create a background image
BackgroundImage backgroundImage = new BackgroundImage(imagePath);

// Place the image with in the page margins
backgroundImage.UseMargins = true;

// Add the background image to the page
page.Elements.Add(backgroundImage);

//Save the PDF
document.Draw(outputPath);
}
}

Remarks​

This class can be used to place an image on the page that will be stretched to the dimensions of the page. If an image will be used more than once, please see the Image Reuse topic.

Constructors​

BackgroundImage(ImageData)​

Initializes a new instance of the BackgroundImage class.

public BackgroundImage(ImageData imageData)
Public Sub New (imageData As ImageData)

Parameters​

ImageData object containing the image data.

BackgroundImage(Stream)​

Initializes a new instance of the BackgroundImage class.

public BackgroundImage(Stream stream)
Public Sub New (stream As Stream)

Parameters​

Stream object containing the image data.

BackgroundImage(String)​

Initializes a new instance of the BackgroundImage class.

public BackgroundImage(string filePath)
Public Sub New (filePath As String)

Parameters​

The physical file path to the background image.

Properties​

BottomPadding​

Get or set the bottom padding of the background image.

public int BottomPadding { get; set; }
Public Property BottomPadding As Int32

Property Value​

Int32

ID​

Gets or sets the ID of the page element. (Inherited from PageElement)

public string ID { get; set; }
Public Property ID As String

Property Value​

String

IgnoreMargins​

Gets or sets ignore margin property. Setting false will consider the margin while placing the page element based on the RelativeTo property. (Inherited from PageElement)

public bool IgnoreMargins { get; set; }
Public Property IgnoreMargins As Boolean

Property Value​

Boolean

Examples​

The following example will place the Label in the top-left of the page with IgnoreMargin

using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;

public class Example
{
public static void CreatePDF(string outputPath)
{
// Create a PDF Document
Document document = new Document();

// Create a Page and add it to the document
Page page = new Page();
document.Pages.Add(page); // Create an Label and place it in page top left with margin ignored
Label label = new Label("I am placed in Page top left with margin ignored", 0, 0, 160, 30);
label.RelativeTo = RelativeTo.TopLeft;
label.IgnoreMargin=true; page.Elements.Add(label);

// Save the PDF
document.Draw(outputPath);
}
}

ImageData​

Get the background image's ImageData object.

public ImageData ImageData { get; }
Public Property ImageData As ImageData

Property Value​

ImageData

LeftPadding​

Get or set the left padding of the background image.

public int LeftPadding { get; set; }
Public Property LeftPadding As Int32

Property Value​

Int32

RelativeTo​

Gets and sets placement of the page element on the page. (Inherited from PageElement)

public RelativeTo RelativeTo { get; set; }
Public Property RelativeTo As RelativeTo

Property Value​

RelativeTo

Examples​

The following example will place the Label in the top-left of the page.

using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;

public class Example
{
public static void CreatePDF(string outputPath)
{
// Create a PDF Document
Document document = new Document();

// Create a Page and add it to the document
Page page = new Page();
document.Pages.Add(page); // Create an Label and place it in page top left with margin
Label label = new Label("I am placed in Page top left with margin.", 0, 0, 160, 30);
label.RelativeTo = RelativeTo.TopLeft;
page.Elements.Add(label);

// Save the PDF
document.Draw(outputPath);
}
}

RightPadding​

Get or set the right padding of the background image.

public int RightPadding { get; set; }
Public Property RightPadding As Int32

Property Value​

Int32

Tag​

Gets or sets the tag of the taggable element. (Inherited from TaggablePageElement)

public Tag Tag { get; set; }
Public Property Tag As Tag

Property Value​

Tag

TagOrder​

Gets or sets the tag order of the taggable element. (Inherited from TaggablePageElement)

public int TagOrder { get; set; }
Public Property TagOrder As Int32

Property Value​

Int32

TopPadding​

Get or set the top padding of the background image.

public int TopPadding { get; set; }
Public Property TopPadding As Int32

Property Value​

Int32

UseMargins​

Get or set a value indicating if the pages margins should be used when calculating the placement of the background image.

public bool UseMargins { get; set; }
Public Property UseMargins As Boolean

Property Value​

Boolean

Methods​

Draw(PageWriter)​

Draws the background image to the given PageWriter object.

public void Draw(PageWriter writer)
Sub Draw(writer As PageWriter)

Parameters​

PageWriter object to receive the background image's output.

Equals(Object)​

Determines whether the specified Object is equal to the current Object . (Inherited from Object)

public bool Equals(Object obj)
Function Equals(obj As Object) As Boolean

Parameters​

The Object to compare with the current Object .

Returns​

true if the specified Object is equal to the current Object ; otherwise, false.

GetHashCode()​

Serves as a hash function for a particular type. (Inherited from Object)

public int GetHashCode()
Function GetHashCode() As Integer

Returns​

A hash code for the current Object .

GetType()​

Gets the Type of the current instance. (Inherited from Object)

public Type GetType()
Function GetType() As Type

Returns​

The Type instance that represents the exact runtime type of the current instance.

ToString()​

Returns a String that represents the current Object . (Inherited from Object)

public string ToString()
Function ToString() As String

Returns​

A String that represents the current Object .

See Also​

ceTe.DynamicPDF.PageElements