HiQPdf Documentation

HTML to SVG Converter

Quickly Create High Quality PDFs

The HTML to SVG converter allows you to quickly create a vectorial representation of the HTML documents in SVG format. The class representing the HTML to SVG converter is HiQPdfHtmlToSvg.

The most important features of the HTML to SVG Converter are described in detail in the topics below.

Serial Number

The SerialNumber property of the of the HiQPdf.HtmlToSvg class must be set with the purchased serial number as described in the License Purchasing section. In the sample code below is set with an evaluation serial number.

The Document DPI

The HtmlToSvgDPI property can be used to control the SVG document resolution in DPI.

Set Size in Document

The SetSize property controls if the calculated size of the document is set in the SVG document.

Load HTML Timeout

The HtmlLoadedTimeout property of the HiQPdf.HtmlToSvg class controls the maximum time in seconds to wait for HTML document to be loaded. The default value is 120 seconds. An exception is thrown if the HTML document cannot be loaded in HtmlLoadedTimeout seconds.

Convert Methods

The Convert methods of the of the HiQPdf.HtmlToSvg class are finally called to convert HTML documents to SVG. Function of how the HTML document to be converted is given, by URL or by content, and function of where the output SVG document is written the following Convert methods are defined in the HiQPdf.HtmlToSvg class:

Methods to convert the HTML document from a given URL to SVG:

Methods to convert a HTML code to SVG:

HTML to Image Converter Demo

In this demo you can convert an URL, a local file or a custom HTML code to a SVG vectorial image. You can set the browser width in pixels. In evaluation mode only the top part of the HTML document is converted to SVG. In the licensed version there is not such a limitation.

Demo Source Code

C#
private void buttonConvertToSvg_Click(object sender, EventArgs e)
{
    // create the HTML to SVG converter
    HtmlToSvg htmlToSvgConverter = new HtmlToSvg();

    // set browser width
    htmlToSvgConverter.BrowserWidth = int.Parse(textBoxBrowserWidth.Text);

    // set browser height if specified, otherwise use the default
    if (textBoxBrowserHeight.Text.Length > 0)
        htmlToSvgConverter.BrowserHeight = int.Parse(textBoxBrowserHeight.Text);

    // set HTML Load timeout
    htmlToSvgConverter.HtmlLoadedTimeout = int.Parse(textBoxLoadHtmlTimeout.Text);

    // set triggering mode; for WaitTime mode set the wait time before convert
    switch (comboBoxTriggeringMode.SelectedItem.ToString())
    {
        case "Auto":
            htmlToSvgConverter.TriggerMode = ConversionTriggerMode.Auto;
            break;
        case "WaitTime":
            htmlToSvgConverter.TriggerMode = ConversionTriggerMode.WaitTime;
            htmlToSvgConverter.WaitBeforeConvert = int.Parse(textBoxWaitTime.Text);
            break;
        case "Manual":
            htmlToSvgConverter.TriggerMode = ConversionTriggerMode.Manual;
            break;
        default:
            htmlToSvgConverter.TriggerMode = ConversionTriggerMode.Auto;
            break;
    }

    this.Cursor = Cursors.WaitCursor;

    // convert to SVG
    string svgFile = null;
    try
    {
        if (radioButtonConvertUrl.Checked)
        {
            // convert URL
            string url = textBoxUrl.Text;
            svgFile = Application.StartupPath + @"\DemoOut\ConvertUrl.svg";

            // ConvertUrlToFile() is called to convert the html document and save the resulted SVG into a file on disk
            // Alternatively, ConvertUrlToMemory() can be called to save the resulted SVG in a buffer in memory
            htmlToSvgConverter.ConvertUrlToFile(url, svgFile);
        }
        else
        {
            // convert HTML code
            string htmlCode = textBoxHtmlCode.Text;
            string baseUrl = textBoxBaseUrl.Text;
            svgFile = Application.StartupPath + @"\DemoOut\ConvertHtml.svg";

            htmlToSvgConverter.ConvertHtmlToFile(htmlCode, baseUrl, svgFile);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(String.Format("Conversion failed. {0}", ex.Message));
        return;
    }
    finally
    {
        this.Cursor = Cursors.Arrow;
    }

    // open the SVG document
    try
    {
        System.Diagnostics.Process.Start(svgFile);
    }
    catch (Exception ex)
    {
        MessageBox.Show(String.Format("Conversion succeeded but cannot open '{0}'. {1}", svgFile, ex.Message));
    }
}
See Also

Other Resources