private void MontarSeccaoRetiradaEquipamentos(List <RetiradaEquipamentosViewModel> listaRetiradaEquipamentosFiltro, ref Document documento, Font bodyFontSmallBold, Font bodyFontSmall) { documento.Add(new Paragraph("Equipamentos Retirados", bodyFontSmallBold)); //document.Add(new Paragraph(" ")); var eqptoRetiradoTable = new PdfPTable(3); eqptoRetiradoTable.HorizontalAlignment = 0; eqptoRetiradoTable.SpacingBefore = 10; eqptoRetiradoTable.SpacingAfter = 10; //produtoFalhadoTable.DefaultCell.Border = 0; eqptoRetiradoTable.DefaultCell.Border = Rectangle.NO_BORDER; float[] widthsER = new float[] { 100f, 400f, 200f }; eqptoRetiradoTable.SetWidths(widthsER); var bodyFontHeader = FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.WHITE); PdfPCell cellCodigo = new PdfPCell(new Phrase("Código", bodyFontHeader)); cellCodigo.BackgroundColor = new BaseColor(189, 192, 215); cellCodigo.Border = Rectangle.NO_BORDER; eqptoRetiradoTable.AddCell(cellCodigo); PdfPCell cellDescricao = new PdfPCell(new Phrase("Descrição", bodyFontHeader)); cellDescricao.BackgroundColor = new BaseColor(189, 192, 215); cellDescricao.Border = Rectangle.NO_BORDER; eqptoRetiradoTable.AddCell(cellDescricao); PdfPCell cellNumeroSerie = new PdfPCell(new Phrase("Número Série", bodyFontHeader)); cellNumeroSerie.BackgroundColor = new BaseColor(189, 192, 215); cellNumeroSerie.Border = Rectangle.NO_BORDER; eqptoRetiradoTable.AddCell(cellNumeroSerie); foreach (RetiradaEquipamentosViewModel eqptoRetirado in listaRetiradaEquipamentosFiltro) { PdfPCell[] cellsER1 = new PdfPCell[] { new PdfPCell(new Phrase(eqptoRetirado.IdProduto.ToString(), bodyFontSmall)), new PdfPCell(new Phrase(eqptoRetirado.Produto, bodyFontSmall)), new PdfPCell(new Phrase(eqptoRetirado.NumeroSerie, bodyFontSmall)) }; PdfPRow rowER1 = new PdfPRow(cellsER1); eqptoRetiradoTable.Rows.Add(rowER1); } documento.Add(eqptoRetiradoTable); documento.Add(new Paragraph(" ")); }
private void MontarSeccaoSolicitacoesPecas(List <SolicitacoesPecasViewModel> listaSolicitacoesPecasFiltro, ref Document documento, Font bodyFontSmallBold, Font bodyFontSmall) { documento.Add(new Paragraph("Solicitações Peças", bodyFontSmallBold)); //document.Add(new Paragraph(" ")); var solicitacaoPecaTable = new PdfPTable(3); solicitacaoPecaTable.HorizontalAlignment = 0; solicitacaoPecaTable.SpacingBefore = 10; solicitacaoPecaTable.SpacingAfter = 10; //produtoFalhadoTable.DefaultCell.Border = 0; solicitacaoPecaTable.DefaultCell.Border = Rectangle.NO_BORDER; float[] widthSP = new float[] { 100f, 400f, 200f }; solicitacaoPecaTable.SetWidths(widthSP); var bodyFontHeader = FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.WHITE); PdfPCell cellCodigo = new PdfPCell(new Phrase("Código", bodyFontHeader)); cellCodigo.BackgroundColor = new BaseColor(189, 192, 215); cellCodigo.Border = Rectangle.NO_BORDER; solicitacaoPecaTable.AddCell(cellCodigo); PdfPCell cellDescricao = new PdfPCell(new Phrase("Descrição", bodyFontHeader)); cellDescricao.BackgroundColor = new BaseColor(189, 192, 215); cellDescricao.Border = Rectangle.NO_BORDER; solicitacaoPecaTable.AddCell(cellDescricao); PdfPCell cellQuantidade = new PdfPCell(new Phrase("Quantidade", bodyFontHeader)); cellQuantidade.BackgroundColor = new BaseColor(189, 192, 215); cellQuantidade.Border = Rectangle.NO_BORDER; solicitacaoPecaTable.AddCell(cellQuantidade); foreach (SolicitacoesPecasViewModel solicitacaoPeca in listaSolicitacoesPecasFiltro) { PdfPCell[] cellsSP1 = new PdfPCell[] { new PdfPCell(new Phrase(solicitacaoPeca.IdProduto.ToString(), bodyFontSmall)), new PdfPCell(new Phrase(solicitacaoPeca.Produto, bodyFontSmall)), new PdfPCell(new Phrase(solicitacaoPeca.Quantidade.ToString(), bodyFontSmall)) }; PdfPRow rowSP1 = new PdfPRow(cellsSP1); solicitacaoPecaTable.Rows.Add(rowSP1); } documento.Add(solicitacaoPecaTable); documento.Add(new Paragraph(" ")); }
/** * @see com.itextpdf.text.pdf.PdfPTableEventAfterSplit#afterSplitTable(com.itextpdf.text.pdf.PdfPTable, com.itextpdf.text.pdf.PdfPRow, int) * @since iText 5.4.3 */ virtual public void AfterSplitTable(PdfPTable table, PdfPRow startRow, int startIdx) { foreach (IPdfPTableEvent evente in events) { if (evente is IPdfPTableEventAfterSplit) { ((IPdfPTableEventAfterSplit)evente).AfterSplitTable(table, startRow, startIdx); } } }
public void ExportToPdf(DataTable dt, string path) { Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path + "\\Swype Pay General Transactions Report.pdf", FileMode.Create)); document.Open(); iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 10); PdfPTable table = new PdfPTable(dt.Columns.Count); PdfPRow row = null; float[] widths = new float[] { 4f, 4f, 4f, 4f, 4f, 4f, 4f, 4f }; table.SetTotalWidth(widths); table.WidthPercentage = 100; int iCol = 0; string colname = ""; PdfPCell cell = new PdfPCell(new Phrase("Products")); cell.Colspan = dt.Columns.Count; var map = new Dictionary <string, string>(); map.Add("transactionItemId", "Product Name"); map.Add("CategoryName", "Category Name"); map.Add("categoryId", "Reference ID"); map.Add("productId", "Transaction ID"); map.Add("productName", "Product Name"); map.Add("productPrice", "Product Price"); map.Add("transactionDate", "Transaction Date"); foreach (DataColumn c in dt.Columns) { try { table.AddCell(new Phrase(map[c.ColumnName], font5)); } catch (Exception notmapped) { table.AddCell(new Phrase(c.ColumnName, font5)); } } foreach (DataRow r in dt.Rows) { if (dt.Rows.Count > 0) { table.AddCell(new Phrase(r[0].ToString(), font5)); table.AddCell(new Phrase(r[1].ToString(), font5)); table.AddCell(new Phrase(r[2].ToString(), font5)); table.AddCell(new Phrase(r[3].ToString(), font5)); table.AddCell(new Phrase(r[4].ToString(), font5)); table.AddCell(new Phrase(r[5].ToString(), font5)); table.AddCell(new Phrase(r[6].ToString(), font5)); table.AddCell(new Phrase(r[7].ToString(), font5)); } } document.Add(table); document.Close(); }
public static void Pdf(int StudentID, int GrupaID, int Semestru, string FileName) { using (var context = new CatalogEntities1()) { try { var tabel = context.usp_catalog_sesiunea_x(StudentID, GrupaID, Semestru).ToList(); string path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path + "\\" + FileName + " Semestrul " + Semestru.ToString() + ".pdf", FileMode.Create)); document.Open(); iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 5); PdfPTable table = new PdfPTable(6); PdfPRow row = null; float[] widths = new float[] { 4f, 4f, 4f, 4f, 4f, 4f }; table.SetWidths(widths); table.WidthPercentage = 100; int iCol = 0; string colname = ""; PdfPCell cell = new PdfPCell(new Phrase("Note pe semestrul" + Semestru.ToString())); cell.Colspan = 6; table.AddCell(new Phrase("Disciplina", font5)); table.AddCell(new Phrase("NotaCurs", font5)); table.AddCell(new Phrase("NotaLaborator", font5)); table.AddCell(new Phrase("NotaProiect", font5)); table.AddCell(new Phrase("NotaFinala", font5)); table.AddCell(new Phrase("Credite", font5)); for (int i = 0; i < tabel.Count; i++) { table.AddCell(new Phrase(tabel[i].NumeMaterie.ToString(), font5)); table.AddCell(new Phrase(tabel[i].NotaCurs.ToString(), font5)); table.AddCell(new Phrase(tabel[i].NotaFinala.ToString(), font5)); table.AddCell(new Phrase(tabel[i].NotaProiect.ToString(), font5)); table.AddCell(new Phrase(tabel[i].NotaFinala.ToString(), font5)); table.AddCell(new Phrase(tabel[i].Credite.ToString(), font5)); } document.Add(table); document.Close(); } catch (Exception e) { Console.Out.WriteLine(e.ToString()); } } }
protected void Button1_Click(object sender, EventArgs e) { string fileName = Guid.NewGuid() + ".pdf"; string filePath = Path.Combine(Server.MapPath("~/PDFFiles"), fileName); Document doc = new Document(PageSize.A4, 2, 2, 2, 2); Paragraph p = new Paragraph("Data Sheet"); try { PdfWriter.GetInstance(doc, new FileStream(filePath, FileMode.Create)); PdfPTable pdfTab = new PdfPTable(2); pdfTab.HorizontalAlignment = 1; pdfTab.SpacingBefore = 20f; Table data = new Table(); foreach (var prop in data.GetType().GetProperties()) { PdfPCell[] cells = new PdfPCell[] { new PdfPCell(new Phrase(prop.Name)), new PdfPCell(new Phrase(prop.GetValue(data, null).ToString())) }; PdfPRow row = new PdfPRow(cells); pdfTab.Rows.Add(row); } doc.Open(); doc.Add(p); doc.Add(pdfTab); doc.Close(); byte[] content = File.ReadAllBytes(filePath); HttpContext context = HttpContext.Current; context.Response.BinaryWrite(content); context.Response.ContentType = "application/pdf"; context.Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName); context.Response.End(); } catch { throw; } finally { doc.Close(); } }
public static void ExportToPdfQuerMitPic(List <Rent> rents, string filepath, NpgsqlConnection connection) { Document document = new Document(); document.SetPageSize(PageSize.A4.Rotate()); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream($"{filepath}", FileMode.Create)); document.Open(); iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 12); iTextSharp.text.Font fontHeader = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 20); PdfPTable table = new PdfPTable(8); PdfPRow row = null; table.HorizontalAlignment = 0; table.WidthPercentage = 100; PdfPCell cell = new PdfPCell(new Phrase(("Vermietungen"), fontHeader)); cell.Colspan = 8; cell.HorizontalAlignment = 1; table.AddCell(cell); cell.Colspan = 8; iTextSharp.text.Image image = null; foreach (Rent r in rents) { if (rents.Count > 0) { System.Drawing.Image pic = ImageCar.GetMainImage(connection, r.CarId); if (pic != null) { image = iTextSharp.text.Image.GetInstance(pic, ImageFormat.Jpeg); PdfPCell imageCell = new PdfPCell(image); imageCell.Colspan = 1; imageCell.Border = 0; table.AddCell(image); } else { table.AddCell(new Phrase("", font5)); } table.AddCell(new Phrase(r.RentNo, font5)); } } document.Add(table); document.Close(); }
public void ExportDSToPdf(DataTable dt) { Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("Datatable.pdf", FileMode.Create)); document.Open(); //Report Header BaseFont bfntHead = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Font fntHead = new Font(bfntHead, 16, 1, Color.GRAY); Font fntHead2 = new Font(bfntHead, 12, 1, Color.GRAY); Paragraph prgHeading = new Paragraph(); prgHeading.Alignment = Element.ALIGN_CENTER; prgHeading.Add(new Chunk("Employee Hours By Week", fntHead)); prgHeading.Add(new Chunk("From " + txtFrom.Text + " to " + txtTo.Text, fntHead2)); document.Add(prgHeading); iTextSharp.text.Font fnt = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 5); PdfPTable table = new PdfPTable(dt.Columns.Count); PdfPRow row = null; float[] widths = new float[] { 4f, 4f, 4f, 4f }; table.SetWidths(widths); table.WidthPercentage = 100; int iCol = 0; string colname = ""; PdfPCell cell = new PdfPCell(new Phrase("Products")); cell.Colspan = dt.Columns.Count; foreach (DataColumn col in dt.Columns) { table.AddCell(new Phrase(col.ColumnName, fnt)); } foreach (DataRow r in dt.Rows) { if (dt.Rows.Count > 0) { table.AddCell(new Phrase(r[0].ToString(), fnt)); table.AddCell(new Phrase(r[1].ToString(), fnt)); table.AddCell(new Phrase(r[2].ToString(), fnt)); table.AddCell(new Phrase(r[3].ToString(), fnt)); } } document.Add(table); document.Close(); }
private PdfPRow CreateTableRow(object[] rowData, int cellsAlignment) { var cells = new List <PdfPCell>(); foreach (var cellData in rowData) { var cell = this.CreateCell(this.defaultCellFont, 1, cellsAlignment, cellData.ToString()); cells.Add(cell); } var row = new PdfPRow(cells.ToArray()); return(row); }
private PdfPRow CreateTableRow(object rowData, int cellsAlignment) { var cells = new List <PdfPCell>(); foreach (var property in rowData.GetType().GetProperties()) { var cell = this.CreateCell(this.defaultCellFont, 1, cellsAlignment, property.GetValue(rowData, null).ToString()); cells.Add(cell); } var row = new PdfPRow(cells.ToArray()); return(row); }
private void CreatePdfDoc() { string FirstCell, SecondCell, ThirdCell, FourthCell; iTextSharp.text.Document doc = new iTextSharp.text.Document(); PdfWriter.GetInstance(doc, new FileStream(@"C:\Users\temch\Desktop\Выписка.pdf", FileMode.Create)); doc.Open(); BaseFont baseFont = BaseFont.CreateFont(@"C:\Windows\Fonts\Calibri.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL, BaseColor.GRAY); PdfPTable table = new PdfPTable(4); PdfPCell[] cells = new PdfPCell[4]; cells[0] = new PdfPCell(new Phrase($"Название", font)); cells[1] = new PdfPCell(new Phrase($"Доход", font)); cells[2] = new PdfPCell(new Phrase($"Сумма к концу срока", font)); cells[3] = new PdfPCell(new Phrase($"Ставка", font)); foreach (var el in cells) { el.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; el.HorizontalAlignment = PdfPCell.ALIGN_CENTER; el.Border = 0; } var row = new PdfPRow(cells); table.Rows.Add(row); AddPicture(table); font = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); FirstCell = "Стабильный"; SecondCell = LabFirstIncome.Text; ThirdCell = LabFirstSumEnd.Text; FourthCell = "8% "; AddRow(table, FirstCell, SecondCell, ThirdCell, FourthCell, font); AddPicture(table); FirstCell = "Оптимальный"; SecondCell = LabSecondIncome.Text; ThirdCell = LabSecondSumEnd.Text; FourthCell = "5% "; AddRow(table, FirstCell, SecondCell, ThirdCell, FourthCell, font); AddPicture(table); FirstCell = "Стандарт"; SecondCell = LabThirdIncome.Text; ThirdCell = LabThirdSumEnd.Text; FourthCell = "6% "; AddRow(table, FirstCell, SecondCell, ThirdCell, FourthCell, font); AddPicture(table); doc.Add(table); doc.Close(); MessageBox.Show("Pdf-документ сохранен"); }
protected void AddTextToRow(string Text, Font fontUse, PdfPTable table) { try { PdfPCell cell1 = GetNewCell(false); cell1.AddElement(GetNewParag(Text, fontUse)); PdfPCell[] cellAry = new PdfPCell[] { cell1 }; PdfPRow row = new PdfPRow(cellAry); table.Rows.Add(row); } catch (Exception ex) { } }
public static void ExportToPdfQuer(DataTable dt, string filepath) { Document document = new Document(); document.SetPageSize(PageSize.A4.Rotate()); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream($"{filepath}", FileMode.Create)); document.Open(); iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 12); iTextSharp.text.Font fontHeader = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 20); PdfPTable table = new PdfPTable(dt.Columns.Count); PdfPRow row = null; //float[] widths = new float[] { 4f, 4f}; //table.SetWidths(widths); table.HorizontalAlignment = 0; table.WidthPercentage = 100; PdfPCell cell = new PdfPCell(new Phrase((dt.TableName), fontHeader)); cell.Colspan = dt.Columns.Count; cell.HorizontalAlignment = 1; table.AddCell(cell); cell.Colspan = dt.Columns.Count; foreach (DataColumn c in dt.Columns) { table.AddCell(new Phrase(c.ColumnName, font5)); } foreach (DataRow r in dt.Rows) { if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Columns.Count; i++) { table.AddCell(new Phrase(r[i].ToString(), font5)); } ; } } document.Add(table); document.Close(); }
public void AddPicture(PdfPTable table) { iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(@"..\\..\\Resources\Полосочка.jpg"); var cells = new PdfPCell[4]; cells[0] = new PdfPCell(image); image.ScalePercent(45); cells[0].PaddingLeft = -60; cells[0].PaddingTop = 10; cells[0].Border = 0; cells[0].Colspan = 4; var row = new PdfPRow(cells); table.Rows.Add(row); }
private PdfPTable crearTabla(DataTable datos) { PdfPTable table = new PdfPTable(5); PdfPCell[] cells = new PdfPCell[] { new PdfPCell(GetCell("Nombre", 0, blanco, 1)), new PdfPCell(GetCell("Gonzalo", 0, blanco, 2)), new PdfPCell(GetCell("Código Cliente", 1, azul, 3)), new PdfPCell(GetCell("Fecha Emisión", 1, azul, 3)), new PdfPCell(GetCell("Moneda", 1, azul, 3)), }; PdfPRow row = new PdfPRow(cells); PdfPCell[] cells2 = new PdfPCell[] { new PdfPCell(GetCell("Dirección", 0, blanco, 1)), new PdfPCell(GetCell("Morales 2560", 0, blanco, 2)), new PdfPCell(GetCell(datos.Rows[0][0].ToString(), 1, blanco, 2)), new PdfPCell(GetCell(datos.Rows[0][1].ToString(), 1, blanco, 2)), new PdfPCell(GetCell(datos.Rows[0][2].ToString(), 1, blanco, 2)), }; PdfPCell[] cells3 = new PdfPCell[] { new PdfPCell(GetCell("Teléfono", 0, blanco, 1)), new PdfPCell(GetCell("094800577", 0, blanco, 2)), new PdfPCell(GetCell("Vendedor", 1, azul, 3)), new PdfPCell(GetCell("Forma de Pago", 1, azul, 3)), new PdfPCell(GetCell("Distribuidor", 1, azul, 3)), }; PdfPCell[] cells4 = new PdfPCell[] { new PdfPCell(GetCell("", 0, blanco, 1)), new PdfPCell(GetCell("", 0, blanco, 1)), new PdfPCell(GetCell(datos.Rows[0][3].ToString(), 1, blanco, 2)), new PdfPCell(GetCell(datos.Rows[0][4].ToString(), 1, blanco, 2)), new PdfPCell(GetCell(datos.Rows[0][5].ToString(), 1, blanco, 2)), }; PdfPRow row2 = new PdfPRow(cells2); PdfPRow row3 = new PdfPRow(cells3); PdfPRow row4 = new PdfPRow(cells4); table.Rows.Add(row); table.Rows.Add(row2); table.Rows.Add(row3); table.Rows.Add(row4); PdfPTable table1 = new PdfPTable(2); float[] columnas = new float[] { 11, 50, 13, 13, 13 }; table.SetWidths(columnas); table.WidthPercentage = 100; return(table); }
/// <summary> /// 获取pdf行 /// </summary> /// <param name="font"></param> /// <param name="texts"></param> /// <returns></returns> public static PdfPRow GetRows(iTextSharp.text.Font font, params object[] texts) { List <PdfPCell> pcells = new List <PdfPCell>(); foreach (var text in texts) { string t = text == null ? "" : text.ToString(); PdfPCell pcell = new PdfPCell(new Phrase(t, font)); pcell.Border = 0; pcells.Add(pcell); } PdfPRow prow = new PdfPRow(pcells.ToArray()); return(prow); }
public void ExportToPdf(DataTable dt) { Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("TermékLista.pdf", FileMode.Create)); document.Open(); iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 10); PdfPTable table = new PdfPTable(dt.Columns.Count); PdfPRow row = null; float[] widths = new float[] { 4f, 4f, 4f, 4f, 4f, 4f, 4f }; table.SetWidths(widths); table.WidthPercentage = 100; int iCol = 0; string colname = ""; PdfPCell cell = new PdfPCell(new Phrase("Products")); cell.Colspan = dt.Columns.Count; foreach (DataColumn c in dt.Columns) { table.AddCell(new Phrase(c.ColumnName, font5)); } foreach (DataRow r in dt.Rows) { if (dt.Rows.Count > 0) { table.AddCell(new Phrase(r[0].ToString(), font5)); table.AddCell(new Phrase(r[1].ToString(), font5)); table.AddCell(new Phrase(r[2].ToString(), font5)); table.AddCell(new Phrase(r[3].ToString(), font5)); table.AddCell(new Phrase(r[4].ToString(), font5)); table.AddCell(new Phrase(r[5].ToString(), font5)); table.AddCell(new Phrase(r[6].ToString(), font5)); } } document.AddAuthor("Incsik-Land Kft"); document.AddHeader("Rendelés", "Vattacukor Műhely"); document.Add(table); document.Close(); }
/// <summary> /// 表格写入 /// </summary> /// <param name="document">itext Document对象</param> /// <param name="content">表格</param> /// <returns>itext Document对象</returns> public static iTextSharp.text.Document Write(this iTextSharp.text.Document document, TableContent content) { if (content == null || content.Content == null) { return(document); } var table = new PdfPTable(content.RelativeWidths.ToArray()); PdfPRow row; var cells = new List <PdfPCell>(); if (content.ShowHeader) { var headcells = new List <PdfPHeaderCell>(); foreach (DataColumn column in content.Content.Columns) { var cell = new PdfPHeaderCell(); cell.AddElement(new Phrase(column.Caption, content.HeaderFont)); cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.VerticalAlignment = Element.ALIGN_MIDDLE; cell.Padding = content.HeaderFont.Size * 0.4f; headcells.Add(cell); } row = new PdfPRow(headcells.ConvertAll(p => (PdfPCell)p).ToArray()); table.Rows.Add(row); } foreach (DataRow dr in content.Content.Rows) { cells.Clear(); cells.AddRange(from DataColumn column in content.Content.Columns select new PdfPCell(new Phrase(dr[column.ColumnName] == null ? "" : dr[column.ColumnName].ToString(), content.ContentFont)) { HorizontalAlignment = Element.ALIGN_CENTER, VerticalAlignment = Element.ALIGN_MIDDLE, Padding = content.ContentFont.Size * 0.3f, }); row = new PdfPRow(cells.ToArray()); table.Rows.Add(row); } document.Add(table); return(document); }
public void ExportToPdf(DataTable dt, string strFilePath) { Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(strFilePath, FileMode.Create)); document.Open(); iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 5); PdfPTable table = new PdfPTable(dt.Columns.Count); PdfPRow row = null; float[] widths = new float[dt.Columns.Count]; for (int i = 0; i < dt.Columns.Count; i++) { widths[i] = 4f; } table.SetWidths(widths); table.WidthPercentage = 100; int iCol = 0; string colname = ""; PdfPCell cell = new PdfPCell(new Phrase("Products")); cell.Colspan = dt.Columns.Count; foreach (DataColumn c in dt.Columns) { table.AddCell(new Phrase(c.ColumnName, font5)); } foreach (DataRow r in dt.Rows) { if (dt.Rows.Count > 0) { for (int h = 0; h < dt.Columns.Count; h++) { table.AddCell(new Phrase(r[h].ToString(), font5)); } } } document.Add(table); document.Close(); }
public void ExportToPdf(DataTable dt, int billno) { Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("E:\\Project\\CMSW\\PDF's\\" + billno + ".pdf", FileMode.Create)); document.Open(); iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 5); font5.Color = new BaseColor(System.Drawing.Color.DarkGray); PdfPTable table = new PdfPTable(dt.Columns.Count); PdfPRow row = null; float[] widths = new float[] { 100f, 100f, 100f, 100f }; table.SetWidths(widths); table.WidthPercentage = 50; int iCol = 0; string colname = ""; PdfPCell cell = new PdfPCell(new Phrase("Products")); cell.Colspan = dt.Columns.Count; foreach (DataColumn c in dt.Columns) { table.AddCell(new Phrase(c.ColumnName, font5)); } foreach (DataRow r in dt.Rows) { if (dt.Rows.Count > 0) { table.AddCell(new Phrase(r[0].ToString(), font5)); table.AddCell(new Phrase(r[1].ToString(), font5)); table.AddCell(new Phrase(r[2].ToString(), font5)); table.AddCell(new Phrase(r[3].ToString(), font5)); } } string name = "cool"; string order = "Bill no." + billno; document.Add(table); document.Close(); }
private PdfPTable crearTablaRUT() { PdfPTable table = new PdfPTable(1); int[] azul = new int[] { 62, 120, 186 }; int[] blanco = new int[] { 255, 255, 255 }; PdfPCell[] cells = new PdfPCell[] { new PdfPCell(GetCell("RUT COMPRADOR", 0, blanco, 1)), }; PdfPCell[] cells1 = new PdfPCell[] { new PdfPCell(GetCell("110322520014", 0, blanco, 1)), }; PdfPRow row = new PdfPRow(cells); PdfPRow row2 = new PdfPRow(cells1); table.Rows.Add(row); table.Rows.Add(row2); return(table); }
// Метод для добавления строк public void AddRow(PdfPTable table, string CellName1, string CellName2, string CellName3, iTextSharp.text.Font font) { var cells = new PdfPCell[3]; cells[0] = new PdfPCell(new Phrase(CellName1 + " человек", font)); cells[1] = new PdfPCell(new Phrase(CellName2 + " человек", font)); cells[2] = new PdfPCell(new Phrase(CellName3 + " Руб.", font)); foreach (var el in cells) { el.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; el.HorizontalAlignment = PdfPCell.ALIGN_CENTER; el.Border = 0; el.PaddingTop = 20; el.PaddingBottom = 20; } var row = new PdfPRow(cells); table.Rows.Add(row); }
private void buttonCreateReport_Click(object sender, EventArgs e) { string FirstCell, SecondCell, ThirdCell; iTextSharp.text.Document doc = new iTextSharp.text.Document();//Создание нового документа if (saveFileDialog1.ShowDialog() == DialogResult.Cancel) { return; } // получаем выбранный файл string filename = saveFileDialog1.FileName + ".pdf";//имя файла if (filename != "") { PdfWriter.GetInstance(doc, new FileStream(filename, FileMode.Create)); doc.Open(); BaseFont baseFont = BaseFont.CreateFont(@"C:\Windows\Fonts\Calibri.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//Установление базового шрифта iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL, BaseColor.GRAY); PdfPTable table = new PdfPTable(3); PdfPCell[] cells = new PdfPCell[3]; cells[0] = new PdfPCell(new Phrase($"Количество зарегистрированных пользователей за период", font)); cells[1] = new PdfPCell(new Phrase($"Количество добавленных мастеров за период", font)); cells[2] = new PdfPCell(new Phrase($"Полученные средства за период", font)); foreach (var el in cells) { el.VerticalAlignment = PdfPCell.ALIGN_MIDDLE; el.HorizontalAlignment = PdfPCell.ALIGN_CENTER; el.Border = 0; } var row = new PdfPRow(cells); table.Rows.Add(row); font = new iTextSharp.text.Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL, BaseColor.BLACK); FirstCell = textBoxCountUserReg.Text; //Добавление в первую ячейку количества пользователей SecondCell = textBoxCountAddMaster.Text; //Добавление во вторую ячейку количества добавленных мастеров ThirdCell = textBoxProfitForTheP.Text; //Добавление в третью ячейку прибыли AddRow(table, FirstCell, SecondCell, ThirdCell, font); doc.Add(table); doc.Close(); MessageBox.Show("Pdf-документ сохранен"); } }
/// <summary> /// 打印一行表格数据 /// </summary> /// <param name="pCells">数据行包含的单元格集合</param> /// <param name="cWidth">数据行包含的单元格各自的宽度集合</param> public void PrintTableRow(PdfPCell[] pCells, float[] cWidth) { if (pCells == null || pCells.Length <= 0) { throw new ArgumentException("Can not found any cell."); } var pt = new PdfPTable(pCells.Length) { WidthPercentage = 100f, SkipFirstHeader = false }; var pRow = new PdfPRow(pCells); pt.Rows.Add(pRow); if (cWidth != null && cWidth.Length == pCells.Length) { pt.SetWidths(cWidth); } Doc.Add(pt); }
public static void ExportToPdf(DataTable dt) { Document document = new Document(); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(PdfFolderPath + NameFile + ".pdf", FileMode.Create)); document.Open(); iTextSharp.text.Font font5 = FontFactory.GetFont(FontFactory.HELVETICA, 5); PdfPTable table = new PdfPTable(dt.Columns.Count); PdfPRow row = null; float[] widths = new float[] { 4f, 4f, 4f, 4f }; table.SetWidths(widths); table.WidthPercentage = 100; int iCol = 0; string colname = ""; PdfPCell cell = new PdfPCell(new Phrase("Products")); cell.Colspan = dt.Columns.Count; foreach (DataColumn c in dt.Columns) { table.AddCell(new Phrase(c.ColumnName, font5)); } foreach (DataRow r in dt.Rows) { if (dt.Rows.Count > 0) { table.AddCell(new Phrase(r[0].ToString(), font5)); table.AddCell(new Phrase(r[1].ToString(), font5)); table.AddCell(new Phrase(r[2].ToString(), font5)); table.AddCell(new Phrase(r[3].ToString(), font5)); } } document.Add(table); document.Close(); MessageBox.Show("Uspjesno završeno!", "Obavijest"); }
/// <summary> /// Imports a PdfPRow and copies all settings /// @since 2.1.3 /// </summary> /// <param name="row">The PdfPRow to import</param> private void importRow(PdfPRow row) { _cells = new ArrayList(); _width = Document.GetDocumentHeader().GetPageSetting().GetPageWidth() - Document.GetDocumentHeader().GetPageSetting().GetMarginLeft() - Document.GetDocumentHeader().GetPageSetting().GetMarginRight(); _width = (int)(_width * _parentTable.GetTableWidthPercent() / 100); var cellRight = 0; var cellWidth = 0; var cells = row.GetCells(); for (var i = 0; i < cells.Length; i++) { cellWidth = (int)(_width * _parentTable.GetProportionalWidths()[i] / 100); cellRight = cellRight + cellWidth; var cell = cells[i]; var rtfCell = new RtfCell(Document, this, cell); rtfCell.SetCellRight(cellRight); rtfCell.SetCellWidth(cellWidth); _cells.Add(rtfCell); } }
/** * Imports a PdfPRow and copies all settings * * @param row The PdfPRow to import * @since 2.1.3 */ private void ImportRow(PdfPRow row) { this.cells = new ArrayList(); this.width = this.document.GetDocumentHeader().GetPageSetting().GetPageWidth() - this.document.GetDocumentHeader().GetPageSetting().GetMarginLeft() - this.document.GetDocumentHeader().GetPageSetting().GetMarginRight(); this.width = (int)(this.width * this.parentTable.GetTableWidthPercent() / 100); int cellRight = 0; int cellWidth = 0; PdfPCell[] cells = row.GetCells(); for (int i = 0; i < cells.Length; i++) { cellWidth = (int)(this.width * this.parentTable.GetProportionalWidths()[i] / 100); cellRight = cellRight + cellWidth; PdfPCell cell = cells[i]; RtfCell rtfCell = new RtfCell(this.document, this, cell); rtfCell.SetCellRight(cellRight); rtfCell.SetCellWidth(cellWidth); this.cells.Add(rtfCell); } }
/// <summary> /// 打印一个表格数据 /// </summary> /// <param name="table">表格</param> /// <param name="cWidth">宽度</param> /// <param name="cAlign">对齐 0左 1中 2右</param> public void PrintTableContent(DataTable table, float[] cWidth, int[] cAlign) { if (table == null || table.Columns == null || table.Columns.Count <= 0) { throw new ArgumentException("Can not found any column from table."); } var pt = new PdfPTable(table.Columns.Count) { WidthPercentage = 100f, SkipFirstHeader = false }; PdfPCell[] pCells; PdfPRow pRow; //内容 foreach (DataRow row in table.Rows) { pCells = new PdfPCell[table.Columns.Count]; for (var i = 0; i < table.Columns.Count; i++) { pCells[i] = new PdfPCell(new Phrase(row[i].ToString(), DefaultFont)); if (cAlign != null && cAlign.Length == table.Columns.Count) { pCells[i].HorizontalAlignment = cAlign[i]; pCells[i].Border = 0; } pCells[i].VerticalAlignment = 1; } pRow = new PdfPRow(pCells); pt.Rows.Add(pRow); } if (cWidth != null && cWidth.Length == table.Columns.Count) { pt.SetWidths(cWidth); } Doc.Add(pt); }
private void CreateContractorTable(AgencyOwnerFixedPriceProposalDetailsOutput proposal, PdfPTable pdfTable) { var fontTableHeader = GetCommonFont(); PdfPRow headerRow = new PdfPRow(new[] { AddHeaderToDetailTable(fontTableHeader, "CONTRACTOR"), AddHeaderToDetailTable(fontTableHeader, "CUSTOMER RATE"), AddHeaderToDetailTable(fontTableHeader, "CU MAX WEEKLY") }); pdfTable.Rows.Add(headerRow); int i = 0; var backgroundColor = new BaseColor(246, 249, 252); foreach (var proposedContract in proposal.ProposedContracts) { CreateContractorRow(proposedContract, pdfTable, fontTableHeader, i % 2 != 0 ? backgroundColor : BaseColor.White); i++; } }
public static PdfPCell[] AddEmptyRowToTable(PdfPTable table, bool isBorderShown, bool isWithPadding, bool isAlighCenter) { PdfPCell[] rowCells = new PdfPCell[table.NumberOfColumns]; for (int i = 0; i < rowCells.Length; i++) { rowCells[i] = new PdfPCell(); if (!isBorderShown) { rowCells[i].Border = 0; } if (!isWithPadding) { rowCells[i].Padding = 0f; } if (isAlighCenter) { rowCells[i].HorizontalAlignment = Element.ALIGN_CENTER; } } PdfPRow addedRow = new PdfPRow(rowCells); table.Rows.Add(addedRow); return(addedRow.GetCells()); }
/** * @see com.itextpdf.text.pdf.PdfPTableEventAfterSplit#afterSplitTable(com.itextpdf.text.pdf.PdfPTable, com.itextpdf.text.pdf.PdfPRow, int) * @since iText 5.4.3 */ virtual public void AfterSplitTable(PdfPTable table, PdfPRow startRow, int startIdx) { foreach (IPdfPTableEvent evente in events) { if (evente is IPdfPTableEventAfterSplit) ((IPdfPTableEventAfterSplit)evente).AfterSplitTable(table, startRow, startIdx); } }