menu

Document Processing

PdfHTMLTextElement Class - C# PDF Library API Reference | Syncfusion

    Show / Hide Table of Contents

    PdfHTMLTextElement Class

    Represents a HTML text area with the ability to span several pages.

    Inheritance
    System.Object
    PdfHTMLTextElement
    Namespace: Syncfusion.Pdf.Graphics
    Assembly: Syncfusion.Pdf.Base.dll
    Syntax
    public class PdfHTMLTextElement : Object
    Remarks

    This API is not supported in WinRT, Windows Phone, Xamarin, Universal Windows Platform and Silverlight. To know more about refer this link .

    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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement(htmlText, font, PdfBrushes.Black);
    htmlTextElement.TextAlign = TextAlign.Left;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    htmlTextElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement(htmlText, font, PdfBrushes.Black)
    htmlTextElement.TextAlign = TextAlign.Left
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    htmlTextElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Constructors

    PdfHTMLTextElement()

    Initializes a new instance of the PdfHTMLTextElement class.

    Declaration
    public PdfHTMLTextElement()
    Remarks

    This Constructor 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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    htmlTextElement.TextAlign = TextAlign.Left;
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    htmlTextElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    htmlTextElement.TextAlign = TextAlign.Left
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    htmlTextElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    PdfHTMLTextElement(String, PdfFont, PdfBrush)

    Initializes a new instance of the PdfHTMLTextElement class with the specified HTML text, font and brush

    Declaration
    public PdfHTMLTextElement(string htmlText, PdfFont font, PdfBrush brush)
    Parameters
    Type Name Description
    System.String htmlText

    The HTML text to be rendered in PDF.

    PdfFont font

    The font.

    PdfBrush brush

    The brush.

    Remarks

    This Constructor 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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement(htmlText, font, PdfBrushes.Black);
    htmlTextElement.TextAlign = TextAlign.Left;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    htmlTextElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement(htmlText, font, PdfBrushes.Black)
    htmlTextElement.TextAlign = TextAlign.Left
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    htmlTextElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Properties

    BackColor

    Gets or sets the background color of the HTML text element.

    Declaration
    public PdfColor BackColor { get; set; }
    Property Value
    Type Description
    PdfColor

    A PdfColor representing the background color.

    Examples
    PdfDocument document = new PdfDocument();
    PdfPage page = document.Pages.Add();
    float rectXStartPos = 50;
    float intY = 100;
    float borderSize = 5;
    RectangleF layoutRectangle = new RectangleF(rectXStartPos, intY + (borderSize / 2), 100, 100);
    string htmlText = "Hello, Syncfusion PDF!";
    PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12);
    PdfHTMLTextElement richTextElement = new PdfHTMLTextElement(htmlText, font, PdfBrushes.White);
    richTextElement.TextAlign = TextAlign.Left;
    richTextElement.BackColor = Color.Transparent;
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage
    page.Graphics.Save();
    PdfBrush backgroundBrush = new PdfSolidBrush(Color.Red);
    page.Graphics.DrawRectangle(backgroundBrush, layoutRectangle);
    page.Graphics.Restore();
    page.Graphics.Save();
    richTextElement.Draw(page, layoutRectangle, format);
    page.Graphics.Restore();
    document.Save("Output.pdf");
    document.Close(true);
    Dim document As PdfDocument = New PdfDocument
    Dim page As PdfPage = document.Pages.Add
    Dim rectXStartPos As Single = 50
    Dim intY As Single = 100
    Dim borderSize As Single = 5
    Dim layoutRectangle As RectangleF = New RectangleF(rectXStartPos, (intY + (borderSize / 2)), 100, 100)
    Dim htmlText As String = "Hello, Syncfusion PDF!"
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 12)
    Dim richTextElement As PdfHTMLTextElement = New PdfHTMLTextElement(htmlText, font, PdfBrushes.White)
    richTextElement.TextAlign = TextAlign.Left
    richTextElement.BackColor = Color.Transparent
    Dim format As PdfMetafileLayoutFormat = New PdfMetafileLayoutFormat
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    page.Graphics.Save
    Dim backgroundBrush As PdfBrush = New PdfSolidBrush(Color.Red)
    page.Graphics.DrawRectangle(backgroundBrush, layoutRectangle)
    page.Graphics.Restore
    page.Graphics.Save
    richTextElement.Draw(page, layoutRectangle, format)
    page.Graphics.Restore
    document.Save("Output.pdf")
    document.Close(true)

    Brush

    Gets or sets the brush for the text element.

    Declaration
    public PdfBrush Brush { get; set; }
    Property Value
    Type
    PdfBrush
    Remarks

    This property 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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    htmlTextElement.TextAlign = TextAlign.Left;
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Set PDF brush.
    htmlTextElement.Brush = new PdfSolidBrush(Color.Red);
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    htmlTextElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    htmlTextElement.TextAlign = TextAlign.Left
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Set PDF brush.
    htmlTextElement.Brush = New PdfSolidBrush(Color.Red)
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    htmlTextElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Font

    Gets or sets the base font for the text element.

    Declaration
    public PdfFont Font { get; set; }
    Property Value
    Type
    PdfFont
    Remarks

    This property 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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    htmlTextElement.TextAlign = TextAlign.Left;
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    htmlTextElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    htmlTextElement.TextAlign = TextAlign.Left
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    htmlTextElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    HTMLText

    Gets or sets the HTML Text.

    Declaration
    public string HTMLText { get; set; }
    Property Value
    Type
    System.String
    Remarks

    This property 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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    htmlTextElement.TextAlign = TextAlign.Left;
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    htmlTextElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    htmlTextElement.TextAlign = TextAlign.Left
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    htmlTextElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    IsNativeRenderingEnabled

    Gets or sets value that indicates whether to use native or managed code rendering.

    Declaration
    public bool IsNativeRenderingEnabled { get; set; }
    Property Value
    Type
    System.Boolean
    Remarks

    This property 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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    //Disable native rendering to avoid GDI+ error in Windows azure
    htmlTextElement.IsNativeRenderingEnabled= false;
    htmlTextElement.TextAlign = TextAlign.Left;
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Set PDF brush.
    htmlTextElement.Brush = new PdfSolidBrush(Color.Red);
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    htmlTextElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    'Disable native rendering to avoid GDI+ error in Windows azure.
    htmlTextElement.IsNativeRenderingEnabled=false;
    htmlTextElement.TextAlign = TextAlign.Left
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Set PDF brush.
    htmlTextElement.Brush = New PdfSolidBrush(Color.Red)
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    htmlTextElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    TextAlign

    Gets or sets the text alignment.

    Declaration
    public TextAlign TextAlign { get; set; }
    Property Value
    Type
    TextAlign
    Remarks

    This property 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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    //Set text align.
    htmlTextElement.TextAlign = TextAlign.Left;
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    htmlTextElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    'Set text align
    htmlTextElement.TextAlign = TextAlign.Left
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    htmlTextElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Methods

    add_BeginPageLayout(BeginPageLayoutEventHandler)

    Declaration
    public void add_BeginPageLayout(BeginPageLayoutEventHandler value)
    Parameters
    Type Name Description
    BeginPageLayoutEventHandler value

    add_EndPageLayout(EndPageLayoutEventHandler)

    Declaration
    public void add_EndPageLayout(EndPageLayoutEventHandler value)
    Parameters
    Type Name Description
    EndPageLayoutEventHandler value

    Draw(PdfGraphics, PointF, Single, Single)

    Draws the text on the graphics.

    Declaration
    public void Draw(PdfGraphics graphics, PointF location, float width, float height)
    Parameters
    Type Name Description
    PdfGraphics graphics
    System.Drawing.PointF location

    Start location on the page.

    System.Single width

    Width of the text bounds.

    System.Single height

    Height of the text bounds.

    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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    //Set text align.
    htmlTextElement.TextAlign = TextAlign.Left;
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    htmlTextElement.Draw(graphics, new PointF(0, 0), page.GetClientSize().Width, page.GetClientSize().Height);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    'Set text align
    htmlTextElement.TextAlign = TextAlign.Left
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    htmlTextElement.Draw(graphics, New PointF(0, 0), page.GetClientSize().Width, page.GetClientSize().Height)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Draw(PdfGraphics, RectangleF)

    Draws the text on the graphics.

    Declaration
    public void Draw(PdfGraphics graphics, RectangleF layoutRectangle)
    Parameters
    Type Name Description
    PdfGraphics graphics
    System.Drawing.RectangleF layoutRectangle

    RectangleF structure that specifies the bounds of the 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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files ";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    //Set text align.
    htmlTextElement.TextAlign = TextAlign.Left;
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    htmlTextElement.Draw(graphics, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height));
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET " + "library with the capability to produce Adobe PDF files "
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    'Set text align
    htmlTextElement.TextAlign = TextAlign.Left
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    htmlTextElement.Draw(graphics, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height))
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Draw(PdfPage, PointF, Single, PdfMetafileLayoutFormat)

    Draws the text on the page.

    Declaration
    public PdfLayoutResult Draw(PdfPage page, PointF location, float width, PdfMetafileLayoutFormat format)
    Parameters
    Type Name Description
    PdfPage page

    Current page where the text should be drawn.

    System.Drawing.PointF location

    Start location on the page.

    System.Single width

    Width of the text bounds.

    PdfMetafileLayoutFormat format

    Layout format.

    Returns
    Type Description
    PdfLayoutResult

    Layouting result.

    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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET library with the capability to produce Adobe PDF files";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    PdfLayoutResult result = htmlTextElement.Draw(page, new PointF(0, 0), page.GetClientSize().Width, format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET library with the capability to produce Adobe PDF files"
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    Dim result As PdfLayoutResult = htmlTextElement.Draw(page, New PointF(0, 0), page.GetClientSize().Width, format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Draw(PdfPage, PointF, Single, Single, PdfMetafileLayoutFormat)

    Draws the text on the page.

    Declaration
    public PdfLayoutResult Draw(PdfPage page, PointF location, float width, float height, PdfMetafileLayoutFormat format)
    Parameters
    Type Name Description
    PdfPage page

    Current page where the text should be drawn.

    System.Drawing.PointF location

    Start location on the page.

    System.Single width

    Width of the text bounds.

    System.Single height

    Height of the text bounds.

    PdfMetafileLayoutFormat format

    Layouting format.

    Returns
    Type Description
    PdfLayoutResult

    Layouting result.

    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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET library with the capability to produce Adobe PDF files"
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    PdfLayoutResult result = htmlTextElement.Draw(page, new PointF(0, 0), page.GetClientSize().Width, page.GetClientSize().Height, format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET library with the capability to produce Adobe PDF files"
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    Dim result As PdfLayoutResult = htmlTextElement.Draw(page, New PointF(0, 0), page.GetClientSize().Width, page.GetClientSize().Height, format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    Draw(PdfPage, RectangleF, PdfMetafileLayoutFormat)

    Draws the text on the page.

    Declaration
    public PdfLayoutResult Draw(PdfPage page, RectangleF layoutRectangle, PdfMetafileLayoutFormat format)
    Parameters
    Type Name Description
    PdfPage page

    Current page where the text should be drawn.

    System.Drawing.RectangleF layoutRectangle

    RectangleF structure that specifies the bounds of the text.

    PdfMetafileLayoutFormat format

    layout format.

    Returns
    Type Description
    PdfLayoutResult

    Layout result.

    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;
    //Set the font.
    PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 14);
    //Simple HTML content
    string htmlText = "Essential PDF is a .NET library with the capability to produce Adobe PDF files";
    //Create new PDF HTML text element.
    PdfHTMLTextElement htmlTextElement = new PdfHTMLTextElement();
    //Set html text.
    htmlTextElement.HTMLText = htmlText;
    //Set font.
    htmlTextElement.Font = font;
    //Format Layout.
    PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
    format.Layout = PdfLayoutType.Paginate;
    format.Break = PdfLayoutBreakType.FitPage;
    //Draw htmlString to PDF page.
    PdfLayoutResult result = htmlTextElement.Draw(page, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format);
    //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
    'Set the font.
    Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 14)
    'Simple HTML content
    Dim htmlText As String = "Essential PDF is a .NET library with the capability to produce Adobe PDF files"
    'Create new PDF HTML text element.
    Dim htmlTextElement As New PdfHTMLTextElement()
    'Set html text.
    htmlTextElement.HTMLText = htmlText
    'Set font.
    htmlTextElement.Font = font
    'Format Layout.
    Dim format As New PdfMetafileLayoutFormat()
    format.Layout = PdfLayoutType.Paginate
    format.Break = PdfLayoutBreakType.FitPage
    'Draw htmlString to PDF page.
    Dim result As PdfLayoutResult = htmlTextElement.Draw(page, New RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format)
    'Save the document.
    doc.Save("Output.pdf")
    'Close the document.
    doc.Close(True)

    remove_BeginPageLayout(BeginPageLayoutEventHandler)

    Declaration
    public void remove_BeginPageLayout(BeginPageLayoutEventHandler value)
    Parameters
    Type Name Description
    BeginPageLayoutEventHandler value

    remove_EndPageLayout(EndPageLayoutEventHandler)

    Declaration
    public void remove_EndPageLayout(EndPageLayoutEventHandler value)
    Parameters
    Type Name Description
    EndPageLayoutEventHandler value

    Events

    BeginPageLayout

    Event. Raises before the element should be printed on the page.

    Declaration
    public event BeginPageLayoutEventHandler BeginPageLayout
    Event Type
    Type
    BeginPageLayoutEventHandler

    EndPageLayout

    Event. Raises after the element was printed on the page.

    Declaration
    public event EndPageLayoutEventHandler EndPageLayout
    Event Type
    Type
    EndPageLayoutEventHandler
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved