コード例 #1
0
        private void pdfToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Title  = "Bulmaca Pdf Kayıt";
                sfd.Filter = "Pdf Dosyası (*.pdf) | *.pdf";
                string sfdname = sfd.FileName;
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    kelimeEkleText.Focus();
                    soldanSagaSorular.BorderStyle       = BorderStyle.None;
                    yukaridanAsagiyaSorular.BorderStyle = BorderStyle.None;

                    var doc = new iTextSharp.text.Document();

                    MemoryStream ms   = new MemoryStream();
                    Bitmap       img2 = new Bitmap(A4.Width, A4.Height);
                    A4.DrawToBitmap(img2, new System.Drawing.Rectangle(0, 0, A4.Width, A4.Height));

                    iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
                    doc.Open();

                    iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(img2, System.Drawing.Imaging.ImageFormat.Png);

                    var jpeg = new Jpeg(img);
                    jpeg.ScaleToFit(doc.PageSize.Width - (doc.LeftMargin + doc.RightMargin), doc.PageSize.Height - (doc.BottomMargin + doc.TopMargin));
                    jpeg.SetAbsolutePosition(doc.BottomMargin, doc.TopMargin);

                    doc.Add(jpeg);
                    doc.Close();

                    soldanSagaSorular.BorderStyle       = BorderStyle.FixedSingle;
                    yukaridanAsagiyaSorular.BorderStyle = BorderStyle.FixedSingle;
                }
            }
            catch { }
        }
コード例 #2
0
        private void capiturar_screenshot(object sender, EventArgs e)
        {
            if (this.driver != null)
            {
                try
                {
                    //ScreenshotImageFormat format;
                    //JPG
                    if (rb_formato_jpg.Checked == true)
                    {
                        //format = ScreenshotImageFormat.Jpeg;
                        String filePathName = path + "\\" + "Screenshot_Capture_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".jpeg";
                        //((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(filePathName, format);

                        var                  bytesArray = driver.TakeScreenshot(new VerticalCombineDecorator(new ScreenshotMaker().RemoveScrollBarsWhileShooting()));
                        MemoryStream         ms         = new MemoryStream(bytesArray, 0, bytesArray.Length);
                        System.Drawing.Image image      = System.Drawing.Image.FromStream(ms, true);
                        image.Save(filePathName, System.Drawing.Imaging.ImageFormat.Jpeg);
                        bytesArray = null;
                        image.Dispose();

                        //PNG
                    }
                    else if (rb_formato_png.Checked == true)
                    {
                        //format = ScreenshotImageFormat.Png;
                        String filePathName = path + "\\" + "Screenshot_Capture_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss") + ".png";
                        //((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(filePathName, format)

                        var                  bytesArray = driver.TakeScreenshot(new VerticalCombineDecorator(new ScreenshotMaker().RemoveScrollBarsWhileShooting()));
                        MemoryStream         ms         = new MemoryStream(bytesArray, 0, bytesArray.Length);
                        System.Drawing.Image image      = System.Drawing.Image.FromStream(ms, true);
                        image.Save(filePathName, System.Drawing.Imaging.ImageFormat.Png);
                        bytesArray = null;
                        image.Dispose();

                        //PDF
                    }
                    else if (rb_formato_pdf.Checked == true)
                    {
                        //format = ScreenshotImageFormat.Jpeg;

                        String filePath     = path;
                        String fileName     = "Screenshot_Capture_" + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss");
                        String filePathName = filePath + "\\" + fileName;
                        //((ITakesScreenshot)driver).GetScreenshot().SaveAsFile(filePathName+ ".jpeg", format);

                        var                  bytesArray = driver.TakeScreenshot(new VerticalCombineDecorator(new ScreenshotMaker().RemoveScrollBarsWhileShooting()));
                        MemoryStream         ms         = new MemoryStream(bytesArray, 0, bytesArray.Length);
                        System.Drawing.Image image      = System.Drawing.Image.FromStream(ms, true);
                        image.Save(filePathName + ".jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
                        bytesArray = null;
                        image.Dispose();

                        //criando pdf
                        Document doc = new Document();
                        try {
                            iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new FileStream(filePathName + ".pdf", FileMode.Create));
                            doc.Open();
                            iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(filePathName + ".jpeg");
                            jpg.Border = iTextSharp.text.Rectangle.BOX;
                            var jpeg = new Jpeg(jpg);
                            jpeg.ScaleToFit(doc.PageSize.Width - (doc.LeftMargin + doc.RightMargin),
                                            doc.PageSize.Height - (doc.BottomMargin + doc.TopMargin));
                            doc.Add(jpeg);
                        }
                        catch (Exception ex) {
                            Console.WriteLine(ex);
                            MessageBox.Show("Tivemos algum problema ao salvar em PDF", "Mensagem");
                        } finally {
                            doc.Close();
                            File.Delete(filePathName + ".jpeg");
                        }
                    }

                    System.Diagnostics.Process.Start("Explorer", path);

                    /*
                     * var result = MessageBox.Show("Imagem salva com sucesso, " +
                     *  "deseja abrir diretorio onde a screenshot esta salva ?",
                     *  "Mensagem",
                     *  MessageBoxButtons.YesNo,
                     *  MessageBoxIcon.Question);
                     * if (result == DialogResult.Yes)  {
                     *  System.Diagnostics.Process.Start("Explorer", path);
                     * }
                     */
                } catch (Exception ex) {
                    Console.WriteLine(ex);
                    MessageBox.Show("Tivemos algum problema ao salvar a screenshot, " +
                                    "provavelmente o navegar foi fechado ou a sua primeira aba, " +
                                    "onde seria realizada a screenshot.", "Mensagem");
                    if (this.driver != null)
                    {
                        this.driver.Quit();
                    }
                }
            }
            else
            {
                MessageBox.Show("Abra o navegar através do nosso aplicativo " +
                                "antes de tentar capiturar a screenshot.", "Mensagem");
            }
        }
