Skip to main content

ConversionOptions

Version: 3.0

ConversionOptions

DynamicPDF HTML Converter supports formatting PDF output using the ConversionOptions class. Features include adding PDF metadata and formatting the PDF document. For more details, refer to the ConversionOptions API documentation.

The ConversionOptions class has four overloaded constructors, allowing you to set the dimensions of the produced PDF. Options include specifying PageSize, margins, size, and orientation.

info

Use one of the Converter.Convert or Converter.ConvertAsync method overloads that accepts a ConversionOptions instance to customize formatting and processing behavior for an individual conversion operation.

Properties​

ConversionOptions supports the following properties.

PropertiesStatic
AuthorGets or sets the Author for metadata in converted PDF.
BottomMarginGets or sets the bottom margin of the page in points.
CancelTokenGets or sets a CancellationToken for conversion task.
CreatorGets or sets the Creator for metadata in converted PDF.
DefaultCommandTimeoutGets or sets a default timeout value for each stages of conversion in milliseconds. The task will be cancelled when the timeout occurs before CancelToken.X
DefaultConversionTimeoutGets or sets a default timeout value for completion of the entire conversion. The task will be cancelled when the timeout occurs before CancelToken.X
DefaultPageLoadTimeoutGets 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.X
FooterGets or sets Footer
HeaderGets or sets Header
HeightGets or sets the width of the page in points.
IncludeBackgroundGets or sets the include back ground in bool.
KeywordsGets or sets the Keywords for metadata in converted PDF.
LeftMarginGets or sets the left margin of the page in points.
LoggingGets or sets the temporary directory path.X
OverrideCssPageSizeGets or sets the override css page size in bool.
ProducerGets or sets the Producer for metadata in converted PDF.
RightMarginGets or sets the right margin of the page in points.
SubjectGets or sets the Subject for metadata in converted PDF.
TitleGets or sets the Title for metadata in converted PDF.
TopMarginGets or sets the top margin of the page in points.
WidthGets or sets the width of the page in points.
ZoomDetermines the magnification level for the HTML. [0.1 to 2.0]

Example​

The following example illustrates using the ConversionOptions class.

string taleOfTwoCities = "https://www.gutenberg.org/files/98/98-h/98-h.htm";
Uri resolvePath = new Uri(taleOfTwoCities);
double leftRightMarginsPts = 36;
double topBottomMarginsPts = 144;

ConversionOptions conversionOptions = new ConversionOptions(PageSize.Letter,
PageOrientation.Portrait, leftRightMarginsPts, topBottomMarginsPts);
conversionOptions.Author = "Charles Dickens";
conversionOptions.Creator = "James B";
conversionOptions.Title = "A Tale of Two Cities";
conversionOptions.Subject = "Guttenberg press version of Charles Dickens\'s"
+ "A Tale of Two Cities.";
conversionOptions.Header = "<div style = 'text-align:center;width:100%"
+ ";font-size:15em;'>A Tale of Two Cities</div>";
Converter.Convert(resolvePath, outputDocumentPath, conversionOptions);
Dim taleOfTwoCities As String = "https://www.gutenberg.org/files/98/98-h/98-h.htm"
Dim resolvePath As Uri = New Uri(taleOfTwoCities)
Dim leftRightMarginsPts As Double = 36
Dim topBottomMarginsPts As Double = 144

Dim conversionOptions As ConversionOptions = New ConversionOptions(PageSize.Letter,
PageOrientation.Portrait, leftRightMarginsPts, topBottomMarginsPts)
conversionOptions.Author = "Charles Dickens"
conversionOptions.Creator = "James B"
conversionOptions.Title = "A Tale of Two Cities"
conversionOptions.Subject = "Guttenberg press version of Charles Dickens\'s" &
"A Tale of Two Cities."
conversionOptions.Header = "<div style = 'text-align:center;width:100%" &
";font-size:15em;'>A Tale of Two Cities</div>"
Converter.Convert(resolvePath, outputDocumentPath, conversionOptions)

[WithConversionOptions.cs](https://github.com/DynamicPDF/html-converter-dotnet-core/blob/master/html-converter-dotnet-core-cs/WithConversionOptions.cs){#gitlink-id target=_blank}


[WithConversionOptions.vb](https://github.com/DynamicPDF/html-converter-dotnet-core/blob/master/html-converter-dotnet-core-vb/WithConversionOptions.vb){#gitlink-id target=_blank}