cete.dynamicpdf.htmlconverter.conversionoptions
ConversionOptions
- Namespace: ceTe.DynamicPDF.HtmlConverter
- Assemblies: DynamicPDF.HTMLConverter.dll
Defines properties and methods for conversion options.
public class ConversionOptions
Public Class ConversionOptions
Inheritance: Object → ConversionOptions
Constructors
ConversionOptions(Double, Double, [Optional] Double)
Initializes a new instance of the ConversionOptions class.
public ConversionOptions(double width, double height, [double margins = 36])
Public Sub New (width As Double, height As Double, Optional margins As Double = 36)
Parameters
- width: Double
Width of the page in points
- height: Double
Height of hte page in points
- margins: Double
Margins of the page in points
ConversionOptions(Double, Double, Double, Double)
Initializes a new instance of the ConversionOptions class.
public ConversionOptions(double width, double height, double leftAndRightMargins, double topAndBottomMargins)
Public Sub New (width As Double, height As Double, leftAndRightMargins As Double, topAndBottomMargins As Double)
Parameters
- width: Double
Width of the page in points
- height: Double
Height of hte page in points
- leftAndRightMargins: Double
Left and right margins of the page in points
- topAndBottomMargins: Double
Top and bottom margins of the page in points
ConversionOptions([Optional] PageSize, [Optional] PageOrientation, [Optional] Double)
Initializes a new instance of the ConversionOptions class.
public ConversionOptions([PageSize size = Letter], [PageOrientation orientation = Portrait], [double margins = 36])
Public Sub New (Optional size As PageSize = Letter, Optional orientation As PageOrientation = Portrait, Optional margins As Double = 36)
Parameters
- size: PageSize
Size of the page
- orientation: PageOrientation
Orientation of the page
- margins: Double
Margins of the page in points
ConversionOptions(PageSize, PageOrientation, Double, Double)
Initializes a new instance of the ConversionOptions class.
public ConversionOptions(PageSize size, PageOrientation orientation, double leftAndRightMargins, double topAndBottomMargins)
Public Sub New (size As PageSize, orientation As PageOrientation, leftAndRightMargins As Double, topAndBottomMargins As Double)
Parameters
- size: PageSize
Size of the page
- orientation: PageOrientation
Orientation of the page.
- leftAndRightMargins: Double
The left and right margins of the page in points.
- topAndBottomMargins: Double
The top and bottom margins of the page in points.
Properties
Author
Gets or sets the Author for metadata in converted PDF.
public string Author { get; set; }
Public Property Author As String
Property Value
BottomMargin
Gets or sets the bottom margin of the page in points.
public double BottomMargin { get; set; }
Public Property BottomMargin As Double
Property Value
CancelToken
Gets or sets a CancellationToken for conversion task.
public CancellationToken CancelToken { get; set; }
Public Property CancelToken As CancellationToken
Property Value
Examples
Following code will cancel the conversion if it does not finish within a second.
ConversionOptions conversionOptions = new ConversionOptions(PageSize.A4, PageOrientation.Portrait, 20);
CancellationTokenSource tokenSource = new CancellationTokenSource();
conversionOptions.CancelToken = tokenSource.Token;
System.Threading.Tasks.Task.Run(() => { Thread.Sleep(1000); tokenSource.Cancel(); });
byte[] pdf = await Converter.ConvertAsync(new Uri("http://www.dynamicpdf.com"), conversionOptions);
Remarks
This property will be used to create the task for conversion, so that the task may be cancelled if needed.
Creator
Gets or sets the Creator for metadata in converted PDF.
public string Creator { get; set; }
Public Property Creator As String
Property Value
DefaultCommandTimeout
Gets or sets a default timeout value for each stages of conversion in milliseconds. The task will be cancelled when the timeout occurs before CancelToken .
public static int DefaultCommandTimeout { get; set; }
Public Shared Property DefaultCommandTimeout As Int32
Property Value
Remarks
Until set explicitely, it is defined as a fixed fraction of DefaultConversionTimeout . It is simpler to use DefaultConversionTimeout unless you explicitely need to fine tune the performance.
DefaultConversionTimeout
Gets or sets a default timeout value for completion of the entire conversion. The task will be cancelled when the timeout occurs before CancelToken .
public static int DefaultConversionTimeout { get; set; }
Public Shared Property DefaultConversionTimeout As Int32
Property Value
DefaultPageLoadTimeout
Gets or sets a default timeout value for completion of navigating to a URI or loading a HTML string in milliseconds. The task will be cancelled when the timeout occurs before CancelToken .
public static int DefaultPageLoadTimeout { get; set; }
Public Shared Property DefaultPageLoadTimeout As Int32
Property Value
Remarks
Until set explicitely, it is defined as a fixed fraction of DefaultConversionTimeout . It is simpler to use DefaultConversionTimeout unless you explicitely need to fine tune the performance.
Footer
Gets or sets Footer
public string Footer { get; set; }
Public Property Footer As String
Property Value
Examples
Following code will add a footer with the URL on left side and total number of pages on right side of the footer.
ConversionOptions conversionOptions = new ConversionOptions(PageSize.A4, PageOrientation.Portrait, 20);
conversionOption.Footer = "<div style='text-align:left; display:inline-block; padding-right:1em; font-size:15em;'><span class=url></span></div>"+ "<div style = 'text-align:center; display:inline-block; padding-right:1em; font-size:15em;'></div>"+ "<div style = 'text-align:right; display:inline-block; padding-right:1em; font-size:15em;'><span class=totalPages></span></div>";
Remarks
Default is an empty string which generates no footer. Assigning null to this property will generate default footer by the browser. HTML template for the print footer should be valid HTML markup with following classes used to inject printing values into them:
date: formatted print date title: document title url: document location pageNumber: current page number totalPages: total pages in the document
For example, {span class=title}{/span}
would generate span containing the title.
Header
Gets or sets Header
public string Header { get; set; }
Public Property Header As String
Property Value
Examples
Following code will add a header with the URL on left side and total number of pages on right side of the header.
ConversionOptions conversionOptions = new ConversionOptions(PageSize.A4, PageOrientation.Portrait, 20);
conversionOption.Header = "<div style='text-align:left; display:inline-block; padding-right:1em; font-size:15em;'><span class='url'></span></div>"+ "<div style = 'text-align:center; display:inline-block; padding-right:1em; font-size:15em;'></div>"+ "<div style = 'text-align:right; display:inline-block; padding-right:1em; font-size:15em;'><span class='totalPages'></span></div>";
Remarks
Default is an empty string which generates no header. Assigning null to this property will generate default header by the browser. HTML template for the print header should be valid HTML markup with following classes used to inject printing values into them:
date: formatted print date title: document title url: document location pageNumber: current page number totalPages: total pages in the document
For example, {span class=title}{/span}
would generate span containing the title.
Height
Gets or sets the width of the page in points.
public double Height { get; set; }
Public Property Height As Double
Property Value
IncludeBackground
Gets or sets the include back ground in bool.
public bool IncludeBackground { get; set; }
Public Property IncludeBackground As Boolean
Property Value
Keywords
Gets or sets the Keywords for metadata in converted PDF.
public string Keywords { get; set; }
Public Property Keywords As String
Property Value
LeftMargin
Gets or sets the left margin of the page in points.
public double LeftMargin { get; set; }
Public Property LeftMargin As Double
Property Value
Logging
Gets or sets the Temporary directory path.
public static LogConfig Logging { get; }
Public Shared Property Logging As LogConfig
Property Value
Examples
This example shows how to use the TemporaryDirectory property.
Imports ceTe.DynamicPDF.Conversion
Module Module1
Sub Main()
' Assign level of logging to log config.
ConversionOptions.Logging.Level = LogLevel.Warning
' Call convert method to do conversion.
Converter.Convert("<h1>Hello World</h1>", "C:\MyOutput.pdf")
End Sub
End Module
using System;
using ceTe.DynamicPDF.Conversion;
class MyClass
{
static void Main()
{
//Assign level of logging to log config.
ConversionOptions.Logging.Level = LogLevel.Warning;
// Call convert method to do conversion.
Converter.Convert(@"<h1>Hello World</h1>", @"C:\MyOutput.pdf");
}
}
OverrideCssPageSize
Gets or sets the override css page size in bool.
public bool OverrideCssPageSize { get; set; }
Public Property OverrideCssPageSize As Boolean
Property Value
Producer
Gets or sets the Producer for metadata in converted PDF.
public string Producer { get; set; }
Public Property Producer As String
Property Value
RightMargin
Gets or sets the right margin of the page in points.
public double RightMargin { get; set; }
Public Property RightMargin As Double
Property Value
Subject
Gets or sets the Subject for metadata in converted PDF.
public string Subject { get; set; }
Public Property Subject As String
Property Value
Title
Gets or sets the Title for metadata in converted PDF.
public string Title { get; set; }
Public Property Title As String
Property Value
TopMargin
Gets or sets the top margin of the page in points.
public double TopMargin { get; set; }
Public Property TopMargin As Double
Property Value
Width
Gets or sets the width of the page in points.
public double Width { get; set; }
Public Property Width As Double
Property Value
Zoom
Determines the magnification level for the HTML. [0.1 to 2.0]
public float Zoom { get; set; }
Public Property Zoom As Single
Property Value
Remarks
Value ranges from 0.1 to 2.0. 1 indicates 100%
Methods
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.
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 .