Skip to main content

HtmlConverter

Version: 3.0

cete.dynamicpdf.conversion.htmlconverter

HtmlConverter​

Defines methods and properties for the HTMLConverter.

public class HtmlConverter
Public Class HtmlConverter

Inheritance: Object → HtmlConverter

Licensing Info​

This class is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

Example shows how to use HtmlConverter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' create new instance of HtmlConversionOptions.
Dim conversionOptions As HtmlConversionOptions = New HtmlConversionOptions(True)

' Create new instance of Converter by providing suitable parameters.
Dim htmlConverter As HtmlConverter = New HtmlConverter("C:\MyDocument.html",conversionOptions)

' Call Convert method to start conversion
htmlConverter.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// create new instance of HtmlConversionOptions.
HtmlConversionOptions conversionOptions = new HtmlConversionOptions(true);

// Create new instance of Converter by providing suitable parameters.
HtmlConverter htmlConverter = new HtmlConverter(@"C:\MyDocument.html", conversionOptions);

//Call Convert method to start conversion
htmlConverter.Convert(@"C:\MyOutput.pdf");
}
}

Constructors​

HtmlConverter(String)​

Initializes a new instance of the HtmlConverter class.

public HtmlConverter(string htmlString)
Public Sub New (htmlString As String)

Parameters​

Licensing Info​

This constructor is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

Example shows how to use HtmlConverter constructor with string as parameter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

Dim html = " <html>
<body>
<h2>HTML Image</h2>
<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="300">
</body>
</htm>
"

' Create new instance of Converter by providing suitable parameters.
Dim htmlConverter As HtmlConverter = New HtmlConverter(html)

' Call Convert method to start conversion
htmlConverter.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
string html = @" <html>
<body>
<h2>HTML Image</h2>
<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="300">
</body>
</html>
";
// Create new instance of Converter by providing suitable parameters.
HtmlConverter htmlConverter = new HtmlConverter(html);

//Call Convert method to start conversion
htmlConverter.Convert(@"C:\MyOutput.pdf");
}
}

HtmlConverter(String, HtmlConversionOptions)​

Initializes a new instance of the HtmlConverter class.

public HtmlConverter(string htmlString, HtmlConversionOptions conversionOptions)
Public Sub New (htmlString As String, conversionOptions As HtmlConversionOptions)

Parameters​

Content of the HTML source.

Initializes the ConversionOptions property of the class.

Licensing Info​

This constructor is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

Example shows how to use HtmlConverter constructor with string and conversionOptions as parameter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

Dim html = " <html>
<body>
<h2>HTML Image</h2>
<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="300">
</body>
</htm>
"

' create new instance of HtmlConversionOptions.
Dim conversionOptions As HtmlConversionOptions = New HtmlConversionOptions(True)

' Create new instance of Converter by providing suitable parameters.
Dim htmlConverter As HtmlConverter = New HtmlConverter(html,conversionOptions)

' Call Convert method to start conversion
htmlConverter.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
string html = @" <html>
<body>
<h2>HTML Image</h2>
<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="300">
</body>
</html>
";

//Create new instance of HtmlConversionOptions
HtmlConversionOptions conversionOptions=new HtmlConversionOptions(true);

// Create new instance of Converter by providing suitable parameters.
HtmlConverter htmlConverter = new HtmlConverter(html,conversionOptions);

//Call Convert method to start conversion
htmlConverter.Convert(@"C:\MyOutput.pdf");
}
}

HtmlConverter(String, Uri)​

Initializes a new instance of the HtmlConverter class.

public HtmlConverter(string htmlString, Uri basePath)
Public Sub New (htmlString As String, basePath As Uri)

Parameters​

Licensing Info​

This constructor is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

Example shows how to use HtmlConverter constructor with string and BasePath as parameter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

Dim html = " <html>
<body>
<h2>HTML Image</h2>
<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="300">
</body>
</htm>
"

' Create new instance of Converter by providing suitable parameters.
Dim htmlConverter As HtmlConverter = New HtmlConverter(html, New Uri("C:\img_girl.jpg"))

' Call Convert method to start conversion
htmlConverter.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
string html = @" <html>
<body>
<h2>HTML Image</h2>
<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="300">
</body>
</html>
";
// Create new instance of Converter by providing suitable parameters.
HtmlConverter htmlConverter = new HtmlConverter(html,new Uri("C:/img_girl.jpg"));

