cete.dynamicpdf.htmlconverter.converter
Converter
- Namespace: ceTe.DynamicPDF.HtmlConverter
- Assemblies: DynamicPDF.HTMLConverter.dll
Converts Html to Pdf
public abstract class Converter
Public MustInherit Class Converter
Inheritance: Object → Converter
Properties
ChromiumProcessArgs
Gets or sets additional command-line arguments for google-chrome/chromium.
public static string ChromiumProcessArgs { get; set; }
Public Shared Property ChromiumProcessArgs As String
Property Value
ChromiumProcessPath
Gets or sets the full path to the google-chrome/chromium executable (including the name of executable). Setting this property is mandatory in the case of a Linux-based machine. On Windows, set this property to use locally installed chrome/chromium.
public static string ChromiumProcessPath { get; set; }
Public Shared Property ChromiumProcessPath As String
Property Value
TemporaryDirectory
Gets or sets the temporary directory path
public static string TemporaryDirectory { get; set; }
Public Shared Property TemporaryDirectory As String
Property Value
Methods
AddLicense(String)
Adds a license key.
public static bool AddLicense(string licenseKey)
Shared Function AddLicense(licenseKey As String) As Boolean
Parameters
- licenseKey: String
The license key to add.
Returns
A boolean value indicating if the license is valid.
Remarks
This method accepts a license key, not a serial number.
Convert(String, String, [Optional] Uri, [Optional] ConversionOptions)
Initializes a new instance of the HtmlConverter class.
public static void Convert(string inputHtml, string outputPath, [Uri basePath = null], [ConversionOptions conversionOptions = null])
Shared Sub Convert(inputHtml As String, outputPath As String, Optional basePath As Uri = null, Optional conversionOptions As ConversionOptions = null)
Parameters
- inputHtml: String
Content of the HTML source.
- outputPath: String
Path where the output file needs to be saved
- basePath: Uri
Base path to fetch HTML resorces like images, scripts etc. Relative links also resolved using this path.
- conversionOptions: ConversionOptions
Initializes the ConversionOptions property of the class.
Remarks
Html resources with an absolute or relative file path will be resolved only when a basePath is specified. These resources will be considered insecure and blocked if no basePath is specified.
Convert(String, [Optional] Uri, [Optional] ConversionOptions)
Initializes a new instance of the HtmlConverter class.
public static Byte[] Convert(string inputHtml, [Uri basePath = null], [ConversionOptions conversionOptions = null])
Shared Function Convert(inputHtml As String, Optional basePath As Uri = null, Optional conversionOptions As ConversionOptions = null) As Byte()
Parameters
- inputHtml: String
Content of the HTML source.
- basePath: Uri
Base path to fetch HTML resorces like images, scripts etc. Relative links also resolved using this path.
- conversionOptions: ConversionOptions
Initializes the ConversionOptions property of the class.
Returns
output pdf in byte array format
Remarks
Html resources with an absolute or relative file path will be resolved only when a basePath is specified. These resources will be considered insecure and blocked if no basePath is specified.
Convert(Uri, [Optional] ConversionOptions)
Initializes a new instance of the HtmlConverter class.
public static Byte[] Convert(Uri uri, [ConversionOptions conversionOptions = null])
Shared Function Convert(uri As Uri, Optional conversionOptions As ConversionOptions = null) As Byte()
Parameters
- uri: Uri
Uniform Resource Identifier for the HTML page.
- conversionOptions: ConversionOptions
Initializes the ConversionOptions property of the class. It is an optional parameter.
Returns
output pdf in byte array format
Convert(Uri, String, [Optional] ConversionOptions)
Initializes a new instance of the HtmlConverter class.
public static void Convert(Uri uri, string outputPath, [ConversionOptions conversionOptions = null])
Shared Sub Convert(uri As Uri, outputPath As String, Optional conversionOptions As ConversionOptions = null)
Parameters
- uri: Uri
Uniform Resource Identifier for the HTML page.
- outputPath: String
Path where the output file needs to be saved
- conversionOptions: ConversionOptions
Initializes the ConversionOptions property of the class. It is an optional parameter.
ConvertAsync(String, String, [Optional] Uri, [Optional] ConversionOptions)
Does the Asynchronous conversion
public static Task<bool> ConvertAsync(string inputHtml, string outputPath, [Uri basePath = null], [ConversionOptions conversionOptions = null])
Shared Function ConvertAsync(inputHtml As String, outputPath As String, Optional basePath As Uri = null, Optional conversionOptions As ConversionOptions = null) As Task(Of Boolean)
Parameters
- inputHtml: String
Content of the HTML source.
- outputPath: String
Path where the output file needs to be saved
- basePath: Uri
Base path to fetch HTML resorces like images, scripts etc. Relative links also resolved using this path.
- conversionOptions: ConversionOptions
Initializes the ConversionOptions property of the class.
Returns
Remarks
Html resources with an absolute or relative file path will be resolved only when a basePath is specified. These resources will be considered insecure and blocked if no basePath is specified.
ConvertAsync(String, [Optional] Uri, [Optional] ConversionOptions)
Does the Asynchronous conversion
public static Task<Byte[]> ConvertAsync(string inputHtml, [Uri basePath = null], [ConversionOptions conversionOptions = null])
Shared Function ConvertAsync(inputHtml As String, Optional basePath As Uri = null, Optional conversionOptions As ConversionOptions = null) As Task(Of Byte())
Parameters
- inputHtml: String
Content of the HTML source.
- basePath: Uri
Base path to fetch HTML resorces like images, scripts etc. Relative links also resolved using this path.
- conversionOptions: ConversionOptions
Initializes the ConversionOptions property of the class.
Returns
output pdf in byte array format
Remarks
Html resources with an absolute or relative file path will be resolved only when a basePath is specified. These resources will be considered insecure and blocked if no basePath is specified.
ConvertAsync(Uri, [Optional] ConversionOptions)
Does the Asynchronous conversion
public static Task<Byte[]> ConvertAsync(Uri uri, [ConversionOptions conversionOptions = null])
Shared Function ConvertAsync(uri As Uri, Optional conversionOptions As ConversionOptions = null) As Task(Of Byte())
Parameters
- uri: Uri
Uniform Resource Identifier for the HTML page.
- conversionOptions: ConversionOptions
Initializes the ConversionOptions property of the class.
Returns
output pdf in byte array format
Examples
This example shows how to convert html converter using convertAsync method and uri and conversion options as parameters.
Imports System
Imports ceTe.DynamicPDF.HtmlConverter
Imports System.Threading.Tasks
Imports System.IO
Module Program
Sub Main(args As String())
Dim var As Task = run()
var.Wait()
End Sub
Public Async Function run() As Task
' Create a instance of ConversionOptions
Dim conversionOptions As ConversionOptions = New ConversionOptions(PageSize.A3, PageOrientation.Portrait, 75)
' Call convert method to do conversion.
Dim pdfData As Byte() = Await Converter.ConvertAsync(New Uri("https://www.google.com/"))
If pdfData IsNot Nothing Then
File.WriteAllBytes("D:\\output.pdf", pdfData)
End If
End Function
End Module
using System;
using ceTe.DynamicPDF.Conversion;
class MyClass
{
static void Main()
{
var task = run();
task.Wait();
}
public static async Task run()
{
ConversionOptions options = new ConversionOptions(PageSize.A3, PageOrientation.Portrait, 75);
byte []pdfData= await Converter.ConvertAsync(new Uri("https://www.google.com/"));
if (pdfData != null)
{
File.WriteAllBytes(@"D:\output.pdf", pdfData);
}
}
}
ConvertAsync(Uri, String, [Optional] ConversionOptions)
Does the Asynchronous conversion
public static Task<bool> ConvertAsync(Uri uri, string outputPath, [ConversionOptions conversionOptions = null])
Shared Function ConvertAsync(uri As Uri, outputPath As String, Optional conversionOptions As ConversionOptions = null) As Task(Of Boolean)
Parameters
- uri: Uri
Uniform Resource Identifier for the HTML page.
- outputPath: String
Path where the output file needs to be saved
- conversionOptions: ConversionOptions
Initializes the ConversionOptions property of the class.
Returns
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 .
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.
ReleaseResources()
Releases all cache setup for faster conversions in order to gain memory and storage space.
public static void ReleaseResources()
Shared Sub ReleaseResources()
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 .
Events
Loaded
Occurs after HTML string or URL has been loaded and ready for conversion.
public event LoadedEventHandler Converter.Loaded;
Public Event Converter.Loaded As LoadedEventHandler
Event Handler
Remarks
One can add sleep in this event if any script evecution is expected to update visual elements.