Convert HTML to TIFF

Using Converter.ConvertHTML methods is the most common way to convert HTML code into various formats. Converting HTML files to TIFF images may be required, for example, if you want to add a web page in a PowerPoint presentation or send it by e-mail. With Aspose.HTML for .NET, you can convert HTML to TIFF format programmatically with full control over a wide range of conversion parameters.

HTML to TIFF conversion allows you to save an HTML document as a TIFF image. In this article, you find information on how to convert HTML to TIFF using ConvertHTML() methods of the Converter class, and how to apply ImageSaveOptions and ICreateStreamProvider parameters.

Online HTML Converter

You can check the Aspose.HTML API functionality and convert HTML in real-time. Please load HTML from the local file system, select the output format and run the example. In the example, the save options are set by default. You will immediately receive the result as a separate file.

                
            

If you want to convert HTML to TIFF programmatically, please see the following C# code examples.

Convert HTML to TIFF

Converting a file to another format using the ConvertHTML() method is a sequence of operations among which document loading and saving:

  1. Load an HTML file using the HTMLDocument class.
  2. Create a new ImageSaveOptions object with TIFF ImageFormat. By default, the Format property is PNG.
  3. Use the ConvertHTML() method of the Converter class to save HTML as a TIFF image. You need to pass the HTMLDocument, ImageSaveOptions, and output file path to the ConvertHTML() method to convert HTML to TIFF.

Please take a look over the following C# code snippet which shows the process of converting HTML to TIFF using Aspose.HTML for .NET.

 1// Prepare a path to a source HTML file
 2string documentPath = Path.Combine(DataDir, "nature.html");
 3
 4// Prepare a path for converted file saving 
 5string savePath = Path.Combine(OutputDir, "nature-output.tiff");
 6
 7// Initialize an HTML document from the file
 8using var document = new HTMLDocument(documentPath);
 9
10// Create an instance of the ImageSaveOptions class 
11var options = new ImageSaveOptions(ImageFormat.Tiff);
12
13// Convert HTML to TIFF
14Converter.ConvertHTML(document, options, savePath);

Save Options

Aspose.HTML allows converting HTML to TIFF using default or custom save options. ImageSaveOptions usage enables you to customize the rendering process. You can specify the image format, page size, margins, compression level, CSS media-type, etc.

PropertyDescription
CompressionSets Tagged Image File Format (TIFF) Compression. By default, this property is LZW.
CSSGets a CssOptions object which is used for configuration of CSS properties processing.
FormatSets the ImageFormat (JPG, PNG, BMP, TIFF, or GIF). By default, this property is PNG.
BackgroundColorThis property sets the color that will fill the background. By default, this property is Transparent.
PageSetupThis property gets a page setup object and uses it for configuration output page-set.
HorizontalResolutionSets horizontal resolution for output images in pixels per inch. The default value is 300 dpi.
VerticalResolutionSets vertical resolution for output images in pixels per inch. The default value is 300 dpi.
UseAntialiasingThis property sets the image rendering quality. Antialiasing is enabled by default.
TextGets a TextOptions object which is used for configuration of text rendering.

To learn more about the ImageSaveOptions class, please read the Fine-Tuning Converters article.

Convert HTML to TIFF using ImageSaveOptions

To convert HTML to TIFF with ImageSaveOptions specifying, you should follow a few steps:

  1. Load an HTML file using one of the HTMLDocument() constructors of the HTMLDocument class.
  2. Create a new ImageSaveOptions object with TIFF ImageFormat and specify save options. By default, the Format property is PNG.
  3. Use the ConvertHTML() method of the Converter class to save HTML as a TIFF image. You need to pass the HTMLDocument, ImageSaveOptions, and output file path to the ConvertHTML() method to convert HTML to TIFF.

The following C# code snippet shows how to convert HTML to TIFF using custom save options:

 1string documentPath = Path.Combine(DataDir, "nature.html");
 2string savePath = Path.Combine(OutputDir, "nature-output-options.tiff");
 3
 4
 5// Initialize an HTML Document from the html file
 6using var document = new HTMLDocument(documentPath);
 7
 8// Initialize ImageSaveOptions 
 9var options = new ImageSaveOptions(ImageFormat.Tiff)
10{
11    Compression = Compression.None,
12    BackgroundColor = System.Drawing.Color.Bisque,
13    HorizontalResolution = 150,
14    VerticalResolution = 150,
15    UseAntialiasing = true,
16};
17
18// Convert HTML to TIFF
19Converter.ConvertHTML(document, options, savePath);

The ImageSaveOptions() constructor initializes an instance of the ImageSaveOptions class that is passed to ConvertHTML() method. The ConvertHTML() method takes the document, options, output file path savePath and performs the conversion operation.

In the above example, we add:

You can download the complete examples and data files from GitHub.

Aspose.HTML offers a free online HTML to TIFF Converter that converts HTML to TIFF image with high quality, easy and fast. Just upload, convert your files and get results in a few seconds!

Text “HTML to TIFF Converter”

Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.