Foros del Web » Programación para mayores de 30 ;) » .NET »

Pasar imágenes desde grid a pdf

Estas en el tema de Pasar imágenes desde grid a pdf en el foro de .NET en Foros del Web. Saludos comunidad, estoy tratando de pasar a un PdfpCell (iTextSharp) una imagen desde un datagrid, a continuación mi code hardcodeado: @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código C: Ver ...
  #1 (permalink)  
Antiguo 26/06/2013, 12:36
 
Fecha de Ingreso: junio-2012
Mensajes: 90
Antigüedad: 11 años, 10 meses
Puntos: 2
Pasar imágenes desde grid a pdf

Saludos comunidad, estoy tratando de pasar a un PdfpCell (iTextSharp) una imagen desde un datagrid, a continuación mi code hardcodeado:

Código C:
Ver original
  1. //Método para cargar datos en el Grid desde SQL
  2.       private void btnExec_Click(object sender, EventArgs e)
  3.         {
  4.             try
  5.             {
  6.                 SqlCommand cmd = new SqlCommand();
  7.                 DataSet DataS = new DataSet();
  8.                 cmd.CommandText = "storedproc";
  9.                 cmd.CommandType = CommandType.StoredProcedure;
  10.                 cmd.Parameters.AddWithValue("@param", param.Value);
  11.                 cmd.Connection = new System.Data.SqlClient.SqlConnection("strconections");
  12.                 SqlDataAdapter Ad = new SqlDataAdapter(cmd);
  13.                 Ad.Fill(DataS);
  14.                 dgv.DataSource = DataS.Tables[0];
  15.                 cmd.Connection.Close();
  16.                 datagrid.ClearSelection();
  17.                 metodoparagenerarpdf();  
  18.             }
  19.             catch (Exception ex)
  20.             {
  21.                 Console.WriteLine("{0} Error!", ex);
  22.             }
  23.         }
  24.  
  25.  
  26. //Evento Cell Formatting para cargar la imagen en la columna del Datagrid
  27.  
  28.  private void dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
  29.         {
  30.             if (e.ColumnIndex == 2)
  31.             {
  32.                 if (e.Value == DBNull.Value)
  33.                 {
  34. //Imagen x defectp
  35.                     string path = (Environment.CurrentDirectory + @"\\img\0.jpg");
  36.                     e.Value = new Bitmap(System.Drawing.Bitmap.FromFile(path), new Size(100, 100));
  37.                 }
  38.                 else
  39.                 {
  40. //Seteo la imagen y redimenciono medidas
  41.                     System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])e.Value);
  42.                     e.Value = new Bitmap(System.Drawing.Image.FromStream(ms), 100, 100);
  43.                     e.FormattingApplied = true;
  44.                 }
  45.             }
  46.         }
  47.  
  48. //Método para cargar los datos en una tabla
  49.  
  50. foreach (DataGridViewRow Row in dgv.Rows)
  51.                 {
  52.                     //PdfPCell c6 = new PdfPCell(new Phrase()); //Foto
  53.                     PdfPCell c7 = new PdfPCell(new Phrase(Row.Cells[3].Value.ToString(), smallfont)); //Nombre
  54.                     PdfPCell c8 = new PdfPCell(new Phrase(Row.Cells[4].Value.ToString() + " %", bigfont)); //Score
  55.                     PdfPCell c9 = new PdfPCell(new Phrase(Row.Cells[0].Value.ToString(), bigfont)); //# Viajes
  56.                     PdfPCell c10 = new PdfPCell(new Phrase(Row.Cells[5].Value.ToString(), smallfont)); //Terminal
  57.  
  58.                     c7.Border = 0;
  59.                     c7.HorizontalAlignment = 1;
  60.                     table.AddCell(c7);
  61.                     c8.Border = 0;
  62.                     c8.HorizontalAlignment = 1;
  63.                     table.AddCell(c8);
  64.                     c9.Border = 0;
  65.                     c9.HorizontalAlignment = 1;
  66.                     table.AddCell(c9);
  67.                     c10.Border = 0;
  68.                     c10.HorizontalAlignment = 1;
  69.                    //table.AddCell(c10);
  70.                 }

Yo lo que necesito es saber como puedo hacerle para pasar el valor que tengo en la columna (Row.Cells[2].Value.ToString()) en mi grid y convertirlo a bitmap o imagen y que se pueda ver en mi PDF, de antemano muchas gracias!


//EDIT


Intenté hacer esto, pero tampoco sin resultado :(

Código C:
Ver original
  1. byte[] bts= new byte[Row.Cells[2].Value.ToString().Length * sizeof(char)];
  2.  System.Buffer.BlockCopy(Row.Cells[2].Value.ToString().ToCharArray(), 0, bytes, 0, bytes.Length);
  3.  
  4. iTextSharp.text.Image img1 = iTextSharp.text.Image.GetInstance(bts);
  5. doc.Add(img1);

Saludos

Etiquetas: datagridview, grid, pdf, sql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:21.