//Call Convert method to start conversion
htmlConverter.Convert(@"C:\MyOutput.pdf");
}
}

HtmlConverter(String, Uri, HtmlConversionOptions)​

Initializes a new instance of the HtmlConverter class.

public HtmlConverter(string htmlString, Uri basePath, HtmlConversionOptions conversionOptions)
Public Sub New (htmlString As String, basePath As Uri, conversionOptions As HtmlConversionOptions)

Parameters​

Content of the HTML source.

  • basePath: Uri

Base path to fetch HTML resorces like images, scripts etc. Relative links also resolved using this path.

Initializes the ConversionOptions property of the class.

Licensing Info​

This constructor is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

Example shows how to use HtmlConverter constructor with string, BasePath and conversion options as parameter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

Dim html = " <html>
<body>
<h2>HTML Image</h2>
<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="300">
</body>
</htm>
"

' create new instance of HtmlConversionOptions.
Dim conversionOptions As HtmlConversionOptions = New HtmlConversionOptions(True)

' Create new instance of Converter by providing suitable parameters.
Dim htmlConverter As HtmlConverter = New HtmlConverter(html, New Uri("C:\img_girl.jpg"),conversionOptions)

' Call Convert method to start conversion
htmlConverter.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
string html = @" <html>
<body>
<h2>HTML Image</h2>
<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="300">
</body>
</html>
";

//Create new instance of HtmlConversionOptions
HtmlConversionOptions conversionOptions=new HtmlConversionOptions(true);

// Create new instance of Converter by providing suitable parameters.
HtmlConverter htmlConverter = new HtmlConverter(html,new Uri("C:\img_girl.jpg"),conversionOptions);

//Call Convert method to start conversion
htmlConverter.Convert(@"C:\MyOutput.pdf");
}
}

HtmlConverter(Uri)​

Initializes a new instance of the HtmlConverter class.

public HtmlConverter(Uri uri)
Public Sub New (uri As Uri)

Parameters​

path to the html file

Licensing Info​

This constructor is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

Example shows how to use HtmlConverter constructor with Uri as parameter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' Create new instance of Converter by providing suitable parameters.
Dim htmlConverter As HtmlConverter = New HtmlConverter(New Uri("https://www.google.com/"));)

' Call Convert method to start conversion
htmlConverter.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// Create new instance of Converter by providing suitable parameters.
HtmlConverter htmlConverter = new HtmlConverter(new Uri("https://www.google.com/"));

//Call Convert method to start conversion
htmlConverter.Convert(@"C:\MyOutput.pdf");
}
}

HtmlConverter(Uri, HtmlConversionOptions)​

Initializes a new instance of the HtmlConverter class.

public HtmlConverter(Uri uri, HtmlConversionOptions conversionOptions)
Public Sub New (uri As Uri, conversionOptions As HtmlConversionOptions)

Parameters​

Uniform Resource Identifier for the HTML page.

Initializes the ConversionOptions property of the class.

Licensing Info​

This constructor is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

Example shows how to use HtmlConverter constructor with Uri and conversion options as parameter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' create new instance of HtmlConversionOptions.
Dim conversionOptions As HtmlConversionOptions = New HtmlConversionOptions(True)

' Create new instance of Converter by providing suitable parameters.
Dim htmlConverter As HtmlConverter = New HtmlConverter(New Uri("https://www.google.com/"),conversionOptions)

' Call Convert method to start conversion
htmlConverter.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
//Create new instance of htmlConversionOptions.
HtmlConversionOptions conversionOptions=new HtmlConversionOptions(true);

// Create new instance of Converter by providing suitable parameters.
HtmlConverter htmlConverter = new HtmlConverter(new Uri("https://www.google.com/"),conversionOptions);

//Call Convert method to start conversion
htmlConverter.Convert(@"C:\MyOutput.pdf");
}
}

Properties​

ChromiumProcessArgs​

Gets or sets the chromium Process directory path On Linux machine this should be set to the path where google-chrome is installed.

public static string ChromiumProcessArgs { get; set; }
Public Shared Property ChromiumProcessArgs As String

Property Value​

String

Licensing Info​

This property is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

