Formatting Using 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.

Properties

ConversionOptions supports the following properties.

Properties
Author Gets or sets the Author for metadata in converted PDF.
BottomMargin Gets or sets the bottom margin of the page in points.
CancelToken Gets or sets a CancellationToken for conversion task.
Creator Gets or sets the Creator for metadata in converted PDF.
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.
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.
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.
Footer Gets or sets Footer
Header Gets or sets Header
Height Gets or sets the width of the page in points.
IncludeBackground Gets or sets the include back ground in bool.
Keywords Gets or sets the Keywords for metadata in converted PDF.
LeftMargin Gets or sets the left margin of the page in points.
Logging Gets or sets the temporary directory path.
OverrideCssPageSize Gets or sets the override css page size in bool.
Producer Gets or sets the Producer for metadata in converted PDF.
RightMargin Gets or sets the right margin of the page in points.
Subject Gets or sets the Subject for metadata in converted PDF.
Title Gets or sets the Title for metadata in converted PDF.
TopMargin Gets or sets the top margin of the page in points.
Width Gets or sets the width of the page in points.
Zoom Determines 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)

In this topic