コード例 #3
0
        private bool SalvarImagen()
        {
            String ImgName = "_DATA_" + DateTime.Now.ToString("yyyy_MM_dd")
                             + "_HORA_" + DateTime.Now.ToString("HH_mm_ss") + "_SysScreen_";
            String ImgMine = "jpeg";

            if (pb_screenshot.Image != null)
            {
                if (cb_salvar_computador.Checked)
                {
                    SaveFileDialog sfd = new SaveFileDialog
                    {
                        FileName         = ImgName,
                        Filter           = Config.lastFormatSave,
                        InitialDirectory = Config.pathSaveImage,
                    };
                    try
                    {
                        DialogResult res = sfd.ShowDialog();
                        if (res == DialogResult.OK)
                        {
                            string ext = Path.GetExtension(sfd.FileName);
                            if (ext == ".jpeg")
                            {
                                pb_screenshot.Image.Save(sfd.FileName, ImageFormat.Jpeg);
                                Config.lastFormatSave = "JPEG|*.jpeg|PNG|*.png|PDF|*.pdf";
                                ImgMine = ".jpeg";
                            }
                            else if (ext == ".png")
                            {
                                pb_screenshot.Image.Save(sfd.FileName, ImageFormat.Png);
                                Config.lastFormatSave = "PNG|*.png|JPEG|*.jpeg|PDF|*.pdf";
                                ImgMine = ".png";
                            }
                            else if (ext == ".pdf")
                            {
                                ImgMine = ".pdf";
                                try
                                {
                                    MemoryStream ms = new MemoryStream();
                                    pb_screenshot.Image.Save(ms, ImageFormat.Jpeg);
                                    byte[] buff = ms.GetBuffer();

                                    Document doc = new Document(PageSize.A4.Rotate(), 2, 2, 2, 2);
                                    PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
                                    doc.Open();
                                    var jpeg = new Jpeg(buff);
                                    jpeg.ScaleToFit(doc.PageSize.Width - (doc.LeftMargin + doc.RightMargin), doc.PageSize.Height - (doc.BottomMargin + doc.TopMargin));
                                    doc.Add(jpeg);
                                    doc.Close();
                                }
                                catch (Exception ex)
                                {
                                    Console.WriteLine(ex);
                                    MessageBox.Show("Tivemos algum problema ao salvar em PDF", "Mensagem");
                                    return(false);
                                }
                                Config.lastFormatSave = "PDF|*.pdf|JPEG|*.jpeg|PNG|*.png";
                            }
                            Config.pathSaveImage = Path.GetDirectoryName(sfd.FileName);
                            if (cb_abrir_diretorio_imagem.Checked == true)
                            {
                                System.Diagnostics.Process.Start("Explorer", Config.pathSaveImage);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        MessageBox.Show("Tivemos algum problema para salvar a imagem no computador", "Mensagem");
                        return(false);
                    }
                    finally
                    {
                        sfd.Dispose();
                    }
                }
                // =====================================================================================
                if (cb_salvar_nuvem.Checked)
                {
                    try
                    {
                        UploadImage(pb_screenshot, "http://sysscreenwebsite/api/uploadimageapi", ImgName, ImgMine);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                        MessageBox.Show("Tivemos algum problema para enviat a imagem para nuvem", "Mensagem");
                        return(false);
                    }
                }
            }
            else
            {
                MessageBox.Show("Nenhuma imagem foi capiturada.", "Mensagem");
                return(false);
            }
            return(true);
        }