Table of Contents

Class PdfImage

Namespace
Syncfusion.Pdf.Graphics
Assembly
Syncfusion.Pdf.Portable.dll

Represents the base class for images.

public abstract class PdfImage : PdfShapeElement
Inheritance
PdfImage
Derived
Inherited Members

Constructors

PdfImage()

protected PdfImage()

Properties

Height

public virtual int Height { get; }

Property Value

int

HorizontalResolution

public virtual float HorizontalResolution { get; }

Property Value

float

Metadata

Gets or sets Xmp metadata of the image.

public XmpMetadata Metadata { get; set; }

Property Value

XmpMetadata

Examples

//Create a new PDF document.
 PdfDocument doc = new PdfDocument();
 //Add a page to the document.
 PdfPage page = doc.Pages.Add();
 //Create PDF graphics for the page
 PdfGraphics graphics = page.Graphics;
 //Load the image from the disk with enable metadata extraction.
 PdfBitmap image = new PdfBitmap(File.OpenRead("Autumn Leaves.jpg"), true);
 //Get image metadata
 XmpMetadata metadata = image.Metadata;
 //Create custom schema.
 CustomSchema customSchema = new CustomSchema(metadata, "custom", "http://www.syncfusion.com");
 customSchema["Author"] = "Syncfusion";
 customSchema["creationDate"] = DateTime.Now.ToString();
 customSchema["DOCID"] = "SYNCSAM001";
 //Set image metadata
 image.Metadata = metadata;
 //Draw the image
 graphics.DrawImage(image, 0, 0);
 //Save and close the document
 MemoryStream stream = new MemoryStream();
 doc.Save(stream);
 //Close the document.
 doc.Close(true);
'Create a new PDF document.
Dim doc As New PdfDocument()
'Add a page to the document.
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image from the disk with enable metadata extraction.
Dim image As New PdfBitmap(File.OpenRead("Autumn Leaves.jpg"), true)
'Get image metadata
 Dim metadata As XmpMetadata = image.Metadata
 //Create custom schema.
 Dim customSchema As New CustomSchema(metadata, "custom", "http://www.syncfusion.com")
 customSchema("Author") = "Syncfusion"
 customSchema("creationDate") = DateTime.Now.ToString()
 customSchema("DOCID") = "SYNCSAM001"
 'Set image metadata
 image.Metadata = metadata
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document.
Dim ms As New MemoryStream()
doc.Save(stream)
'Close the document.
doc.Close(True)

PhysicalDimension

public virtual SizeF PhysicalDimension { get; }

Property Value

SizeF

VerticalResolution

public virtual float VerticalResolution { get; }

Property Value

float

Width

public virtual int Width { get; }

Property Value

int

Methods

DrawInternal(PdfGraphics)

Draws an element on the Graphics.

protected override void DrawInternal(PdfGraphics graphics)

Parameters

graphics PdfGraphics

Graphics context where the element should be printed.

FromStream(Stream)

Creates PdfImage from stream.

public static PdfImage FromStream(Stream stream)

Parameters

stream Stream

The stream.

Returns

PdfImage

Returns a created PdfImage object.

GetBoundsInternal()

Gets bounds of image.

protected override RectangleF GetBoundsInternal()

Returns

RectangleF

Bounds of image.

Remarks

The DPI is standard, not image DPI.

GetPixelSize(float, float)

Calculates the width and height of the image.

protected static SizeF GetPixelSize(float width, float height)

Parameters

width float

Width of the image in points.

height float

Height of the image in points.

Returns

SizeF

Calculates the width and height of the image.

GetPointSize(float, float)

Calculates size of the image in points.

protected SizeF GetPointSize(float width, float height)

Parameters

width float

Width in pixels.

height float

Height in pixels.

Returns

SizeF

size of the image in points.

GetPointSize(float, float, float, float)

Calculates size of the image in points.

protected SizeF GetPointSize(float width, float height, float horizontalResolution, float verticalResolution)

Parameters

width float

Width in pixels.

height float

Height in pixels.

horizontalResolution float

Horizontal resolution.

verticalResolution float

Vertical resolution.

Returns

SizeF

size of the image in points.

SetResolution(float, float)

Sets resolution of the image.

protected void SetResolution(float horizontalResolution, float verticalResolution)

Parameters

horizontalResolution float

Horizontal resolution of the image.

verticalResolution float

Vertical resolution of the image.