menu

Document Processing

PdfImage Class - C# PDF Library API Reference | Syncfusion

    Show / Hide Table of Contents

    PdfImage Class

    Represents the base class for images and provides functionality for the PdfBitmap class

    Inheritance
    System.Object
    PdfGraphicsElement
    PdfLayoutElement
    PdfShapeElement
    PdfImage
    PdfBitmap
    PdfMetafile
    Inherited Members
    PdfGraphicsElement.Draw(PdfGraphics)
    PdfGraphicsElement.Draw(PdfGraphics, PointF)
    PdfGraphicsElement.Draw(PdfGraphics, Single, Single)
    PdfLayoutElement.add_BeginPageLayout(BeginPageLayoutEventHandler)
    PdfLayoutElement.add_EndPageLayout(EndPageLayoutEventHandler)
    PdfLayoutElement.BeginPageLayout
    PdfLayoutElement.Draw(PdfPage, PointF)
    PdfLayoutElement.Draw(PdfPage, PointF, PdfLayoutFormat)
    PdfLayoutElement.Draw(PdfPage, RectangleF)
    PdfLayoutElement.Draw(PdfPage, RectangleF, PdfLayoutFormat)
    PdfLayoutElement.Draw(PdfPage, Single, Single)
    PdfLayoutElement.Draw(PdfPage, Single, Single, PdfLayoutFormat)
    PdfLayoutElement.EndPageLayout
    PdfLayoutElement.Layout(HtmlToPdfLayoutParams)
    PdfLayoutElement.PdfTag
    PdfLayoutElement.remove_BeginPageLayout(BeginPageLayoutEventHandler)
    PdfLayoutElement.remove_EndPageLayout(EndPageLayoutEventHandler)
    PdfShapeElement.GetBounds()
    PdfShapeElement.Layout(PdfLayoutParams)
    Namespace: Syncfusion.Pdf.Graphics
    Assembly: Syncfusion.Pdf.Base.dll
    Syntax
    public abstract class PdfImage : PdfShapeElement, IPdfWrapper
    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.
    PdfImage image = PdfImage.FromFile("Autumn Leaves.jpg");
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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.
    Dim image As PdfImage = PdfImage.FromFile("Autumn Leaves.jpg")
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Constructors

    PdfImage()

    Declaration
    protected PdfImage()

    Fields

    m_softmask

    Holds mask type flag.

    Declaration
    protected bool m_softmask
    Field Value
    Type
    System.Boolean

    Properties

    Height

    Gets the height of the image in pixels (Read only).

    Declaration
    public int Height { get; }
    Property Value
    Type Description
    System.Int32

    The height of the image.

    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.
    PdfImage image = PdfImage.FromFile("Autumn Leaves.jpg");
    //Get image width.
    float imageWidth = image.Width;
    //Get image height.
    float imageHeight = image.Height;
    //Get the horizontal resolution.
    float hResolution = image.HorizontalResolution;
    //Get the vertical resolution. 
    float vResolution = image.VerticalResolution;
    //Get the image physical dimension.
    SizeF dimenstion = image.PhysicalDimension;
    Console.WriteLine("Image width :" + imageWidth);
    Console.WriteLine("Image height :" + imageHeight);
    Console.WriteLine("Horizontal resolution :" + hResolution);
    Console.WriteLine("Vertical resolution :" + vResolution);
    Console.WriteLine("Physical dimension :" + dimenstion);
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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.
    Dim image As PdfImage = PdfImage.FromFile("Autumn Leaves.jpg")
    'Get image width.
    Dim imageWidth As Single = image.Width
    'Get image height.
    Dim imageHeight As Single = image.Height
    'Get the horizontal resolution.
    Dim hResolution As Single = image.HorizontalResolution
    'Get the vertical resolution. 
    Dim vResolution As Single = image.VerticalResolution
    'Get the image physical dimension.
    Dim dimenstion As SizeF = image.PhysicalDimension
    Console.WriteLine("Image width :" + imageWidth)
    Console.WriteLine("Image height :" + imageHeight)
    Console.WriteLine("Horizontal resolution :" + hResolution)
    Console.WriteLine("Vertical resolution :" + vResolution)
    Console.WriteLine("Physical dimension :" + dimenstion)
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    HorizontalResolution

    Gets the horizontal resolution, in pixels per inch, of this Image (Read only).

    Declaration
    public float HorizontalResolution { get; }
    Property Value
    Type Description
    System.Single

    The horizontal resolution of the image.

    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.
    PdfImage image = PdfImage.FromFile("Autumn Leaves.jpg");
    //Get image width.
    float imageWidth = image.Width;
    //Get image height.
    float imageHeight = image.Height;
    //Get the horizontal resolution.
    float hResolution = image.HorizontalResolution;
    //Get the vertical resolution. 
    float vResolution = image.VerticalResolution;
    //Get the image physical dimension.
    SizeF dimenstion = image.PhysicalDimension;
    Console.WriteLine("Image width :" + imageWidth);
    Console.WriteLine("Image height :" + imageHeight);
    Console.WriteLine("Horizontal resolution :" + hResolution);
    Console.WriteLine("Vertical resolution :" + vResolution);
    Console.WriteLine("Physical dimension :" + dimenstion);
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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.
    Dim image As PdfImage = PdfImage.FromFile("Autumn Leaves.jpg")
    'Get image width.
    Dim imageWidth As Single = image.Width
    'Get image height.
    Dim imageHeight As Single = image.Height
    'Get the horizontal resolution.
    Dim hResolution As Single = image.HorizontalResolution
    'Get the vertical resolution. 
    Dim vResolution As Single = image.VerticalResolution
    'Get the image physical dimension.
    Dim dimenstion As SizeF = image.PhysicalDimension
    Console.WriteLine("Image width :" + imageWidth)
    Console.WriteLine("Image height :" + imageHeight)
    Console.WriteLine("Horizontal resolution :" + hResolution)
    Console.WriteLine("Vertical resolution :" + vResolution)
    Console.WriteLine("Physical dimension :" + dimenstion)
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Metadata

    Gets or sets Xmp metadata of the image.

    Declaration
    public XmpMetadata Metadata { get; set; }
    Property Value
    Type
    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("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 the document.
    doc.Save("Output.pdf");
    //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("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.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    PhysicalDimension

    Gets the size of the image in points (Read only).

    Declaration
    public virtual SizeF PhysicalDimension { get; }
    Property Value
    Type
    System.Drawing.SizeF
    Remarks

    This property uses HorizontalResolution and VerticalResolution for calculating the size in points.

    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.
    PdfImage image = PdfImage.FromFile("Autumn Leaves.jpg");
    //Get image width.
    float imageWidth = image.Width;
    //Get image height.
    float imageHeight = image.Height;
    //Get the horizontal resolution.
    float hResolution = image.HorizontalResolution;
    //Get the vertical resolution. 
    float vResolution = image.VerticalResolution;
    //Get the image physical dimension.
    SizeF dimenstion = image.PhysicalDimension;
    Console.WriteLine("Image width :" + imageWidth);
    Console.WriteLine("Image height :" + imageHeight);
    Console.WriteLine("Horizontal resolution :" + hResolution);
    Console.WriteLine("Vertical resolution :" + vResolution);
    Console.WriteLine("Physical dimension :" + dimenstion);
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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.
    Dim image As PdfImage = PdfImage.FromFile("Autumn Leaves.jpg")
    'Get image width.
    Dim imageWidth As Single = image.Width
    'Get image height.
    Dim imageHeight As Single = image.Height
    'Get the horizontal resolution.
    Dim hResolution As Single = image.HorizontalResolution
    'Get the vertical resolution. 
    Dim vResolution As Single = image.VerticalResolution
    'Get the image physical dimension.
    Dim dimenstion As SizeF = image.PhysicalDimension
    Console.WriteLine("Image width :" + imageWidth)
    Console.WriteLine("Image height :" + imageHeight)
    Console.WriteLine("Horizontal resolution :" + hResolution)
    Console.WriteLine("Vertical resolution :" + vResolution)
    Console.WriteLine("Physical dimension :" + dimenstion)
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    VerticalResolution

    Gets the vertical resolution, in pixels per inch, of this Image (Read only).

    Declaration
    public float VerticalResolution { get; }
    Property Value
    Type Description
    System.Single

    The vertical resolution of the image.

    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.
    PdfImage image = PdfImage.FromFile("Autumn Leaves.jpg");
    //Get image width.
    float imageWidth = image.Width;
    //Get image height.
    float imageHeight = image.Height;
    //Get the horizontal resolution.
    float hResolution = image.HorizontalResolution;
    //Get the vertical resolution. 
    float vResolution = image.VerticalResolution;
    //Get the image physical dimension.
    SizeF dimenstion = image.PhysicalDimension;
    Console.WriteLine("Image width :" + imageWidth);
    Console.WriteLine("Image height :" + imageHeight);
    Console.WriteLine("Horizontal resolution :" + hResolution);
    Console.WriteLine("Vertical resolution :" + vResolution);
    Console.WriteLine("Physical dimension :" + dimenstion);
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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.
    Dim image As PdfImage = PdfImage.FromFile("Autumn Leaves.jpg")
    'Get image width.
    Dim imageWidth As Single = image.Width
    'Get image height.
    Dim imageHeight As Single = image.Height
    'Get the horizontal resolution.
    Dim hResolution As Single = image.HorizontalResolution
    'Get the vertical resolution. 
    Dim vResolution As Single = image.VerticalResolution
    'Get the image physical dimension.
    Dim dimenstion As SizeF = image.PhysicalDimension
    Console.WriteLine("Image width :" + imageWidth)
    Console.WriteLine("Image height :" + imageHeight)
    Console.WriteLine("Horizontal resolution :" + hResolution)
    Console.WriteLine("Vertical resolution :" + vResolution)
    Console.WriteLine("Physical dimension :" + dimenstion)
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Width

    Gets the width of the image in pixels (Read only).

    Declaration
    public int Width { get; }
    Property Value
    Type Description
    System.Int32

    The width of the image.

    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.
    PdfImage image = PdfImage.FromFile("Autumn Leaves.jpg");
    //Get image width.
    float imageWidth = image.Width;
    //Get image height.
    float imageHeight = image.Height;
    //Get the horizontal resolution.
    float hResolution = image.HorizontalResolution;
    //Get the vertical resolution. 
    float vResolution = image.VerticalResolution;
    //Get the image physical dimension.
    SizeF dimenstion = image.PhysicalDimension;
    Console.WriteLine("Image width :" + imageWidth);
    Console.WriteLine("Image height :" + imageHeight);
    Console.WriteLine("Horizontal resolution :" + hResolution);
    Console.WriteLine("Vertical resolution :" + vResolution);
    Console.WriteLine("Physical dimension :" + dimenstion);
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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.
    Dim image As PdfImage = PdfImage.FromFile("Autumn Leaves.jpg")
    'Get image width.
    Dim imageWidth As Single = image.Width
    'Get image height.
    Dim imageHeight As Single = image.Height
    'Get the horizontal resolution.
    Dim hResolution As Single = image.HorizontalResolution
    'Get the vertical resolution. 
    Dim vResolution As Single = image.VerticalResolution
    'Get the image physical dimension.
    Dim dimenstion As SizeF = image.PhysicalDimension
    Console.WriteLine("Image width :" + imageWidth)
    Console.WriteLine("Image height :" + imageHeight)
    Console.WriteLine("Horizontal resolution :" + hResolution)
    Console.WriteLine("Vertical resolution :" + vResolution)
    Console.WriteLine("Physical dimension :" + dimenstion)
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Methods

    FromFile(String)

    Creates PdfImage from the specified file..

    Declaration
    public static PdfImage FromFile(string path)
    Parameters
    Type Name Description
    System.String path

    A string that contains the name of the file from which to create the PdfImage

    Returns
    Type Description
    PdfImage

    Returns a created PdfImage object.

    Remarks

    This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.

    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.
    PdfImage image = PdfImage.FromFile("Autumn Leaves.jpg");
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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.
    Dim image As PdfImage = PdfImage.FromFile("Autumn Leaves.jpg")
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    FromImage(Image)

    Creates a PdfImage from the existing System.Drawing.Image.

    Declaration
    public static PdfImage FromImage(Image image)
    Parameters
    Type Name Description
    System.Drawing.Image image

    The System.Drawing.Image from which to create the new PdfImage.

    Returns
    Type Description
    PdfImage

    Returns a created PdfImage object.

    Remarks

    This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.

    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 image from file
    Image picture = Image.FromFile("Autumn Leaves.jpg");
    //Load the image from the Image object
    PdfImage image = PdfImage.FromImage(picture);
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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 image from file
    Dim picture As Image = Image.FromFile("Autumn Leaves.jpg")
    'Load the image from the Image object
    Dim image As PdfImage = PdfImage.FromImage(picture)
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    FromRtf(String, Single, PdfImageType)

    Creates a new image instance from RTF text with the specified RTF text, width and image type

    Declaration
    public static PdfImage FromRtf(string rtf, float width, PdfImageType type)
    Parameters
    Type Name Description
    System.String rtf

    The RTF text from which to create the new PdfImage

    System.Single width

    Width of the image in points.

    PdfImageType type

    Type of the image that should be created.

    Returns
    Type Description
    PdfImage

    PdfImage containing RTF text.

    Remarks

    This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.

    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;
    string rtfData = @"{\rtf1\ansi\deff0 {\colortbl;\red0\green0\blue0;\red255\green0\blue0; }Default Color\line\cf2Red Color\line\cf1Default Color}";
    //Load image from rtf data.
    PdfImage image = PdfImage.FromRtf(rtfData, 200, PdfImageType.Bitmap)
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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
    Dim rtfData As String = "{\rtf1\ansi\deff0 {\colortbl;\red0\green0\blue0;\red255\green0\blue0; }Default Color\line\cf2Red Color\line\cf1Default Color}"
    'Load image from rtf data.
    Dim Image As PdfImage = PdfImage.FromRtf(rtfData, 200, PdfImageType.Bitmap)
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    FromRtf(String, Single, Single, PdfImageType)

    Creates a new image instance from RTF text with the specified RTF text, width, height and image type

    Declaration
    public static PdfImage FromRtf(string rtf, float width, float height, PdfImageType type)
    Parameters
    Type Name Description
    System.String rtf

    The RTF text from which to create the new PdfImage.

    System.Single width

    Width of the image in points.

    System.Single height

    Height of the image in points.

    PdfImageType type

    Type of the image that should be created.

    Returns
    Type Description
    PdfImage

    PdfImage containing RTF text.

    Remarks

    This method is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight.

    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;
    string rtfData = @"{\rtf1\ansi\deff0 {\colortbl;\red0\green0\blue0;\red255\green0\blue0; }Default Color\line\cf2Red Color\line\cf1Default Color}";
    //Load image from rtf data.
    PdfImage image = PdfImage.FromRtf(rtfData, 200, 200, PdfImageType.Bitmap)
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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
    Dim rtfData As String = "{\rtf1\ansi\deff0 {\colortbl;\red0\green0\blue0;\red255\green0\blue0; }Default Color\line\cf2Red Color\line\cf1Default Color}"
    'Load image from rtf data.
    Dim Image As PdfImage = PdfImage.FromRtf(rtfData, 200, 200, PdfImageType.Bitmap)
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    FromStream(Stream)

    Creates PdfImage from the specified data stream..

    Declaration
    public static PdfImage FromStream(Stream stream)
    Parameters
    Type Name Description
    System.IO.Stream stream

    A Stream that contains the data for this PdfImage.

    Returns
    Type Description
    PdfImage

    Returns a created PdfImage object.

    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.
    PdfImage image = PdfImage.FromStream(File.OpenRead("Autumn Leaves.jpg"));
    //Draw the image
    graphics.DrawImage(image, 0, 0);
    //Save the document.
    doc.Save("Output.pdf");
    //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.
    Dim image As PdfImage = PdfImage.FromStream(File.OpenRead("Autumn Leaves.jpg"))
    'Draw the image
    graphics.DrawImage(image, 0, 0)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    GetPixelSize(Single, Single)

    Calculates the width and height of the image.

    Declaration
    protected static SizeF GetPixelSize(float width, float height)
    Parameters
    Type Name Description
    System.Single width

    Width of the image in points.

    System.Single height

    Height of the image in points.

    Returns
    Type Description
    System.Drawing.SizeF

    Calculates the width and height of the image.

    GetPointSize(Single, Single)

    Calculates size of the image in points.

    Declaration
    protected SizeF GetPointSize(float width, float height)
    Parameters
    Type Name Description
    System.Single width

    Width in pixels.

    System.Single height

    Height in pixels.

    Returns
    Type Description
    System.Drawing.SizeF

    size of the image in points.

    GetPointSize(Single, Single, Single, Single)

    Calculates size of the image in points.

    Declaration
    protected SizeF GetPointSize(float width, float height, float horizontalResolution, float verticalResolution)
    Parameters
    Type Name Description
    System.Single width

    Width in pixels.

    System.Single height

    Height in pixels.

    System.Single horizontalResolution

    Horizontal resolution.

    System.Single verticalResolution

    Vertical resolution.

    Returns
    Type Description
    System.Drawing.SizeF

    size of the image in points.

    SetResolution(Single, Single)

    Sets resolution of the image.

    Declaration
    protected void SetResolution(float horizontalResolution, float verticalResolution)
    Parameters
    Type Name Description
    System.Single horizontalResolution

    Horizontal resolution of the image.

    System.Single verticalResolution

    Vertical resolution of the image.

    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved