menu

WPF

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class PdfMetafile - WPF API Reference | Syncfusion

    Show / Hide Table of Contents

    Class PdfMetafile

    Class representing metafile image

    Inheritance
    System.Object
    PdfGraphicsElement
    PdfLayoutElement
    PdfShapeElement
    PdfImage
    PdfMetafile
    Implements
    System.IDisposable
    Inherited Members
    PdfGraphicsElement.Draw(PdfGraphics)
    PdfGraphicsElement.Draw(PdfGraphics, PointF)
    PdfGraphicsElement.Draw(PdfGraphics, Single, Single)
    PdfImage.FromFile(String)
    PdfImage.FromImage(Image)
    PdfImage.FromRtf(String, Single, PdfImageType)
    PdfImage.FromRtf(String, Single, Single, PdfImageType)
    PdfImage.FromStream(Stream)
    PdfImage.GetPixelSize(Single, Single)
    PdfImage.GetPointSize(Single, Single)
    PdfImage.GetPointSize(Single, Single, Single, Single)
    PdfImage.Height
    PdfImage.HorizontalResolution
    PdfImage.m_softmask
    PdfImage.Metadata
    PdfImage.PhysicalDimension
    PdfImage.SetResolution(Single, Single)
    PdfImage.VerticalResolution
    PdfImage.Width
    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.PdfTag
    PdfShapeElement.GetBounds()
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Syncfusion.Pdf.Graphics
    Assembly: Syncfusion.Pdf.Base.dll
    Syntax
    public class PdfMetafile : PdfImage, IPdfWrapper, IDisposable
    Remarks

    This API is not supported in WinRT, Windows Phone, ASP.NET Core, Xamarin, Universal Windows Platform and Silverlight.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create the layout format
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Split text and image between pages
    format.SplitImages = true;
    format.SplitTextLines = true;
    //Create a Metafile instance
    PdfMetafile metaChart = new PdfMetafile("MetaChart.emf");
    //Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create the layout format
    Dim format As New PdfMetafileLayoutFormat()
    'Split text and image between pages
    format.SplitImages = True
    format.SplitTextLines = True
    'Create a Metafile instance
    Dim metaChart As New PdfMetafile("MetaChart.emf")
    'Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Constructors

    PdfMetafile(Metafile)

    Initializes a new instance of the PdfMetafile class with System.Drawing.Imaging.Metafile

    Declaration
    public PdfMetafile(Metafile metafile)
    Parameters
    Type Name Description
    System.Drawing.Imaging.Metafile metafile

    The metafile.

    Remarks

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

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create the layout format
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Split text and image between pages
    format.SplitImages = true;
    format.SplitTextLines = true;
    Metafile metaFile = new Metafile("MetaChart.emf");
    //Create a Metafile instance
    PdfMetafile metaChart = new PdfMetafile(metaFile);
    //Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create the layout format
    Dim format As New PdfMetafileLayoutFormat()
    'Split text and image between pages
    format.SplitImages = True
    format.SplitTextLines = True
    Dim metaFile As New Metafile("MetaChart.emf")
    'Create a Metafile instance
    Dim metaChart As New PdfMetafile(metaFile)
    'Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    PdfMetafile(Stream)

    Initializes a new instance of the PdfMetafile class from stream of the metafile

    Declaration
    public PdfMetafile(Stream stream)
    Parameters
    Type Name Description
    System.IO.Stream stream

    The stream.

    Remarks

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

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create the layout format
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Split text and image between pages
    format.SplitImages = true;
    format.SplitTextLines = true;
    byte[] data = File.ReadAllBytes("MetaChart.emf");
    //Create a Metafile instance
    PdfMetafile metaChart = new PdfMetafile(new MemoryStream(data));
    //Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create the layout format
    Dim format As New PdfMetafileLayoutFormat()
    'Split text and image between pages
    format.SplitImages = True
    format.SplitTextLines = True
    Dim data As Byte() = File.ReadAllBytes("MetaChart.emf")
    'Create a Metafile instance
    Dim metaChart As New PdfMetafile(New MemoryStream(data))
    'Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    PdfMetafile(String)

    Initializes a new instance of the PdfMetafile class with metafile path

    Declaration
    public PdfMetafile(string path)
    Parameters
    Type Name Description
    System.String path

    The metafile path.

    Remarks

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

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create the layout format
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Split text and image between pages
    format.SplitImages = true;
    format.SplitTextLines = true;
    //Create a Metafile instance
    PdfMetafile metaChart = new PdfMetafile("MetaChart.emf");
    //Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create the layout format
    Dim format As New PdfMetafileLayoutFormat()
    'Split text and image between pages
    format.SplitImages = True
    format.SplitTextLines = True
    'Create a Metafile instance
    Dim metaChart As New PdfMetafile("MetaChart.emf")
    'Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Properties

    ImageResolution

    Gets or sets the resolution of the image

    Declaration
    public int ImageResolution { get; set; }
    Property Value
    Type
    System.Int32
    Remarks

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

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create the layout format
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Split text and image between pages
    format.SplitImages = true;
    format.SplitTextLines = true;
    //Create a Metafile instance
    PdfMetafile metaChart = new PdfMetafile("MetaChart.emf");
    //Set image resolution.
    metaChart.ImageResolution = 72;
    //Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create the layout format
    Dim format As New PdfMetafileLayoutFormat()
    'Split text and image between pages
    format.SplitImages = True
    format.SplitTextLines = True
    'Create a Metafile instance
    Dim metaChart As New PdfMetafile("MetaChart.emf")
    'Set image resolution.
    metaChart.ImageResolution = 72
    'Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    PageScale

    Gets or sets the page scale.

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

    The page scale.

    Remarks

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

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create the layout format
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Split text and image between pages
    format.SplitImages = true;
    format.SplitTextLines = true;
    //Create a Metafile instance
    PdfMetafile metaChart = new PdfMetafile("MetaChart.emf");
    //Set page scale.
    metaChart.PageScale = 1.2f;
    //Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create the layout format
    Dim format As New PdfMetafileLayoutFormat()
    'Split text and image between pages
    format.SplitImages = True
    format.SplitTextLines = True
    'Create a Metafile instance
    Dim metaChart As New PdfMetafile("MetaChart.emf")
    'Set page scale.
    metaChart.PageScale = 1.2F
    'Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    PageUnit

    Gets or sets the page graphics unit.

    Declaration
    public GraphicsUnit PageUnit { get; set; }
    Property Value
    Type Description
    System.Drawing.GraphicsUnit

    The page unit.

    Remarks

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

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create the layout format
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Split text and image between pages
    format.SplitImages = true;
    format.SplitTextLines = true;
    //Create a Metafile instance
    PdfMetafile metaChart = new PdfMetafile("MetaChart.emf");
    //Set the page unit.
    metaChart.PageUnit = GraphicsUnit.Point;
    //Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create the layout format
    Dim format As New PdfMetafileLayoutFormat()
    'Split text and image between pages
    format.SplitImages = True
    format.SplitTextLines = True
    'Create a Metafile instance
    Dim metaChart As New PdfMetafile("MetaChart.emf")
    'Set the page unit.
    metaChart.PageUnit = GraphicsUnit.Point
    'Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Quality

    Gets or sets the quality of the image.

    Declaration
    public long Quality { get; set; }
    Property Value
    Type
    System.Int64
    Remarks

    When the image is stored into PDF not as a mask, you may reduce its quality, which saves the disk space.

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create the layout format
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Split text and image between pages
    format.SplitImages = true;
    format.SplitTextLines = true;
    //Create a Metafile instance
    PdfMetafile metaChart = new PdfMetafile("MetaChart.emf");
    //Set image quality.
    metaChart.Quality = 10;
    //Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create the layout format
    Dim format As New PdfMetafileLayoutFormat()
    'Split text and image between pages
    format.SplitImages = True
    format.SplitTextLines = True
    'Create a Metafile instance
    Dim metaChart As New PdfMetafile("MetaChart.emf")
    'Set image quality.
    metaChart.Quality = 10
    'Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Methods

    Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

    Declaration
    public void Dispose()
    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create the layout format
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Split text and image between pages
    format.SplitImages = true;
    format.SplitTextLines = true;
    //Create a Metafile instance
    PdfMetafile metaChart = new PdfMetafile("MetaChart.emf");
    //Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format);
    //Dispose the metafile.
     metaChart.Dispose();
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create the layout format
    Dim format As New PdfMetafileLayoutFormat()
    'Split text and image between pages
    format.SplitImages = True
    format.SplitTextLines = True
    'Create a Metafile instance
    Dim metaChart As New PdfMetafile("MetaChart.emf")
    'Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format)
    'Dispose the metafile.
    metaChart.Dispose()
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Finalize()

    Releases unmanaged resources and performs other cleanup operations before the PdfMetafile is reclaimed by garbage collection.

    Declaration
    protected void Finalize()

    Layout(PdfLayoutParams)

    Layouts the element.

    Declaration
    protected override PdfLayoutResult Layout(PdfLayoutParams param)
    Parameters
    Type Name Description
    PdfLayoutParams param

    Layout parameters.

    Returns
    Type Description
    PdfLayoutResult

    Returns lay outing results.

    Overrides
    PdfShapeElement.Layout(PdfLayoutParams)

    Layout(HtmlToPdfLayoutParams)

    Layouts the HtmlToPdf element.

    Declaration
    protected override PdfLayoutResult Layout(HtmlToPdfLayoutParams param)
    Parameters
    Type Name Description
    HtmlToPdfLayoutParams param

    Layout parameters.

    Returns
    Type Description
    PdfLayoutResult

    Returns lay outing results.

    Overrides
    PdfLayoutElement.Layout(HtmlToPdfLayoutParams)

    SetTransparency(Single, Single, PdfBlendMode, Boolean)

    Sets the transparency.

    Declaration
    public void SetTransparency(float alphaPen, float alphaBrush, PdfBlendMode blendMode, bool transparency)
    Parameters
    Type Name Description
    System.Single alphaPen

    The alpha value for pen operations.

    System.Single alphaBrush

    The alpha value for brush operations.

    PdfBlendMode blendMode

    The blend mode.

    System.Boolean transparency

    Transparency is applied or not.

    Remarks

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

    Examples
    // Create a PDF Document.
    PdfDocument doc = new PdfDocument();
    //Add pages to the document
    PdfPage page = doc.Pages.Add();
    //Create PDF graphics for the page
    PdfGraphics graphics = page.Graphics;
    //Create the layout format
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    //Split text and image between pages
    format.SplitImages = true;
    format.SplitTextLines = true;
    //Create a Metafile instance
    PdfMetafile metaChart = new PdfMetafile("MetaChart.emf");
    //Set transparency.
    metaChart.SetTransparency(0.5f, 0.5f, PdfBlendMode.Overlay, true);
    //Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format);
    //Save the document
    doc.Save("Output.pdf");
    //Close the document
    doc.Close(true);
    ' Create a PDF Document.
    Dim doc As New PdfDocument()
    'Add pages to the document
    Dim page As PdfPage = doc.Pages.Add()
    'Create PDF graphics for the page
    Dim graphics As PdfGraphics = page.Graphics
    'Create the layout format
    Dim format As New PdfMetafileLayoutFormat()
    'Split text and image between pages
    format.SplitImages = True
    format.SplitTextLines = True
    'Create a Metafile instance
    Dim metaChart As New PdfMetafile("MetaChart.emf")
    'Set transparency.
    metaChart.SetTransparency(0.5F, 0.5F, PdfBlendMode.Overlay, True)
    'Draw the Metafile in the page
    metaChart.Draw(page, PointF.Empty, format)
    'Save the document
    doc.Save("Output.pdf")
    'Close the document
    doc.Close(True)

    Implements

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