Esempio n. 1
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add pages to PDF document
        /// </summary>
        /// <remarks>
        /// The PrintDoc.Print method will call BeginPrint method,
        /// next it will call multiple times PrintPage method and finally
        /// it will call EndPrint method.
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public void AddPagesToPdfDocument()
        {
            // print the document by calling BeginPrint, PrintPage multiple times and finally EndPrint
            Print();

            // get printing results in the form of array of images one per page
            // image format is Metafile
            PreviewPageInfo[] PageInfo = ((PreviewPrintController)PrintController).GetPreviewPageInfo();

            // page size in user units
            Double PageWidth  = Document.PageSize.Width / Document.ScaleFactor;
            Double PageHeight = Document.PageSize.Height / Document.ScaleFactor;

            // define empty image source rectangle
            Rectangle SourceRect = new Rectangle();

            // add pages to pdf document
            for (Int32 ImageIndex = 0; ImageIndex < PageInfo.Length; ImageIndex++)
            {
                // add page to document
                PdfPage Page = new PdfPage(Document);

                // add contents to the page
                PdfContents Contents = new PdfContents(Page);

                // page image
                Image PageImage = PageInfo[ImageIndex].Image;

                // no crop
                if (CropRect.IsEmpty)
                {
                    // convert metafile image to PdfImage
                    PdfImage Image = new PdfImage(Contents.Document, PageImage, Resolution);

                    // draw the image
                    Contents.DrawImage(Image, 0.0, 0.0, PageWidth, PageHeight);
                }

                // crop
                else
                {
                    Int32 ImageWidth  = PageImage.Width;
                    Int32 ImageHeight = PageImage.Height;
                    SourceRect.X      = (Int32)(ImageWidth * CropRect.X / PageWidth + 0.5);
                    SourceRect.Y      = (Int32)(ImageHeight * CropRect.Y / PageHeight + 0.5);
                    SourceRect.Width  = (Int32)(ImageWidth * CropRect.Width / PageWidth + 0.5);
                    SourceRect.Height = (Int32)(ImageHeight * CropRect.Height / PageHeight + 0.5);

                    // convert metafile image to PdfImage
                    PdfImage PdfPageImage = new PdfImage(Contents.Document, PageImage, SourceRect, Resolution);

                    // draw the image
                    Contents.DrawImage(PdfPageImage, CropRect.X, PageHeight - CropRect.Y - CropRect.Height, CropRect.Width, CropRect.Height);
                }
            }
            return;
        }
Esempio n. 2
0
 public static void DrawFullPageImage( this PdfContents contents, PdfImage image, bool landscape )
 {
     if ( landscape == true )
     {
         contents.DrawImage( image, 0, 0, 29.7, 21 );
     }
     else
     {
         contents.DrawImage( image, 0, 0, 21, 29.7 );
     }
 }
