HiQPdf Documentation

HTML to SVG Converter

HiQPdf Client for .NET Core

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 HiQPdfClientHtmlToSvg.

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 HiQPdfClient.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 HiQPdfClient.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 HiQPdfClient.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 HiQPdfClient.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#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;

using HiQPdfClient;

namespace HiQPdf_Demo.Controllers
{
    public class ConvertHtmlToSvgController : Controller
    {
        // GET: ConvertHtmlToSvg
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult ConvertToSvg(IFormCollection collection)
        {
            string serverIP = collection["textBoxServerIP"];
            uint serverPort = uint.Parse(collection["textBoxServerPort"]);
            string serverPassword = collection["textBoxServerPassword"];

            // create the HTML to SVG converter
            HtmlToSvg htmlToSvgConverter = new HtmlToSvg(serverIP, serverPort);

            // use server password if necessary
            if (serverPassword.Length > 0)
                htmlToSvgConverter.ServerPassword = serverPassword;

            // set a demo serial number
            htmlToSvgConverter.SerialNumber = "YCgJMTAE-BiwJAhIB-EhlWTlBA-UEBRQFBA-U1FOUVJO-WVlZWQ==";

            // set browser width
            htmlToSvgConverter.BrowserWidth = int.Parse(collection["textBoxBrowserWidth"]);

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

            // set HTML Load timeout
            htmlToSvgConverter.HtmlLoadedTimeout = int.Parse(collection["textBoxLoadHtmlTimeout"]);

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

            // convert to SVG
            string svgFileName = "HtmlToSvg.svg";
            byte[] svgBuffer = null;

            if (collection["UrlOrHtmlCode"] == "radioButtonConvertUrl")
            {
                // convert URL
                string url = collection["textBoxUrl"];

                svgBuffer = htmlToSvgConverter.ConvertUrlToMemory(url);
            }
            else
            {
                // convert HTML code
                string htmlCode = collection["textBoxHtmlCode"];
                string baseUrl = collection["textBoxBaseUrl"];

                svgBuffer = htmlToSvgConverter.ConvertHtmlToMemory(htmlCode, baseUrl);
            }

            FileResult fileResult = new FileContentResult(svgBuffer, "image/svg+xml");
            fileResult.FileDownloadName = svgFileName;

            return fileResult;
        }
    }
}
See Also

Other Resources