public void pdfCliente(ClienteEN cliente) { Document document; document = new Document(PageSize.A4, 25, 25, 30, 30); string path = @"" + "Cliente " + cliente.Nif + ".pdf"; FileStream fs = new FileStream(path, FileMode.OpenOrCreate); // Create an instance to the PDF file by creating an instance of the PDF // Writer class using the document and the filestrem in the constructor. PdfWriter writer = PdfWriter.GetInstance(document, fs); // Open the document to enable you to write to the document document.Open(); // Creo cabecera del informe PdfPTable tableTitulo = new PdfPTable(2); tableTitulo.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; PdfPCell cell = new PdfPCell(new Phrase("Informe de Cliente")); cell.BorderWidth = 0; cell.Colspan = 3; cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right tableTitulo.AddCell(cell); document.Add(tableTitulo); //Tabla sin bordes PdfPTable tableCabecera = new PdfPTable(2); tableCabecera.DefaultCell.Border = iTextSharp.text.Rectangle.NO_BORDER; //Cargamos la imagen de resources. System.Drawing.Image logores = Properties.Resources.logo; iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(logores, System.Drawing.Imaging.ImageFormat.Jpeg); //Añado imagen a la cabecera y fecha. logo.ScaleAbsolute(100f, 100f); PdfPCell cellLogo = new PdfPCell(logo); cellLogo.BorderWidth = 0; tableCabecera.AddCell(cellLogo); tableCabecera.AddCell("\n\n\n\n\nEmpresa: " + Constantes._NOMBREEMPRESA + "\nLocalidad: " + Constantes._CIUDADEMPRESA + "\nFecha: " + DateTime.Now.ToString() + "\n"); //Inserto tabla de cabecera document.Add(tableCabecera); Paragraph salto = new Paragraph(" "); document.Add(salto); document.Add(salto); //Añadimos una tabla con los datos del cliente PdfPTable tableCliente = new PdfPTable(2); PdfPCell cell2 = new PdfPCell(new Phrase("Datos del Cliente")); cell2.Colspan = 2; cell2.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right tableCliente.AddCell(cell2); tableCliente.AddCell("NIF"); tableCliente.AddCell(cliente.Nif); tableCliente.AddCell("Nombre"); tableCliente.AddCell(cliente.Nombre); tableCliente.AddCell("Email"); tableCliente.AddCell(cliente.Email); tableCliente.AddCell("Dirección"); tableCliente.AddCell(cliente.Direccion); tableCliente.AddCell("Localidad"); tableCliente.AddCell(cliente.Localidad); tableCliente.AddCell("Provincia"); tableCliente.AddCell(cliente.Provincia); tableCliente.AddCell("CP"); tableCliente.AddCell(cliente.CodigoPostal); tableCliente.AddCell("País"); tableCliente.AddCell(cliente.Pais); tableCliente.AddCell("Teléfono"); tableCliente.AddCell(cliente.Telefono); tableCliente.AddCell("Descripción"); tableCliente.AddCell(cliente.Descripcion); document.Add(tableCliente); document.Add(salto); document.Add(salto); //Añadimos una tabla con los datos del cliente PdfPTable tableInstalaciones = new PdfPTable(7); tableInstalaciones.TotalWidth = 500f; tableInstalaciones.LockedWidth = true; PdfPCell cell3 = new PdfPCell(new Phrase("Instalaciones del Cliente")); cell3.Colspan = 7; cell3.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right tableInstalaciones.AddCell(cell3); tableInstalaciones.AddCell("Nombre"); tableInstalaciones.AddCell("Dirección"); tableInstalaciones.AddCell("Localidad"); tableInstalaciones.AddCell("Provincia"); tableInstalaciones.AddCell("CP"); tableInstalaciones.AddCell("País"); tableInstalaciones.AddCell("Teléfono"); InstalacionCEN instalacionCEN = new InstalacionCEN(); IList<InstalacionEN> instalacionesCliente = new List<InstalacionEN>(); instalacionesCliente = instalacionCEN.BuscarInstalacionesCliente(cliente.Nif); foreach (InstalacionEN ins in instalacionesCliente) { tableInstalaciones.AddCell(ins.Nombre); tableInstalaciones.AddCell(ins.Direccion); tableInstalaciones.AddCell(ins.Localidad); tableInstalaciones.AddCell(ins.Provincia); tableInstalaciones.AddCell(ins.CodigoPostal); tableInstalaciones.AddCell(ins.Pais); tableInstalaciones.AddCell(ins.Telefono); } document.Add(tableInstalaciones); //Cerramos todo document.Close(); writer.Close(); fs.Close(); MessageBox.Show("Se ha generado un informe en PDF con el nombre \"" + path + "\"" ); }