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
HorizontalResolution
public virtual float HorizontalResolution { get; }
Property Value
Metadata
Gets or sets Xmp metadata of the image.
public XmpMetadata Metadata { get; set; }
Property Value
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
Width
public virtual int Width { get; }
Property Value
Methods
DrawInternal(PdfGraphics)
Draws an element on the Graphics.
protected override void DrawInternal(PdfGraphics graphics)
Parameters
graphics
PdfGraphicsGraphics context where the element should be printed.
FromStream(Stream)
Creates PdfImage from stream.
public static PdfImage FromStream(Stream stream)
Parameters
stream
StreamThe 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
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
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
floatWidth in pixels.
height
floatHeight in pixels.
horizontalResolution
floatHorizontal resolution.
verticalResolution
floatVertical resolution.
Returns
- SizeF
size of the image in points.
SetResolution(float, float)
Sets resolution of the image.
protected void SetResolution(float horizontalResolution, float verticalResolution)