ChromiumProcessPath​

Gets or sets the chromium Process directory path On Linux machine this should be set to the path where google-chrome is installed.

public static string ChromiumProcessPath { get; set; }
Public Shared Property ChromiumProcessPath As String

Property Value​

String

Licensing Info​

This property is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

ConversionOptions​

Gets an instance of HtmlConversionOptions class.

public HtmlConversionOptions ConversionOptions { get; }
Public Property ConversionOptions As HtmlConversionOptions

Property Value​

HtmlConversionOptions

Licensing Info​

This property is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Methods​

Convert()​

Converts Html to Pdf

public Byte[] Convert()
Function Convert() As Byte()

Returns​

returns a output pdf byte array

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with output byte array as return type.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' Create new instance of Converter by providing suitable parameters.
Dim htmlConversion As HtmlConverter = New HtmlConverter("C:\MyDocument.html")

' Call Convert method to start conversion
Dim output As Byte() = htmlConversion.Convert()

If (output IsNot Nothing) Then
'save byte array output to a file.
File.WriteAllBytes("C:\MyOutputFile.pdf", output)
End If

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// Create new instance of Converter.
HtmlConverter htmlConverter = new HtmlConverter(@"C:\MyDocument.html");

//Call Convert method to start conversion
byte []output=htmlConverter.Convert();

if(output!=null)
{
//save byte array output to a file.
File.WriteAllBytes("C:\MyOutputFile.pdf",output);
}
}
}

Convert(Byte[])​

Converts Html to Pdf

public Byte[] Convert(Byte[] pdfToAppendTo)
Function Convert(pdfToAppendTo As Byte()) As Byte()

Parameters​

Contents of Pdf in byte array format, to which the current conversion needs to be appended to

Returns​

returns a Task where the result type is byte array

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with pdf byte array as parameter and byte array as return type.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' Create new instance of Converter by providing suitable parameters.
Dim htmlConversion As HtmlConverter = New HtmlConverter("C:\MyDocument.html")

' Call Convert method to start conversion
Dim output As Byte() = htmlConversion.Convert()

If (output IsNot Nothing) Then
Dim finalOutput As Byte() = htmlConversion.Convert(output)
'save byte array output to a file.
File.WriteAllBytes("C:\MyOutputFile.pdf", finalOutput)
End If

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// Create new instance of Converter.
HtmlConverter htmlConverter = new HtmlConverter(@"C:\MyDocument.html");

//Call Convert method to start conversion
byte []output=htmlConverter.Convert();

if(output!=null)
{
byte []finalOutputByte=htmlConverter.Convert(output);
//save byte array output to a file.
File.WriteAllBytes("C:\MyOutputFile.pdf",finalOutputByte);
}
}
}

Convert(String)​

Converts Html to Pdf

public void Convert(string outputFilePath)
Sub Convert(outputFilePath As String)

Parameters​

Path where the output file needs to be saved

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with outputFilePath as parameter.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' Create new instance of Converter by providing suitable parameters.
Dim htmlConversion As HtmlConverter = New HtmlConverter("C:\MyDocument.html")

' Call Convert method to start conversion
htmlConversion.Convert("C:\MyOutput.pdf")

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// Create new instance of Converter.
HtmlConverter htmlConverter = new HtmlConverter(@"C:\MyDocument.html");

//Call Convert method to start conversion
htmlConverter.Convert(@"C:\MyOutput.pdf");
}
}

ConvertAsync()​

Does the Asynchronous conversion

public Task&ltByte[]> ConvertAsync()
Function ConvertAsync() As Task(Of Byte())

Returns​

returns a Task where the result type is byte array

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with byte array as return type.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Async Function run() As Task

' Create new instance of Converter by providing suitable parameters.
Dim htmlConversion As HtmlConverter = New HtmlConverter("C:\MyDocument.html")

' Call Convert method to start conversion
Dim result= Await htmlConversion.ConvertAsync()
If (result IsNot Nothing) Then
File.WriteAllBytes("C:\MyDocument.pdf",result)
End If

End Function

Sub Main()
run().Wait()
End Sub

End Module
using ceTe.DynamicPDF.Conversion;
using System.IO;

