} // End Task ClosePage

        public static void ConvertData(ConversionData conversionData)
        {
            ConvertDataAsync(conversionData).Wait();
        } // End Sub ConvertData
        } // End Function ConnectToChrome

        public static async System.Threading.Tasks.Task ConvertDataAsync(ConversionData conversionData)
        {
#if false
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
#endif

            MasterDevs.ChromeDevTools.IChromeSessionFactory chromeSessionFactory = new MasterDevs.ChromeDevTools.ChromeSessionFactory();

            using (ConnectionInfo connectionInfo = await ConnectToChrome(conversionData.ChromePath, conversionData.RemoteDebuggingUri))
            {
                MasterDevs.ChromeDevTools.IChromeSession chromeSession = chromeSessionFactory.Create(connectionInfo.SessionInfo.WebSocketDebuggerUrl);

                // STEP 3 - Send a command
                //
                // Here we are sending a commands to tell chrome to set the viewport size
                // and navigate to the specified URL
                await chromeSession.SendAsync(new SetDeviceMetricsOverrideCommand
                {
                    Width  = conversionData.ViewPortWidth,
                    Height = conversionData.ViewPortHeight,
                    Scale  = 1
                });

                MasterDevs.ChromeDevTools.CommandResponse <NavigateCommandResponse> navigateResponse =
                    await chromeSession.SendAsync(new NavigateCommand
                {
                    // Url = "http://www.google.com"
                    Url = "about:blank"
                });

                System.Console.WriteLine("NavigateResponse: " + navigateResponse.Id);

                MasterDevs.ChromeDevTools.CommandResponse <SetDocumentContentCommandResponse> setContentResponse =
                    await chromeSession.SendAsync(new SetDocumentContentCommand()
                {
                    FrameId = navigateResponse.Result.FrameId,
                    Html    = conversionData.Html
                }
                                                  );



                // private static double cm2inch(double centimeters) { return centimeters * 0.0393701; }
                UnitConversion_t cm2inch = delegate(double centimeters) { return(centimeters * 0.393701); };
                // private static double mm2inch(double milimeters) { return milimeters * 0.0393701; }
                UnitConversion_t mm2inch = delegate(double milimeters) { return(milimeters * 0.0393701); };


                PrintToPDFCommand printCommand2 = new PrintToPDFCommand()
                {
                    Scale           = 1,
                    MarginTop       = 0,
                    MarginLeft      = 0,
                    MarginRight     = 0,
                    MarginBottom    = 0,
                    PrintBackground = true,
                    Landscape       = false,
                    // PaperWidth = cm2inch(21),
                    // PaperHeight = cm2inch(29.7),

                    // PaperWidth = cm2inch(conversionData.PageWidth),
                    // PaperHeight = cm2inch(conversionData.PageHeight)

                    PaperWidth  = mm2inch(conversionData.PageWidth),
                    PaperHeight = mm2inch(conversionData.PageHeight)
                };

                // await System.Threading.Tasks.Task2.Delay(300);


                if (conversionData.ChromiumActions.HasFlag(ChromiumActions_t.GetVersion))
                {
                    try
                    {
                        System.Diagnostics.Debug.WriteLine("Getting browser-version");

                        MasterDevs.ChromeDevTools.CommandResponse <GetVersionCommandResponse> version =
                            await chromeSession.SendAsync(new GetVersionCommand());

                        System.Diagnostics.Debug.WriteLine("Got browser-version");

                        conversionData.Version = version.Result;
                    }
                    catch (System.Exception ex)
                    {
                        conversionData.Exception = ex;
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                } // End if (conversionData.ChromiumActions.HasFlag(ChromiumActions_t.GetVersion))



                if (conversionData.ChromiumActions.HasFlag(ChromiumActions_t.ConvertToImage))
                {
                    try
                    {
                        System.Diagnostics.Debug.WriteLine("Taking screenshot");

                        MasterDevs.ChromeDevTools.CommandResponse <CaptureScreenshotCommandResponse> screenshot =
                            await chromeSession.SendAsync(new CaptureScreenshotCommand { Format = "png" });

                        System.Diagnostics.Debug.WriteLine("Screenshot taken.");

                        conversionData.PngData = System.Convert.FromBase64String(screenshot.Result.Data);
                    }
                    catch (System.Exception ex)
                    {
                        conversionData.Exception = ex;
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                } // End if (conversionData.ChromiumActions.HasFlag(ChromiumActions_t.ConvertToImage))


                if (conversionData.ChromiumActions.HasFlag(ChromiumActions_t.ConvertToPdf))
                {
                    try
                    {
                        System.Diagnostics.Debug.WriteLine("Printing PDF");

                        MasterDevs.ChromeDevTools.CommandResponse <PrintToPDFCommandResponse> pdf =
                            await chromeSession.SendAsync(printCommand2);

                        System.Diagnostics.Debug.WriteLine("PDF printed.");

                        conversionData.PdfData = System.Convert.FromBase64String(pdf.Result.Data);
                    }
                    catch (System.Exception ex)
                    {
                        conversionData.Exception = ex;
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                } // End if (conversionData.ChromiumActions.HasFlag(ChromiumActions_t.ConvertToPdf))


                System.Console.WriteLine("Closing page");
                await ClosePage(chromeSession, navigateResponse.Result.FrameId, true);

                System.Console.WriteLine("Page closed");
            } // End Using connectionInfo
        }     // End Sub ConvertDataAsync