示例#1
0
        static void Main(string[] args)
        {
            if (args.Length != 2) {
                PrintInstructions();
                return;
            }

            if (args[1].EndsWith(".pdf")) {
                WkHtmlToPdfConverter conv = new WkHtmlToPdfConverter();
                conv.GlobalSettings.Out = args[1];
                conv.ObjectSettings.Page = args[0];

                int phaseLine = Console.CursorTop + 1;
                int progressLine = phaseLine + 1;

                conv.PhaseChanged += (sender, eventArgs) => { Console.CursorTop = phaseLine; Console.CursorLeft = 0; Console.Write("Phase: {0} - {1}", eventArgs.Value, eventArgs.Value2); };
                conv.ProgressChanged += (sender, eventArgs) => { Console.CursorTop = progressLine; Console.CursorLeft = 0; Console.Write("Progress: {0} - {1}", eventArgs.Value, eventArgs.Value2); };
                conv.Finished += (sender, eventArgs) => { Console.CursorTop = progressLine + 2; Console.CursorLeft = 0; };

                conv.Convert();

                conv.Dispose();
            } else {
                WkHtmlToImageConverter conv = new WkHtmlToImageConverter();
                conv.GlobalSettings.Out = args[1];
                conv.GlobalSettings.In = args[0];

                int phaseLine = Console.CursorTop + 1;
                int progressLine = phaseLine + 1;

                conv.PhaseChanged += (sender, eventArgs) => { Console.CursorTop = phaseLine; Console.CursorLeft = 0; Console.Write("Phase: {0} - {1}", eventArgs.Value, eventArgs.Value2); };
                conv.ProgressChanged += (sender, eventArgs) => { Console.CursorTop = progressLine; Console.CursorLeft = 0; Console.Write("Progress: {0} - {1}", eventArgs.Value, eventArgs.Value2); };
                conv.Finished += (sender, eventArgs) => { Console.CursorTop = progressLine + 2; Console.CursorLeft = 0; };

                conv.Convert();

                conv.Dispose();
            }
        }
示例#2
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            BackgroundWorker bgw = new BackgroundWorker();
            bgw.WorkerReportsProgress = true;

            //string address = tbHttpAddress.Text;
            string outputFile = tbOutputFile.Text;

            bgw.ProgressChanged += (o, args) => {
                progressBar1.Value = args.ProgressPercentage;
                lblProgress.Text = args.UserState as string;
            };

            if (outputFile.EndsWith(".pdf")) {
                bgw.DoWork += (o, args) => {
                    Tuple<string, string> t = args.Argument as Tuple<string, string>;

                    string address = t.Item1;
                    string outFile = t.Item2;

                    WkHtmlToPdfConverter conv = new WkHtmlToPdfConverter();
                    conv.ObjectSettings.Page = address;
                    conv.GlobalSettings.Out = outFile;
                    conv.ProgressChanged += (sender1, eventArgs) => bgw.ReportProgress(eventArgs.Value, eventArgs.Value2);
                    conv.PhaseChanged += (sender1, eventArgs) => this.Invoke(new Action(() => { lblPhase.Text = string.Format("Phase {0}: {1}", eventArgs.Value, eventArgs.Value2); }));

                    conv.Convert();

                    conv.Dispose();
                };
            } else if (outputFile.EndsWith(".jpg") || outputFile.EndsWith(".png")) {
                bgw.DoWork += (o, args) => {
                    Tuple<string, string> t = args.Argument as Tuple<string, string>;

                    string address = t.Item1;
                    string outFile = t.Item2;

                    WkHtmlToImageConverter conv = new WkHtmlToImageConverter();
                    conv.GlobalSettings.In = address;
                    conv.GlobalSettings.Out = outFile;
                    conv.ProgressChanged += (sender1, eventArgs) => bgw.ReportProgress(eventArgs.Value, eventArgs.Value2);
                    conv.PhaseChanged += (sender1, eventArgs) => this.Invoke(new Action(() => { lblPhase.Text = string.Format("Phase {0}: {1}", eventArgs.Value, eventArgs.Value2); }));

                    conv.Convert();

                    conv.Dispose();
                };
            }

            bgw.RunWorkerCompleted += (o, args) => bgw.Dispose();

            bgw.RunWorkerAsync(new Tuple<string, string>(tbHttpAddress.Text, outputFile));
        }