class MyClass
{
static async Task run()
{

// Create new instance of Converter.
HtmlConverter htmlConverter = new HtmlConverter(@"C:\MyDocument.html");

//Call Convert method to start conversion
byte[] result=await htmlConverter.ConvertAsync();
if(result!=null)
{
File.WriteAllBytes("C:\MyDocument.pdf", result);

}
}
static void Main()
{
run().Wait();
}
}

ConvertAsync(Byte[])​

Does the Asynchronous conversion

public Task&ltByte[]> ConvertAsync(Byte[] pdfToAppendTo)
Function ConvertAsync(pdfToAppendTo As Byte()) As Task(Of Byte())

Parameters​

Contents of Pdf in byte array format, to which the current conversion needs to be appended to

Returns​

returns a Task where the result type is byte array

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method with pdf byte array as parameter and byte array as return type.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Sub Main()

' Create new instance of Converter by providing suitable parameters.
Dim htmlConversion As HtmlConverter = New HtmlConverter("C:\MyDocument.html")

' Call Convert method to start conversion
Dim output As Byte() =Await htmlConversion.ConvertAsync()

If (output IsNot Nothing) Then
Dim finalOutput As Byte() =Await htmlConversion.ConvertAsync(output)
'save byte array output to a file.
File.WriteAllBytes("C:\MyOutputFile.pdf", finalOutput)
End If

End Sub

End Module
using ceTe.DynamicPDF.Conversion;

class MyClass
{
static void Main()
{
// Create new instance of Converter.
HtmlConverter htmlConverter = new HtmlConverter(@"C:\MyDocument.html");

//Call Convert method to start conversion
byte []output=await htmlConverter.ConvertAsync();

if(output!=null)
{
byte []finalOutputByte=await htmlConverter.ConvertAsync(output);
//save byte array output to a file.
File.WriteAllBytes("C:\MyOutputFile.pdf",finalOutputByte);
}
}
}

ConvertAsync(String)​

Does the Asynchronous conversion

public Task&ltbool> ConvertAsync(string outputFilePath)
Function ConvertAsync(outputFilePath As String) As Task(Of Boolean)

Parameters​

Returns​

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Examples​

This example shows how to use convert method byte array as return type.

Imports ceTe.DynamicPDF.Conversion

Module Module1

Async Function run() As Task

' Create new instance of Converter by providing suitable parameters.
Dim htmlConversion As HtmlConverter = New HtmlConverter("C:\MyDocument.html")

' Call Convert method to start conversion
Dim result= Await htmlConversion.ConvertAsync("C:\MyOutput.pdf")
If (result) Then
Console.WriteLine("Completed successfully);

End If

End Function

Sub Main()
run().Wait()
End Sub

End Module
using ceTe.DynamicPDF.Conversion;
using Syste.IO;

class MyClass
{
static async Task run()
{

// Create new instance of Converter.
HtmlConverter htmlConverter = new HtmlConverter(@"C:\MyDocument.html");

//Call Convert method to start conversion
bool result= await htmlConverter.ConvertAsync(@"C:\MyOutput.pdf");
if(result)
{
Console.WriteLine("Completed successfully);

}
}
static void Main()
{
run().Wait();
}
}

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​

The Object to compare with the current Object .

Returns​

true if the specified Object is equal to the current Object ; otherwise, false.

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

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 .

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

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.

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

ReleaseResources()​

Releases all cache setup for faster conversions in order to gain memory and storage space.

public static void ReleaseResources()
Shared Sub ReleaseResources()

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Remarks​

Do not use this unless it is sure that no other HTML conversions will be done anytime soon. It can be used to gain memory and storage space, but it will also cause some delay in the conversion which will be performed after calling this method.

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 .

Licensing Info​

This method is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

Events​

Completed​

Occurs when a document is successfully converted.

public event ConversionCompleted HtmlConverter.Completed;
Public Event HtmlConverter.Completed As ConversionCompleted

Event Handler​

ConversionCompleted

Licensing Info​

This event is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

ProgressChanged​

Occurs when the status of a document conversion changes.

public event ProgressChanged HtmlConverter.ProgressChanged;
Public Event HtmlConverter.ProgressChanged As ProgressChanged

Event Handler​

ProgressChanged

Licensing Info​

This event is a DynamicPDF Converter feature. One of the following is required for non-evaluation usage:

See Also​

ceTe.DynamicPDF.Conversion