Click or drag to resize

RtfToHtmlHtmlSaveOptionsJpegQuality Property

Gets and sets the value indicating Jpeg quality level. Affects only to the images which embedded in Jpeg format. Default value: 90.

Namespace: SautinSoft
Assembly: SautinSoft.RtfToHtml (in SautinSoft.RtfToHtml.dll) Version: 2024.6.6
public int JpegQuality { get; set; }

Property Value


The amount of JPEG compression should really depend on the usage purpose for the JPEG, and the contents of the JPEG.

The quality level one should choose when exporting an image to JPEG is highly dependent upon the kind of detail contained within the image.

An image of a smooth blue sky or a sunset sky with large areas of orange gradient should probably use a high quality setting, 90-100. An image that contains nothing but complex detail could probably get away with a quality setting of 50-60, possibly even lower.There is no single "best" JPEG compression setting, and depending on the type and complexity of detail(or lack of complexity and detail), you may find yourself using 40-60, 70-80, or 90-100 as appropriate for the photo(s) you are exporting.

Here is a test with quality from left to right: 10, 20, 30, 40, 55, 70, 80, 90, 100%.
File sizes for the full files are: 210k, 278k, 347k, 477k, 601k, 709k, 987k, 1.7M, 7M.

Set jpeg quality using C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using SautinSoft;

namespace Example
    class Program
        static void Main(string[] args)
        /// <summary>
        /// How to set jpeg quality.
        /// </summary>
        static void SetJpegQuality()
            string inpFile = @"..\..\..\example.docx";
            string outFile = Path.GetFullPath(@"Result.html");
            string imgDir = Path.GetDirectoryName(outFile);

            RtfToHtml r = new RtfToHtml();

            // 1. Set JPEG format and quality.
            RtfToHtml.HtmlFixedSaveOptions opt = new RtfToHtml.HtmlFixedSaveOptions()
                ImagesDirectoryPath = Path.Combine(imgDir, "Result_images"),
                ImagesDirectorySrcPath = "Result_images",
                // Change to store images as physical files on local drive.
                EmbedImages = false,
                ImageFormat = RtfToHtml.HtmlSaveOptions.ImagesFormat.Jpeg,                
                JpegQuality = 50,
                Title = "JPEG images, 50% quality"
                r.Convert(inpFile, outFile, opt);
            catch (Exception ex)
                Console.WriteLine($"Conversion failed! {ex.Message}");

            // Open the result.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
Set jpeg quality using VB.Net
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.IO
Imports SautinSoft

Namespace Example
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
        End Sub
        ''' <summary>
        ''' How to set jpeg quality.
        ''' </summary>
        Private Shared Sub SetJpegQuality()
            Dim inpFile As String = "..\..\..\example.docx"
            Dim outFile As String = Path.GetFullPath("Result.html")
            Dim imgDir As String = Path.GetDirectoryName(outFile)

            Dim r As New RtfToHtml()

            ' 1. Set JPEG format and quality.
            Dim opt As New RtfToHtml.HtmlFixedSaveOptions() With {
                .ImagesDirectoryPath = Path.Combine(imgDir, "Result_images"),
                .ImagesDirectorySrcPath = "Result_images",
                .EmbedImages = False,
                .ImageFormat = RtfToHtml.HtmlSaveOptions.ImagesFormat.Jpeg,
                .JpegQuality = 50,
                .Title = "JPEG images, 50% quality"
                r.Convert(inpFile, outFile, opt)
            Catch ex As Exception
                Console.WriteLine($"Conversion failed! {ex.Message}")
            End Try

            ' Open the result.
            System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
        End Sub
    End Class
End Namespace
See Also