コード例 #1
0
        private void OnConvertButtonClick(object sender, EventArgs e)
        {
            PerformanceCollector pc = new PerformanceCollector("PDF creation");

            //PechkinStatic.InitLib(false);

            pc.FinishAction("Library initialized");

            SynchronizedPechkin sc = new SynchronizedPechkin(new GlobalConfig().SetMargins(new Margins(300, 100, 150, 100))
                                                             .SetDocumentTitle("Ololo").SetCopyCount(1).SetImageQuality(50)
                                                             .SetLosslessCompression(true).SetMaxImageDpi(20).SetOutlineGeneration(true).SetOutputDpi(1200).SetPaperOrientation(true)
                                                             .SetPaperSize(PaperKind.Letter));

            pc.FinishAction("Converter created");

            sc.Begin           += OnScBegin;
            sc.Error           += OnScError;
            sc.Warning         += OnScWarning;
            sc.PhaseChanged    += OnScPhase;
            sc.ProgressChanged += OnScProgress;
            sc.Finished        += OnScFinished;

            pc.FinishAction("Event handlers installed");

            byte[] buf = sc.Convert(new ObjectConfig(), htmlText.Text);

            /*sc.Convert(new ObjectConfig().SetPrintBackground(true).SetProxyString("http://localhost:8888")
             * .SetAllowLocalContent(true).SetCreateExternalLinks(false).SetCreateForms(false).SetCreateInternalLinks(false)
             * .SetErrorHandlingType(ObjectConfig.ContentErrorHandlingType.Ignore).SetFallbackEncoding(Encoding.ASCII)
             * .SetIntelligentShrinking(false).SetJavascriptDebugMode(true).SetLoadImages(true).SetMinFontSize(16)
             * .SetRenderDelay(2000).SetRunJavascript(true).SetIncludeInOutline(true).SetZoomFactor(2.2), htmlText.Text);*/

            pc.FinishAction("conversion finished");

            if (buf == null)
            {
                MessageBox.Show("Error converting!");

                return;
            }

            //for (int i = 0; i < 1000; i++)
            {
                buf = sc.Convert(new ObjectConfig(), htmlText.Text);

                if (buf == null)
                {
                    MessageBox.Show("Error converting!");

                    return;
                }
            }

            pc.FinishAction("1 more conversions finished");

            try
            {
                string fn = Path.GetTempFileName() + ".pdf";

                FileStream fs = new FileStream(fn, FileMode.Create);
                fs.Write(buf, 0, buf.Length);
                fs.Close();

                pc.FinishAction("dumped file to disk");

                Process myProcess = new Process();
                myProcess.StartInfo.FileName = fn;
                myProcess.Start();

                pc.FinishAction("opened it");
            } catch { }

            pc.ShowInMessageBox(null);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: kimx/Examples
        private void OnConvertButtonClick(object sender, EventArgs e)
        {
            PerformanceCollector pc = new PerformanceCollector("PDF creation");

            pc.FinishAction("Library initialized");

            IPechkin sc = Factory.Create(new GlobalConfig().SetMargins(new Margins(300, 100, 150, 100))
                .SetDocumentTitle("Ololo").SetCopyCount(1).SetImageQuality(50)
                .SetLosslessCompression(true).SetMaxImageDpi(20).SetOutlineGeneration(true).SetOutputDpi(1200).SetPaperOrientation(true)
                .SetPaperSize(PaperKind.Letter));

            pc.FinishAction("Converter created");

            sc.Begin += OnScBegin;
            sc.Error += OnScError;
            sc.Warning += OnScWarning;
            sc.PhaseChanged += OnScPhase;
            sc.ProgressChanged += OnScProgress;
            sc.Finished += OnScFinished;

            pc.FinishAction("Event handlers installed");

            byte[] buf = sc.Convert(new ObjectConfig(), htmlText.Text);
                /*sc.Convert(new ObjectConfig().SetPrintBackground(true).SetProxyString("http://localhost:8888")
                .SetAllowLocalContent(true).SetCreateExternalLinks(false).SetCreateForms(false).SetCreateInternalLinks(false)
                .SetErrorHandlingType(ObjectConfig.ContentErrorHandlingType.Ignore).SetFallbackEncoding(Encoding.ASCII)
                .SetIntelligentShrinking(false).SetJavascriptDebugMode(true).SetLoadImages(true).SetMinFontSize(16)
                .SetRenderDelay(2000).SetRunJavascript(true).SetIncludeInOutline(true).SetZoomFactor(2.2), htmlText.Text);*/

            pc.FinishAction("conversion finished");

            if (buf == null)
            {
                MessageBox.Show("Error converting!");

                return;
            }

            //for (int i = 0; i < 1000; i++)
            {
                buf = sc.Convert(new ObjectConfig(), htmlText.Text);

                if (buf == null)
                {
                    MessageBox.Show("Error converting!");

                    return;
                }
            }

            pc.FinishAction("1 more conversions finished");

            try
            {
                string fn = Path.GetTempFileName() + ".pdf";

                FileStream fs = new FileStream(fn, FileMode.Create);
                fs.Write(buf, 0, buf.Length);
                fs.Close();

                pc.FinishAction("dumped file to disk");

                Process myProcess = new Process();
                myProcess.StartInfo.FileName = fn;
                myProcess.Start();

                pc.FinishAction("opened it");
            } catch { }

            pc.ShowInMessageBox(null);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: wislon/TuesPechkin
        private void OnConvertButtonClick(object sender, EventArgs e)
        {
            PerformanceCollector pc = new PerformanceCollector("PDF creation");

            var document = new HtmlToPdfDocument
            {
                GlobalSettings =
                {
                    ProduceOutline = true,
                    DocumentTitle  = "Business Document",
                    PaperSize      = PaperKind.A4,
                    Margins        =
                    {
                        Top    =                 1.5,
                        Right  =                   1,
                        Bottom =                   1,
                        Left   =                1.25,
                        Unit   = Unit.Centimeters
                    }
                },
                Objects =
                {
                    new ObjectSettings {
                        HtmlText = this.htmlText.Text
                    }
                }
            };

            IPechkin sc2 = Factory.Create();
            var      buf = sc2.Convert(document);

            MessageBox.Show("All conversions done");

            pc.FinishAction("conversion finished");

            if (buf == null)
            {
                MessageBox.Show("Error converting!");

                return;
            }

            try
            {
                string fn = string.Format("{0}.pdf", Path.GetTempFileName());

                FileStream fs = new FileStream(fn, FileMode.Create);
                fs.Write(buf, 0, buf.Length);
                fs.Close();

                pc.FinishAction("dumped file to disk");

                Process myProcess = new Process();
                myProcess.StartInfo.FileName = fn;
                myProcess.Start();

                pc.FinishAction("opened it");
            }
            catch
            {
            }

            pc.ShowInMessageBox(null);
        }
コード例 #4
-1
ファイル: MainForm.cs プロジェクト: JamesPatison/TuesPechkin
        private void OnConvertButtonClick(object sender, EventArgs e)
        {
            PerformanceCollector pc = new PerformanceCollector("PDF creation");

            var document = new HtmlToPdfDocument
            {
                GlobalSettings = {
                    ProduceOutline = true,
                    DocumentTitle = "Business Document",
                    PaperSize = PaperKind.A4,
                    Margins = {
                        Top = 1.5,
                        Right = 1,
                        Bottom = 1,
                        Left = 1.25,
                        Unit = Unit.Centimeters
                    }
                },
                Objects = {
                    new ObjectSettings { HtmlText = this.htmlText.Text }
                }
            };

            IPechkin sc2 = Factory.Create();
            var buf = sc2.Convert(document);

            MessageBox.Show("All conversions done");

            pc.FinishAction("conversion finished");

            if (buf == null)
            {
                MessageBox.Show("Error converting!");

                return;
            }

            try
            {
                string fn = string.Format("{0}.pdf", Path.GetTempFileName());

                FileStream fs = new FileStream(fn, FileMode.Create);
                fs.Write(buf, 0, buf.Length);
                fs.Close();

                pc.FinishAction("dumped file to disk");

                Process myProcess = new Process();
                myProcess.StartInfo.FileName = fn;
                myProcess.Start();

                pc.FinishAction("opened it");
            }
            catch
            {
            }

            pc.ShowInMessageBox(null);
        }