Esempio n. 3
0
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add pages to PDF document
        /// </summary>
        /// <remarks>
        /// The PrintDoc.Print method will call BeginPrint method,
        /// next it will call multiple times PrintPage method and finally
        /// it will call EndPrint method.
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public void AddPagesToPdfDocument()
        {
            // print the document by calling BeginPrint, PrintPage multiple times and finally EndPrint
            Print();

            // get printing results in the form of array of images one per page
            // image format is Metafile
            PreviewPageInfo[] PageInfo = ((PreviewPrintController)PrintController).GetPreviewPageInfo();

            // page size in user units
            double PageWidth  = Document.PageSize.Width / Document.ScaleFactor;
            double PageHeight = Document.PageSize.Height / Document.ScaleFactor;

            // add pages to pdf document
            for (int ImageIndex = 0; ImageIndex < PageInfo.Length; ImageIndex++)
            {
                // add page to document
                PdfPage Page = new PdfPage(Document);

                // add contents to the page
                PdfContents Contents = new PdfContents(Page);

                // page image
                Image PageImage = PageInfo[ImageIndex].Image;

                // empty pdf image
                PdfImage PdfImage = new PdfImage(Contents.Document);
                PdfImage.Resolution     = Resolution;
                PdfImage.SaveAs         = SaveAs;
                PdfImage.ImageQuality   = ImageQuality;
                PdfImage.GrayToBWCutoff = GrayToBWCutoff;
                PdfImage.CropRect       = Rectangle.Empty;
                PdfImage.CropPercent    = RectangleF.Empty;

                // no crop
                if (PageCropRect.IsEmpty)
                {
                    // convert metafile image to PdfImage
                    PdfImage.LoadImage(PageImage);

                    // draw the image
                    Contents.DrawImage(PdfImage, 0.0, 0.0, PageWidth, PageHeight);
                }

                // crop
                else
                {
                    int ImageWidth  = PageImage.Width;
                    int ImageHeight = PageImage.Height;
                    PdfImage.CropRect.X      = (int)(ImageWidth * PageCropRect.X / PageWidth + 0.5);
                    PdfImage.CropRect.Y      = (int)(ImageHeight * PageCropRect.Y / PageHeight + 0.5);
                    PdfImage.CropRect.Width  = (int)(ImageWidth * PageCropRect.Width / PageWidth + 0.5);
                    PdfImage.CropRect.Height = (int)(ImageHeight * PageCropRect.Height / PageHeight + 0.5);

                    // convert metafile image to PdfImage
                    PdfImage.LoadImage(PageImage);

                    // draw the image
                    Contents.DrawImage(PdfImage, PageCropRect.X, PageHeight - PageCropRect.Y - PageCropRect.Height, PageCropRect.Width, PageCropRect.Height);
                }
            }
            return;
        }
