cete.dynamicpdf.pageelements.html.htmlarea
HtmlArea
- Namespace: ceTe.DynamicPDF.PageElements.Html
- Assemblies: DynamicPDF.CoreSuite.dll
Represents a HTML Area page element.
public class HtmlArea : RotatingPageElement, IArea, ICoordinate, ISerializable
Public Class HtmlArea
Inherits RotatingPageElement
Implements IArea, ICoordinate, ISerializable
Inheritance: Object → PageElement → TaggablePageElement → RotatingPageElement → HtmlArea
Implements: IArea, ICoordinate, ISerializable
Examples
This example shows simple HTML being displayed on the page.
Imports System
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.PageElements
Imports ceTe.DynamicPDF.PageElements.Html
Module MyModule
Sub Main()
' Create a PDF Document
Dim MyDocument As Document = New Document()
' Create a uri
Dim MyUri As Uri = New Uri("C:\Temp\TestPage.html")
' Create a html area
Dim MyHtmlArea As HtmlArea = New HtmlArea(MyUri, 0, 0, 500, 600)
' Create a page
Dim MyPage As Page = New Page()
' Add the html area to the page
MyPage.Elements.Add(MyHtmlArea)
' Add the page to the document
MyDocument.Pages.Add(MyPage)
' Save the PDF
MyDocument.Draw("MyOutput.pdf")
End Sub
End Module
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements.Html;
public class Example
{
public static void CreatePDF(string inputHTMLPath, string outputPath)
{
// Create a PDF Document
Document document = new Document();
// Create a Uri
Uri filePath = new Uri( inputHTMLPath );
// Create a html area
HtmlArea htmlArea = new HtmlArea(filePath, 0, 0, 500, 600);
//Create a page
Page page = new Page();
// Add the html area to the page;
page.Elements.Add(htmlArea);
// Add the page to the document
document.Pages.Add(page);
// Save the PDF
document.Draw(outputPath);
}
}
Remarks
With some of the .Net runtimes (example: .Net Core 2.0), HTML Area will give the error "No data is available for encoding 1252. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.". To resolve this error refer the user manual page Encoding Considerations.
Constructors
HtmlArea(Stream, Single, Single, Single, Single)
Initializes a new instance of the HtmlArea class.
public HtmlArea(Stream stream, float x, float y, float width, float height)
Public Sub New (stream As Stream, x As Single, y As Single, width As Single, height As Single)
Parameters
- stream: Stream
Stream object containing the HTML data.
- x: Single
X coordinate of the HTML Area.
- y: Single
Y coordinate of the HTML Area.
- width: Single
Width of the HTML Area.
- height: Single
Height of the HTML Area.
HtmlArea(Stream, Single, Single, Uri, Single, Single)
Initializes a new instance of the HtmlArea class.
public HtmlArea(Stream stream, float x, float y, Uri baseHref, float width, float height)
Public Sub New (stream As Stream, x As Single, y As Single, baseHref As Uri, width As Single, height As Single)
Parameters
- stream: Stream
Stream object containing the HTML data.
- x: Single
X coordinate of the HTML Area.
- y: Single
Y coordinate of the HTML Area.
- baseHref: Uri
Basehref of the HTML Area.
- width: Single
Width of the HTML Area.
- height: Single
Height of the HTML Area.
HtmlArea(String, Single, Single, Single, Single)
Initializes a new instance of the HtmlArea class.
public HtmlArea(string text, float x, float y, float width, float height)
Public Sub New (text As String, x As Single, y As Single, width As Single, height As Single)
Parameters
- text: String
Text to display in the HTML Area.
- x: Single
X coordinate of the HTML Area.
- y: Single
Y coordinate of the HTML Area.
- width: Single
Width of the HTML Area.
- height: Single
Height of the HTML Area.
HtmlArea(String, Single, Single, Uri, Single, Single)
Initializes a new instance of the HtmlArea class.
public HtmlArea(string text, float x, float y, Uri baseHref, float width, float height)
Public Sub New (text As String, x As Single, y As Single, baseHref As Uri, width As Single, height As Single)
Parameters
- text: String
Text to display in the HTML Area.
- x: Single
X coordinate of the HTML Area.
- y: Single
Y coordinate of the HTML Area.
- baseHref: Uri
Basehref of the HTML Area.
- width: Single
Width of the HTML Area.
- height: Single
Height of the HTML Area.
HtmlArea(Uri, Single, Single, Single, Single)
Initializes a new instance of the HtmlArea class.
public HtmlArea(Uri uri, float x, float y, float width, float height)
Public Sub New (uri As Uri, x As Single, y As Single, width As Single, height As Single)
Parameters
- uri: Uri
Physical file path of the HTML Area.
- x: Single
X coordinate of the HTML Area.
- y: Single
Y coordinate of the HTML Area.
- width: Single
Width of the HTML Area.
- height: Single
Height of the HTML Area.
HtmlArea(Uri, Single, Single, Uri, Single, Single)
Initializes a new instance of the HtmlArea class.
public HtmlArea(Uri uri, float x, float y, Uri baseHref, float width, float height)
Public Sub New (uri As Uri, x As Single, y As Single, baseHref As Uri, width As Single, height As Single)
Parameters
- uri: Uri
Physical file path of the HTML Area.
- x: Single
X coordinate of the HTML Area.
- y: Single
Y coordinate of the HTML Area.
- baseHref: Uri
Basehref of the HTML Area.
- width: Single
Width of the HTML Area.
- height: Single
Height of the HTML Area.
Properties
Angle
Gets or sets the heights of the angle element. (Inherited from RotatingPageElement)
public float Angle { get; set; }
Public Property Angle As Single
Property Value
Height
Gets or sets the height of the HTML area.
public float Height { get; set; }
Public Property Height As Single
Property Value
ID
Gets or sets the ID of the page element. (Inherited from PageElement)
public string ID { get; set; }
Public Property ID As String
Property Value
IgnoreMargins
Gets or sets ignore margin property. Setting false will consider the margin while placing the page element based on the RelativeTo property. (Inherited from PageElement)
public bool IgnoreMargins { get; set; }
Public Property IgnoreMargins As Boolean
Property Value
Examples
The following example will place the Label in the top-left of the page with IgnoreMargin
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
public class Example
{
public static void CreatePDF(string outputPath)
{
// Create a PDF Document
Document document = new Document();
// Create a Page and add it to the document
Page page = new Page();
document.Pages.Add(page); // Create an Label and place it in page top left with margin ignored
Label label = new Label("I am placed in Page top left with margin ignored", 0, 0, 160, 30);
label.RelativeTo = RelativeTo.TopLeft;
label.IgnoreMargin=true; page.Elements.Add(label);
// Save the PDF
document.Draw(outputPath);
}
}
RelativeTo
Gets and sets placement of the page element on the page. (Inherited from PageElement)
public RelativeTo RelativeTo { get; set; }
Public Property RelativeTo As RelativeTo
Property Value
Examples
The following example will place the Label in the top-left of the page.
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
public class Example
{
public static void CreatePDF(string outputPath)
{
// Create a PDF Document
Document document = new Document();
// Create a Page and add it to the document
Page page = new Page();
document.Pages.Add(page); // Create an Label and place it in page top left with margin
Label label = new Label("I am placed in Page top left with margin.", 0, 0, 160, 30);
label.RelativeTo = RelativeTo.TopLeft;
page.Elements.Add(label);
// Save the PDF
document.Draw(outputPath);
}
}
Tag
Gets or sets the tag of the taggable element. (Inherited from TaggablePageElement)
public Tag Tag { get; set; }
Public Property Tag As Tag
Property Value
TagOrder
Gets or sets the tag order of the taggable element. (Inherited from TaggablePageElement)
public int TagOrder { get; set; }
Public Property TagOrder As Int32
Property Value
Width
Gets or sets the width of the HTML area.
public float Width { get; set; }
Public Property Width As Single
Property Value
X
Gets or sets the X coordinate of the page element. (Inherited from RotatingPageElement)
public float X { get; set; }
Public Property X As Single
Property Value
Y
Gets or sets the Y coordinate of the page element. (Inherited from RotatingPageElement)
public float Y { get; set; }
Public Property Y As Single
Property Value
Methods
Draw(PageWriter)
Draws the page element to the given PageWriter object. (Inherited from RotatingPageElement)
public void Draw(PageWriter writer)
Sub Draw(writer As PageWriter)
Parameters
- writer: PageWriter
PageWriter object to receive the page element's output.
Equals(Object)
Determines whether the specified Object is equal to the current Object . (Inherited from Object)
public bool Equals(Object obj)
Function Equals(obj As Object) As Boolean
Parameters
- obj: Object
The Object to compare with the current Object .
Returns
true if the specified Object is equal to the current Object ; otherwise, false.
GetHashCode()
Serves as a hash function for a particular type. (Inherited from Object)
public int GetHashCode()
Function GetHashCode() As Integer
Returns
A hash code for the current Object .
GetOverflowHtmlArea()
Returns a new HtmlArea object containing the overflow html area.
public HtmlArea GetOverflowHtmlArea()
Function GetOverflowHtmlArea() As HtmlArea
Returns
A HtmlArea if there is overflow html area; otherwise, null .
Examples
The following example shows you how to use the GetOverflowHtmlArea object.
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements.Html;
public class Example
{
public static void CreatePDF(string inputHTMLPath, string outputPath)
{
// Create a PDF Document
Document document = new Document();
// Create a Uri
Uri filePath = new Uri(inputHTMLPath);
// create a html area
HtmlArea htmlArea = new HtmlArea(filePath, 0, 0, 500, 600);
do
{
// Create a new page
Page page = new Page();
// Add the html area to the page;
page.Elements.Add(htmlArea);
// Add the page to the document
document.Pages.Add(page);
// Set the html area object equal to the rest of the html area that did not fit
// if all the html area did fit, GetOverflowHtmlArea will return null
htmlArea = htmlArea.GetOverflowHtmlArea(0, 0, 600);
} while (htmlArea != null);
//Save the PDF
document.Draw(outputPath);
}
}
Remarks
This method returns a new HTML area object that contains the remaining html area that did not fit.
GetOverflowHtmlArea(Single, Single, Single)
Returns a new HtmlArea object containing the overflow html area.
public HtmlArea GetOverflowHtmlArea(float x, float y, float height)
Function GetOverflowHtmlArea(x As Single, y As Single, height As Single) As HtmlArea
Parameters
- x: Single
X coordinate of the new object.
- y: Single
Y coordinate of the new object.
- height: Single
Height of the new object.
Returns
A HtmlArea if there is overflow html area; otherwise, null .
Examples
The following example shows you how to use the GetOverflowHtmlArea object.
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements.Html;
public class Example
{
public static void CreatePDF(string inputHTMLPath, string outputPath)
{
// Create a PDF Document
Document document = new Document();
// Create a Uri
Uri filePath = new Uri(inputHTMLPath);
// create a html area
HtmlArea htmlArea = new HtmlArea(filePath, 0, 0, 500, 600);
do
{
// Create a new page
Page page = new Page();
// Add the html area to the page;
page.Elements.Add(htmlArea);
// Add the page to the document
document.Pages.Add(page);
// Set the html area object equal to the rest of the html area that did not fit
// if all the html area did fit, GetOverflowHtmlArea will return null
htmlArea = htmlArea.GetOverflowHtmlArea(0, 0, 600);
} while (htmlArea != null);
//Save the PDF
document.Draw(outputPath);
}
}
Remarks
This method returns a new HTML area object that contains the remaining html area that did not fit.
GetRequiredHeight()
Returns the height required to fit html file.
public float GetRequiredHeight()
Function GetRequiredHeight() As Single
Returns
The required height to display html file.
GetType()
Gets the Type of the current instance. (Inherited from Object)
public Type GetType()
Function GetType() As Type
Returns
The Type instance that represents the exact runtime type of the current instance.
ToString()
Returns a String that represents the current Object . (Inherited from Object)
public string ToString()
Function ToString() As String
Returns
A String that represents the current Object .
Events
FontSelecting
Occurs when the Font is being selected to write the HtmlArea text. This can be used to change the font and related properties of the text.
public event HtmlAreaFontSelecting HtmlArea.FontSelecting;
Public Event HtmlArea.FontSelecting As HtmlAreaFontSelecting
Event Handler
Examples
This example shows simple HTML being displayed on the page.
Imports ceTe.DynamicPDF
Imports ceTe.DynamicPDF.LayoutEngine.LayoutElements
Imports ceTe.DynamicPDF.PageElements.Html
Public Class Example
Public Shared Sub CreatePDF(inputHTMLPath As String, outputPath As String)
' Create a Uri Dim url As Uri = New Uri(inputHTMLPath)
' Create a PDF Document Dim document As Document = New Document()
' create a html area Dim htmlArea As HtmlArea = New HtmlArea(url, 0, 0, 530, 580)
' Adding Font Selecting Event AddHandler htmlArea.FontSelecting, AddressOf HtmlArea_FontSelecting
' Create a new page
Dim page As Page = New Page()
' Add the html area to the page; page.Elements.Add(htmlArea)
' Add the page to the document document.Pages.Add(page)
//Save the PDF to disk
document.Draw(outputPath)
End Sub
Private Shared Sub HtmlArea_FontSelecting(ByVal sender As Object, ByVal e As FontSelectingEventArgs)
' Update the Font and related properties as needed If e.FontFamily.Contains("Times") Then
e.Font = Font.Helvetica
End If
End Sub
End Class
using System;
using ceTe.DynamicPDF;
using ceTe.DynamicPDF.PageElements;
using ceTe.DynamicPDF.PageElements.Html;
public class Example
{
public static void CreatePDF(string inputHTMLPath, string outputPath){ // Create an Uri with the html file path Uri url = new Uri(inputHTMLPath);
// Create Document object Document document = new Document();
// create an html area HtmlArea htmlArea = new HtmlArea(url, 0, 0, 530, 580);
// Adding Font Selecting Event htmlArea.FontSelecting += HtmlArea_FontSelecting;
// Create a new page Page page = new Page();
// Add the html area to the page; page.Elements.Add(htmlArea);
// Add the page to the document document.Pages.Add(page);
//Save the PDF to disk document.Draw(outputPath);}
private static void HtmlArea_FontSelecting(object sender, FontSelectingEventArgs e){ // Update the Font and related properties as needed if (e.FontFamily.Contains("Times")) { e.Font = Font.Helvetica; }}
}