Esempio n. 4
0
		void CreatePDFFile( IEnumerable<ScannedImageViewModel> items, string filename )
		{
			try
			{
				// Save document
				var Document = new PdfDocument( PaperType.A4, false, UnitOfMeasure.cm, filename );

				// add to pdf file all images from collection
				foreach ( ScannedImageViewModel scan in items )
				{
					var page = new PdfPage( Document, PaperType.A4, scan.Image.Landscape );
					var contents = new PdfContents( page );
					var image = new PdfImage( Document, scan.Image.Source, 0, PdfQuality );
					contents.DrawFullPageImage( image, scan.Image.Landscape );
				}
				Document.CreateFile();
			}
			catch ( IOException )
			{
				// localization dictionary
				var dictionary = Application.Current.Resources.MergedDictionaries[ 0 ];
				Notify = new Notify( (string) dictionary[ "er_CantCreateFile" ], Notify.Type.Warning );
			}
			catch ( Exception ex )
			{
				Notify = new Notify( ex.Message, Notify.Type.Warning );
			}
		}
        private void DrawPicturePai(
            PdfDocument Document,
            PdfContents Contents
            )
        {
            // define local image resources
            PdfImage Image1 = new PdfImage(Document, "D:\\visual studio 2012\\TestPDFFileWriter\\TestPDFFileWriter\\logo.png");

            // image size will be limited to 1.4" by 1.4"
            SizeD ImageSize = Image1.ImageSize(1.4, 1.4);

            // save graphics state
            Contents.SaveGraphicsState();

            // translate coordinate origin to the center of the picture
            Contents.Translate(3.36, 5.7);

            // clipping path
            //   Contents.DrawOval(-ImageSize.Width / 2, -ImageSize.Height / 2, ImageSize.Width, ImageSize.Height, PaintOp.ClipPathEor);

            // draw image
            Contents.DrawImage(Image1, -ImageSize.Width / 2, -ImageSize.Height / 2, ImageSize.Width, ImageSize.Height);

            // restore graphics state
            Contents.RestoreGraphicsState();
            return;
        }
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Draw image
        /// </summary>
        /// <param name="Image">PdfImage resource</param>
        /// <param name="OriginX">Origin X</param>
        /// <param name="OriginY">Origin Y</param>
        /// <param name="Width">Display width</param>
        /// <param name="Height">Display height</param>
        /// <remarks>
        /// The chart will be stretched or shrunk to fit the display width
        /// and display height. Use PdfImage.ImageSize(...) or 
        /// PdfImage.ImageSizePosition(...) to ensure correct aspect ratio 
        /// and positioning.
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public void DrawImage(
			PdfImage	Image,
			Double		OriginX,
			Double		OriginY,
			Double		Width,
			Double		Height
			)
        {
            // add image code to current list of resources
            AddToUsedResources(Image);

            // draw image
            ContentsString.AppendFormat(NFI.PeriodDecSep, "q {0} 0 0 {1} {2} {3} cm {4} Do Q\n",
            ToPt(Width), ToPt(Height), ToPt(OriginX), ToPt(OriginY), Image.ResourceCode);
            return;
        }
        private void mandarButton_Click(object sender, EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;

              String connString = "Database=" + Properties.Settings.Default.databaseFiscal + ";Data Source=" + Properties.Settings.Default.datasource + ";Integrated Security=False;User ID='" + Properties.Settings.Default.user + "';Password='******';connect timeout = 10";
              try
              {

                  using (SqlConnection connection = new SqlConnection(connString))
                  {
                      connection.Open();
                      String queryXML = "";
                      if(Login.unidadDeNegocioGlobal.Equals("FOP"))
                      {
                          queryXML = "SELECT b.ADDR_LINE_1,b.ADDR_LINE_2,b.ADDR_LINE_3,b.ADDR_LINE_4,b.ADDR_LINE_5  , a.AMOUNT, a.TRANS_DATETIME,a.DESCRIPTN,a.JRNAL_SRCE, a.ANAL_T0,a.ACCNT_CODE,c.DESCR FROM [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_" + Properties.Settings.Default.sunLibro + "_SALFLDG] a INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_ADDR] b on a.ANAL_T2 = b.ADDR_CODE INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[FOP_ACNT] c on c.ACNT_CODE = a.ACCNT_CODE WHERE a.JRNAL_NO = " + diarioText.Text + " AND a.ANAL_T9 = '" + iglesiaText.Text + "'";
                      }
                      else
                      {
                          queryXML = "SELECT b.ADDR_LINE_1,b.ADDR_LINE_2,b.ADDR_LINE_3,b.ADDR_LINE_4,b.ADDR_LINE_5  , a.AMOUNT, a.TRANS_DATETIME,a.DESCRIPTN,a.JRNAL_SRCE, a.ANAL_T0,a.ACCNT_CODE,c.DESCR FROM [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_" + Properties.Settings.Default.sunLibro + "_SALFLDG] a INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_ADDR] b on a.ANAL_T2 = b.ADDR_CODE INNER JOIN [" + Properties.Settings.Default.sunDatabase + "].[dbo].[" + Login.unidadDeNegocioGlobal + "_ACNT] c on c.ACNT_CODE = a.ACCNT_CODE WHERE a.JRNAL_NO = " + diarioText.Text + " AND a.ANAL_T5 = '" + iglesiaText.Text + "'";
                      }
                      using (SqlCommand cmdCheck = new SqlCommand(queryXML, connection))
                      {
                          String saveANAL="";
                          String saveFecha = "";

                          SqlDataReader reader = cmdCheck.ExecuteReader();
                          if (reader.HasRows)
                          {
                              bool first = true;
                              String FileName = "C:" + (object)Path.DirectorySeparatorChar + "recibos" + (object)Path.DirectorySeparatorChar + iglesiaText.Text + "_" + diarioText.Text + ".pdf";
                              string path = "C:" + (object)Path.DirectorySeparatorChar + "recibos";
                              if (!Directory.Exists(path))
                                  Directory.CreateDirectory(path);
                              if (File.Exists(FileName))
                              {
                                  try
                                  {
                                      File.Delete(FileName);
                                  }
                                  catch (IOException ex2)
                                  {
                                      System.Windows.Forms.MessageBox.Show(ex2.ToString(), "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                  }
                              }

                              Document = new PdfDocument(PaperType.Letter, false, UnitOfMeasure.Inch, FileName);
                              DefineFontResources();
                              DefineTilingPatternResource();
                              PdfPage Page = new PdfPage(Document);
                              PdfContents Contents = new PdfContents(Page);
                              Contents.SaveGraphicsState();

                              String fileImage = "C:" + (object)Path.DirectorySeparatorChar + "recibos" + (object)Path.DirectorySeparatorChar + "logo.jpg";
                              PdfImageControl ImageControl = new PdfImageControl();
                              ImageControl.Resolution = 300.0;
                              PdfImage Image = new PdfImage(Document, fileImage, ImageControl); //new PdfImage(Document, fileImage, 72.0, 50);
                              Contents.SaveGraphicsState();
                              double top = 9.9;
                              double left = 0.4;
                              int ancho = 1;
                              int largo = 1;
                             Contents.DrawImage(Image, left, top, ancho, largo);
                             Contents.DrawImage(Image, left, top-6.2, ancho, largo);

                              Contents.RestoreGraphicsState();
                              Contents.SaveGraphicsState();

                              const Double Width = 8.15;
                              const Double Height = 10.65;
                              PdfFileWriter.TextBox Box = new PdfFileWriter.TextBox(Width, 0.0);
                              PdfFileWriter.TextBox Datos = new PdfFileWriter.TextBox(Width, 0.0);
                              PdfFileWriter.TextBox derecha = new PdfFileWriter.TextBox(Width, 0.0);
                              PdfFileWriter.TextBox fechaBox = new PdfFileWriter.TextBox(Width, 0.0);
                              PdfFileWriter.TextBox graciasBox = new PdfFileWriter.TextBox(Width, 0.0);
                              PdfFileWriter.TextBox copiaBox = new PdfFileWriter.TextBox(Width, 0.0);

                              //double dif = 2.5;
                             // Contents.SaveGraphicsState();
                              //Contents.RestoreGraphicsState();
                              Contents.Translate(0.0, 0.0);
                              PdfTable Table = new PdfTable(Page, Contents, ArialNormal, 9.0);
                              PdfTable TableCopy = new PdfTable(Page, Contents, ArialNormal, 9.0);

                              Table.TableArea = new PdfRectangle(0.5, 1,8.0,7.7);
                              TableCopy.TableArea = new PdfRectangle(0.5, 1, 8.0, 1.75);

                              Double MarginHor = 0.04;
                              double aver = ArialNormal.TextWidth(9.0, "9999.99") + 2.0 * MarginHor;
                              double aver2 = ArialNormal.TextWidth(9.0, "Qty") + 2.0 * MarginHor;
                              aver += 0.2;
                              Table.SetColumnWidth(new Double[] { aver2,aver , aver, aver2 });
                              Table.Borders.SetAllBorders(0.0);

                              Table.Header[0].Style = Table.HeaderStyle;
                              Table.Header[0].Style.Alignment = ContentAlignment.MiddleCenter;
                              Table.Header[1].Style = Table.HeaderStyle;
                              Table.Header[1].Style.Alignment = ContentAlignment.MiddleCenter;
                              Table.Header[2].Style = Table.HeaderStyle;
                              Table.Header[2].Style.Alignment = ContentAlignment.MiddleCenter;
                              Table.Header[3].Style = Table.HeaderStyle;
                              Table.Header[3].Style.Alignment = ContentAlignment.MiddleCenter;

                              Table.Header[0].Value = "Cuenta";
                              Table.Header[1].Value = "Descripción";
                              Table.Header[2].Value = "Concepto";
                              Table.Header[3].Value = "Total";

                              TableCopy.SetColumnWidth(new Double[] { aver2, aver, aver, aver2 });
                              TableCopy.Borders.SetAllBorders(0.0);

                              TableCopy.Header[0].Style = Table.HeaderStyle;
                              TableCopy.Header[0].Style.Alignment = ContentAlignment.MiddleCenter;
                              TableCopy.Header[1].Style = Table.HeaderStyle;
                              TableCopy.Header[1].Style.Alignment = ContentAlignment.MiddleCenter;
                              TableCopy.Header[2].Style = Table.HeaderStyle;
                              TableCopy.Header[2].Style.Alignment = ContentAlignment.MiddleCenter;
                              TableCopy.Header[3].Style = Table.HeaderStyle;
                              TableCopy.Header[3].Style.Alignment = ContentAlignment.MiddleCenter;

                              TableCopy.Header[0].Value = "Cuenta";
                              TableCopy.Header[1].Value = "Descripción";
                              TableCopy.Header[2].Value = "Concepto";
                              TableCopy.Header[3].Value = "Total";

                              StringBuilder cad = new StringBuilder("");
                              StringBuilder primeros = new StringBuilder("");
                              StringBuilder letrasGrandes = new StringBuilder("");
                              StringBuilder fechaCad = new StringBuilder("");

                              StringBuilder tabla = new StringBuilder("");
                              double total=0;
                              int contadorTabla = 0;
                              while (reader.Read())
                              {
                                  String ADDR_LINE_1 = reader.GetString(0).Trim();
                                  String ADDR_LINE_2 = reader.GetString(1).Trim();
                                  String ADDR_LINE_3 = reader.GetString(2).Trim();
                                  String ADDR_LINE_4 = reader.GetString(3).Trim();
                                  String ADDR_LINE_5 = reader.GetString(4).Trim();
                                  String amount = Convert.ToString(reader.GetDecimal(5));
                                  String fecha = Convert.ToString(reader.GetDateTime(6)).Substring(0, 10);

                                  String DESCR = reader.GetString(7).Trim();
                                  if(DESCR.Length>32)
                                  {
                                      DESCR = DESCR.Substring(0, 32);
                                  }
                                  String JRNAL_SRCE = reader.GetString(8).Trim();
                                  String ANAL_T0 = reader.GetString(9).Trim();
                                  saveANAL=ANAL_T0;
                                  String ACNT_CODE = reader.GetString(10).Trim();
                                  String descrCuenta = reader.GetString(11).Trim();
                                  if (descrCuenta.Length > 36)
                                  {
                                      descrCuenta = descrCuenta.Substring(0, 36);
                                  }
                                  total+=Convert.ToDouble(amount);
                                  if(first)
                                  {
                                      first = false;
                                      primeros.Append( ADDR_LINE_1 + "\n" +
                                         ADDR_LINE_2 + "\n" +
                                      ADDR_LINE_3 + "\n" +
                                      ADDR_LINE_4 + "\n" +
                                      ADDR_LINE_5 + "\n\n");
                                      fechaCad.Append(" Fecha de recepción:\n" + fecha);

                                      letrasGrandes.Append("      Recibido de " + DESCR + "\n");
                                      saveFecha = fecha;
                                  }
                                  Table.Cell[0].Value = ACNT_CODE;
                                  Table.Cell[1].Value = descrCuenta;
                                  Table.Cell[2].Value = DESCR;
                                   Table.Cell[3].Value = "$"+String.Format("{0:n}", Convert.ToDouble(amount));
                                  Table.DrawRow();
                                  TableCopy.Cell[0].Value = ACNT_CODE;
                                  TableCopy.Cell[1].Value = descrCuenta;
                                  TableCopy.Cell[2].Value = DESCR;
                                  TableCopy.Cell[3].Value = "$" + String.Format("{0:n}", Convert.ToDouble(amount));
                                  TableCopy.DrawRow();

                                  contadorTabla++;

                                //  tabla.Append("\n"+DESCR+"         "+ACNT_CODE+"        "+JRNAL_SRCE+"        "+  String.Format("{0:n}", Convert.ToDouble(amount)));
                              }//while
                              Table.Close();
                              TableCopy.Close();
                              Contents.SaveGraphicsState();
                              Contents.RestoreGraphicsState();

                              letrasGrandes.Append("      ***** " + Conversiones.NumeroALetras(total.ToString()) + " *****\n");

                              cad.Append(" Número de recibo original: " + saveANAL + "\n Diario: " + diarioText.Text + "\n" +
                                      " Monto recibido\n ***** "+String.Format("{0:n}", Convert.ToDouble(total))+" *****\n\n");
                              //cad.Append();
                              try{

                                  Box.AddText(ArialNormal, 14.0,
                                    primeros.ToString()  );
                                  Datos.AddText(ArialNormal, 14.0,
                                letrasGrandes.ToString() );
                                  copiaBox.AddText(ArialBold, 50.0,
                              "     COPY");
                                  graciasBox.AddText(ArialItalic, 30.0,
                              "                           Gracias\n");
                                  fechaBox.AddText(ArialNormal, 10.0,
                                 fechaCad.ToString());
                               derecha.AddText(ArialNormal, 12.0,
                                 cad.ToString());
                                  Double PosY = 8.5;
                                  Double PosYDatos = 9.0;
                                  Double auxY = Height;
                                  Double auxFecha = Height-0.5;
                                  double dif = 6.0;
                                  Double auxYCopia = Height-dif;
                                  Double auxFechaCopia = Height - 0.5-dif;
                                  Double PosYCopia = 8.5-dif;
                                  Double copiaCopia = 8.5 - dif;

                                  Double PosYDatosCopia = 9.0-dif;

                                  Contents.Translate(0.0, 10.0);

                                 // Contents.Translate(0.0, -9.9);//-9.9

                                 Contents.Translate(0.0, -9.9);

                                  Contents.DrawText(0.0, ref auxY, 9.0, 0, 0.0, 0.0, TextBoxJustify.Center, Box);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();
                                  //la copia
                                  Contents.DrawText(0.0, ref auxYCopia, 1.0, 0, 0.0, 0.0, TextBoxJustify.Center, Box);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();
                                 // Contents.Translate(0.0, -9.9);
                                  Contents.DrawText(0, ref PosYDatos, 8.5, 0, 0.00, 0.00, TextBoxJustify.Left, Datos);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref PosYDatosCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Left, Datos);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                 // Contents.Translate(0.0, -9.9);
                                  Contents.DrawText(0, ref PosY, 7.0, 0, 0.00, 0.00, TextBoxJustify.Right, derecha);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref PosYDatos, 7.0, 0, 0.00, 0.00, TextBoxJustify.Left, graciasBox);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref PosYCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Right, derecha);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref PosYDatosCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Left, graciasBox);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref copiaCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Left, copiaBox);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  //Contents.Translate(0.0, -9.9);
                                  Contents.DrawText(0, ref auxFecha, 9.5, 0, 0.00, 0.00, TextBoxJustify.Right, fechaBox);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                  Contents.DrawText(0, ref auxFechaCopia, 1.0, 0, 0.00, 0.00, TextBoxJustify.Right, fechaBox);
                                  Contents.RestoreGraphicsState();
                                  Contents.SaveGraphicsState();

                                Document.CreateFile();

                                try
                                {
                                    MailMessage mail2 = new MailMessage();
                                    SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                                    mail2.From = new MailAddress(Properties.Settings.Default.correoEmisor);
                                    mail2.To.Add(correoLabel.Text);

                                    mail2.CC.Add(Properties.Settings.Default.correoReceptor);
                                    DateTime now = DateTime.Now;
                                    int year = now.Year;
                                    int month = now.Month;
                                    int day = now.Day;
                                    String mes = month.ToString();
                                    if (month < 10)
                                    {
                                        mes = "0" + month;
                                    }
                                    String dia = day.ToString();
                                    if (day < 10)
                                    {
                                        dia = "0" + day;
                                    }
                                    if(Login.unidadDeNegocioGlobal.Equals("FOP"))
                                    {
                                        mail2.Subject = "Recibo del dia: " + saveFecha + " del diario "+diarioText.Text+" de FORPOUMN " + iglesiaText.Text ;
                                        mail2.Body = "Hola " + nombreLabel.Text + ", por este medio le envio el recibo de FOPROUMN correspondiente al diario "+diarioText.Text+". Dios lo bendiga. ";
                                    }
                                    else
                                    {
                                        mail2.Subject = "Recibo de caja del dia: " + saveFecha + " de la iglesia " + iglesiaText.Text;
                                        mail2.Body = "Hola " + nombreLabel.Text + ", por este medio le envio el recibo de caja de la iglesia " + iglesiaText.Text;
                                    }
                                    Attachment pdf = new Attachment(FileName);
                                    mail2.Attachments.Add(pdf);
                                    SmtpServer.Port = 587;
                                    SmtpServer.Credentials = new System.Net.NetworkCredential(Properties.Settings.Default.correoEmisor, Properties.Settings.Default.passEmisor);
                                    SmtpServer.EnableSsl = true;
                                    SmtpServer.Send(mail2);
                                    this.Cursor = System.Windows.Forms.Cursors.Arrow;

                                    System.Windows.Forms.MessageBox.Show("Ya se mando el correo", "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                                }
                                catch (Exception ex3)
                                {
                                    System.Windows.Forms.MessageBox.Show(ex3.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                }

                                   }//try
                              catch(Exception ex1)
                              {
                                          System.Windows.Forms.MessageBox.Show(ex1.ToString(), "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                              }
                          }
                      }
                  }
              }
            catch(Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString(), "Sunplusito", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
              this.Cursor = System.Windows.Forms.Cursors.Arrow;
        }
        public void vuelveAHacerElCheque(bool conImagen)
        {
            string path = Properties.Settings.Default.letra+ ":" + (object)Path.DirectorySeparatorChar + "cheques";
            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            if (File.Exists(FileName))
            {
                try
                {
                    File.Delete(FileName);
                }
                catch (IOException ex2)
                {
                    System.Windows.Forms.MessageBox.Show(ex2.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            String fileImage = path + (object)Path.DirectorySeparatorChar + "cheque" + tipoDeBancoGlobal+".jpg";

            Document = new PdfDocument(PaperType.sobreprima, false, UnitOfMeasure.Point, FileName);
            DefineFontResources();
            DefineTilingPatternResource();
            PdfPage Page = new PdfPage(Document);
            PdfContents Contents = new PdfContents(Page);

            Contents.SaveGraphicsState();
            Contents.Translate(0.1, 0.1);

            const Double FontSize = 9.0;

            if(conImagen)
            {
                PdfImage Image = new PdfImage(Document, fileImage, 72.0, 50);
                Contents.SaveGraphicsState();
                int top = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "topCheque" + tipoDeBancoGlobal));
                int left = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "leftCheque" + tipoDeBancoGlobal));
                int ancho = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "anchoCheque" + tipoDeBancoGlobal));
                int largo = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "largoCheque" + tipoDeBancoGlobal));
                Contents.DrawImage(Image, left, top, ancho, largo);
                Contents.RestoreGraphicsState();
            }

            int fechaX = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "fechaX" + tipoDeBancoGlobal));
            int fechaY = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "fechaY" + tipoDeBancoGlobal));
            Contents.MoveTo(new PointD(fechaX, fechaY));
            Contents.DrawText(ArialNormal, FontSize, fechaX, fechaY, fecha);
            Contents.RestoreGraphicsState();
            Contents.SaveGraphicsState();

            int nombreX = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "nombreX" + tipoDeBancoGlobal));
            int nombreY = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "nombreY" + tipoDeBancoGlobal));
            Contents.MoveTo(new PointD(nombreX, nombreY));
            Contents.DrawText(ArialNormal, FontSize, nombreX, nombreY, nombre);
            Contents.RestoreGraphicsState();
            Contents.SaveGraphicsState();

            int cantidadX = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "cantidadX" + tipoDeBancoGlobal));
            int cantidadY = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "cantidadY" + tipoDeBancoGlobal));
            Contents.MoveTo(new PointD(cantidadX, cantidadY));
            Contents.DrawText(ArialNormal, FontSize, cantidadX, cantidadY, total);
            Contents.RestoreGraphicsState();
            Contents.SaveGraphicsState();

            int letraX = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "letraX" + tipoDeBancoGlobal));
            int letraY = Convert.ToInt32(DataBinder.Eval(Properties.Settings.Default, "letraY" + tipoDeBancoGlobal));
            Contents.MoveTo(new PointD(letraX, letraY));
            Contents.DrawText(ArialNormal, FontSize, letraX, letraY, numeroAletras);
            Contents.RestoreGraphicsState();
            Contents.SaveGraphicsState();

            Contents.RestoreGraphicsState();
            Document.CreateFile();

            String url = "file:" + (object)Path.DirectorySeparatorChar + (object)Path.DirectorySeparatorChar +FileName;
            // this.webBrowser1.Navigate(new Uri(url));
            this.webView1.ZoomFactor = 1.0;
            this.webView1.Url = url;
            Properties.Settings.Default.Save();
        }
        ////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Add pages to PDF document
        /// </summary>
        /// <remarks>
        /// The PrintDoc.Print method will call BeginPrint method,
        /// next it will call multiple times PrintPage method and finally
        /// it will call EndPrint method. 
        /// </remarks>
        ////////////////////////////////////////////////////////////////////
        public void AddPagesToPdfDocument()
        {
            // print the document by calling BeginPrint, PrintPage multiple times and finally EndPrint
            Print();

            // get printing results in the form of array of images one per page
            // image format is Metafile
            PreviewPageInfo[] PageInfo = ((PreviewPrintController) PrintController).GetPreviewPageInfo();

            // page size in user units
            Double PageWidth = Document.PageSize.Width / Document.ScaleFactor;
            Double PageHeight = Document.PageSize.Height / Document.ScaleFactor;

            // define empty image source rectangle
            Rectangle SourceRect = new Rectangle();

            // add pages to pdf document
            for(Int32 ImageIndex = 0; ImageIndex < PageInfo.Length; ImageIndex++)
            {
            // add page to document
            PdfPage Page = new PdfPage(Document);

            // add contents to the page
            PdfContents Contents = new PdfContents(Page);

            // page image
            Image PageImage = PageInfo[ImageIndex].Image;

            // no crop
            if(CropRect.IsEmpty)
                {
                // convert metafile image to PdfImage
                PdfImage Image = new PdfImage(Contents.Document, PageImage, Resolution);

                // draw the image
                Contents.DrawImage(Image, 0.0, 0.0, PageWidth, PageHeight);
                }

            // crop
            else
                {
                Int32 ImageWidth = PageImage.Width;
                Int32 ImageHeight = PageImage.Height;
                SourceRect.X = (Int32) (ImageWidth * CropRect.X / PageWidth + 0.5);
                SourceRect.Y = (Int32) (ImageHeight * CropRect.Y / PageHeight + 0.5);
                SourceRect.Width = (Int32) (ImageWidth * CropRect.Width / PageWidth + 0.5);
                SourceRect.Height = (Int32) (ImageHeight * CropRect.Height / PageHeight + 0.5);

                // convert metafile image to PdfImage
                PdfImage PdfPageImage = new PdfImage(Contents.Document, PageImage, SourceRect, Resolution);

                // draw the image
                Contents.DrawImage(PdfPageImage, CropRect.X, PageHeight - CropRect.Y - CropRect.Height, CropRect.Width, CropRect.Height);
                }
            }
            return;
        }
        public void ReportBlueprintImage()
        {
            var path = XmlParser.GetValue("ImagePath");

            var page = new PdfPage(mDocument);
            var contents = new PdfContents(page);

            contents.DrawText(mTimesNormal, 12.0, 1.5, 26, TextJustify.Left, "Plan budynku, na którym zaprojektowano sieć sensorową.");

            PdfImage blueprintImage = new PdfImage(mDocument, path);
            blueprintImage.ImageSize(500,700);
            contents.DrawImage(blueprintImage, 1.5, 26, 500, 700);
            contents.CommitToPdfFile(false);
        }