// el metodo retorna un tabla para el documento pdf private PdfPTable PdfTable(GunaDataGridView table) { PdfPTable pdfTable = new PdfPTable(table.Columns.Count); pdfTable.DefaultCell.Padding = 3; pdfTable.WidthPercentage = 100; pdfTable.HorizontalAlignment = Element.ALIGN_LEFT; pdfTable.SpacingBefore = 20; foreach (DataGridViewColumn column in table.Columns) { PdfPHeaderCell pdfCell = new PdfPHeaderCell() { Phrase = new Phrase(column.HeaderText) }; pdfTable.AddCell(pdfCell); } foreach (DataGridViewRow row in table.Rows) { foreach (DataGridViewCell cell in row.Cells) { pdfTable.AddCell(cell.Value.ToString()); } } return(pdfTable); }
private PdfPCell HeaderCell(string CellContent) { PdfPHeaderCell cell = new PdfPHeaderCell(); cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.HorizontalAlignment = 1; cell.Phrase = new Phrase(CellContent); return(cell); }
private PdfPHeaderCell HeaderCell(string cellContent) { PdfPHeaderCell cell = new PdfPHeaderCell { BackgroundColor = BaseColor.LIGHT_GRAY, HorizontalAlignment = 1, Phrase = new Phrase(cellContent) }; return(cell); }
private void GenerateReportTableHeaders(ref Document doc, out PdfPTable stTable) { // Table creation stTable = new PdfPTable(6); stTable.DefaultCell.Border = 1; stTable.WidthPercentage = 100; stTable.SpacingBefore = 70f; stTable.TotalWidth = 500f; stTable.SetWidths(new float[] { 5f, 60f, 20f, 20f, 15f, 15f }); stTable.LockedWidth = true; // End of table creation // Header Font thFont = new Font(bFont, 13, Font.BOLD, BaseColor.BLACK); PdfPHeaderCell headerCell = new PdfPHeaderCell(); headerCell.AddElement(new Paragraph("№", thFont) { Alignment = Element.ALIGN_CENTER }); stTable.AddCell(headerCell); headerCell = new PdfPHeaderCell(); headerCell.AddElement(new Paragraph("ФИО", thFont) { Alignment = Element.ALIGN_CENTER }); stTable.AddCell(headerCell); headerCell = new PdfPHeaderCell(); headerCell.AddElement(new Paragraph("Получено баллов за семестр", thFont) { Alignment = Element.ALIGN_CENTER }); stTable.AddCell(headerCell); headerCell = new PdfPHeaderCell(); headerCell.AddElement(new Paragraph("Получено баллов за экзамен", thFont) { Alignment = Element.ALIGN_CENTER }); stTable.AddCell(headerCell); headerCell = new PdfPHeaderCell(); headerCell.AddElement(new Paragraph("Всего баллов", thFont) { Alignment = Element.ALIGN_CENTER }); stTable.AddCell(headerCell); headerCell = new PdfPHeaderCell(); headerCell.AddElement(new Paragraph("Итоговая оценка", thFont) { Alignment = Element.ALIGN_CENTER }); stTable.AddCell(headerCell); // Header end }
public static void CreatePdfTable() { //first column is 3 times longer than the others var widths = new[] { 3f, 1f, 1f, 1f, 1f, 1f }; var table = new PdfPTable(widths); table.DefaultCell.Border = PdfPCell.NO_BORDER; table.DefaultCell.VerticalAlignment = Element.ALIGN_CENTER; var hdr = new PdfPHeaderCell(); hdr.Colspan = widths.Length; hdr.AddElement(new Paragraph("SUMMARY REPORT")); table.AddCell(hdr); table.AddCell(""); var cell = new PdfPCell(); cell.Border = PdfPCell.NO_BORDER; var p1 = new Paragraph("Mar"); p1.Alignment = Element.ALIGN_CENTER; cell.AddElement(p1); var p2 = new Paragraph("2018"); p1.Alignment = Element.ALIGN_CENTER; cell.AddElement(p2); table.AddCell(cell); table.AddCell("Apr 2017"); table.AddCell("May 2016"); table.AddCell("Mar 2015"); table.AddCell("Jul 2014"); table.AddCell("Some row name"); table.AddCell("1.1"); table.AddCell("1.2"); table.AddCell("1.3"); table.AddCell("1.4"); table.AddCell("1.5"); var document = new Document(PageSize.LETTER); var pdfWriter = PdfWriter.GetInstance(document, new FileStream(@"C:\Projects\31g\trunk\temp\pdf\myPdfTable.pdf", FileMode.OpenOrCreate)); document.Open(); document.Add(table); document.Close(); pdfWriter.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 byte[] GetPDFDocument() { byte[] stream; using (MemoryStream output = new MemoryStream()) { BaseFont baseFont = BaseFont.CreateFont(@"C:\Windows\Fonts\times.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font font = new iTextSharp.text.Font(baseFont, 12); Font fontCapital = new iTextSharp.text.Font(baseFont, 16, Font.BOLD); Document doc = new Document(); PdfWriter writer = PdfWriter.GetInstance(doc, output); doc.Open(); doc.Add(new Paragraph("\n", font)); PdfPTable table = new PdfPTable(1); table.DefaultCell.Border = PdfPCell.NO_BORDER; //table.DefaultCell.VerticalAlignment = Element.ALIGN_RIGHT; table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; table.AddCell(new Phrase("АКТ № " + _NumberExp.ToString(), fontCapital)); table.AddCell(new Phrase("ТЕХНИЧЕСКОЙ ЭКСПЕРТИЗЫ", fontCapital)); table.AddCell(new Phrase("к обращению ID " + _RequestId, fontCapital)); doc.Add(table); doc.Add(new Chunk("\n")); //doc.Add(new Chunk("Настоящий акт составил - ",font)); doc.Add(new Chunk("\n")); PdfPTable tableDate = new PdfPTable(1); tableDate.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT; tableDate.DefaultCell.Border = PdfPCell.NO_BORDER; tableDate.AddCell(new Phrase("Дата: " + _DateExp, font)); doc.Add(tableDate); doc.Add(new Chunk("\n")); doc.Add(new Chunk("Представителем ООО «Сбербанк-Сервис» прозведены работы по технической экспертизе следующего технического средства:", font)); doc.Add(new Chunk("\n")); // Таблица с данными по оборудованию PdfPTable mainTable = new PdfPTable(5); mainTable.WidthPercentage = 100; mainTable.DefaultCell.VerticalAlignment = Element.ALIGN_CENTER; mainTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; PdfPHeaderCell headerCell0 = new PdfPHeaderCell(); headerCell0.AddElement(new Phrase("Наименование", font)); mainTable.AddCell(headerCell0); PdfPHeaderCell headerCell1 = new PdfPHeaderCell(); headerCell1.AddElement(new Phrase("Инвентарный номер", font)); mainTable.AddCell(headerCell1); PdfPHeaderCell headerCell2 = new PdfPHeaderCell(); headerCell2.AddElement(new Phrase("Серийный номер", font)); mainTable.AddCell(headerCell2); PdfPHeaderCell headerCell3 = new PdfPHeaderCell(); headerCell3.AddElement(new Phrase("Год ввода в экспл.", font)); mainTable.AddCell(headerCell3); PdfPHeaderCell headerCell4 = new PdfPHeaderCell(); headerCell4.AddElement(new Phrase("Техническое состояние устройства (описание неисправности)", font)); mainTable.AddCell(headerCell4); mainTable.AddCell(new Phrase(_Name, font)); mainTable.AddCell(new Phrase(_InventoryNumber, font)); mainTable.AddCell(new Phrase(_SerialNumber, font)); mainTable.AddCell(new Phrase(_StartupDate, font)); mainTable.AddCell(new Phrase(_Reason, font)); doc.Add(mainTable); doc.Add(new Chunk("\n")); // Таблица о результате с решением PdfPTable conclusionTable = new PdfPTable(3); conclusionTable.WidthPercentage = 100; conclusionTable.DefaultCell.VerticalAlignment = Element.ALIGN_CENTER; conclusionTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; PdfPCell headerCell10 = new PdfPCell(); headerCell10.AddElement(new Phrase("Заключение:", font)); conclusionTable.AddCell(headerCell10); PdfPCell headerCell11 = new PdfPCell(new Phrase("Да", font)); headerCell11.HorizontalAlignment = Element.ALIGN_CENTER; conclusionTable.AddCell(headerCell11); PdfPCell headerCell12 = new PdfPCell(new Phrase("Нет", font)); headerCell12.HorizontalAlignment = Element.ALIGN_CENTER; conclusionTable.AddCell(headerCell12); conclusionTable.AddCell(new Phrase("Оборудование исправно", font)); PdfPCell cellYesNo = new PdfPCell(new Phrase("+", font)); cellYesNo.HorizontalAlignment = Element.ALIGN_CENTER; if ((_IsServiceableEquipment ?? false)) { conclusionTable.AddCell(cellYesNo); conclusionTable.AddCell(new Phrase("", font)); } else { conclusionTable.AddCell(new Phrase("", font)); conclusionTable.AddCell(cellYesNo); } conclusionTable.AddCell(new Phrase("Необходим ремонт по гарантии", font)); if (_IsWarrantyRepair ?? false) { conclusionTable.AddCell(cellYesNo); conclusionTable.AddCell(new Phrase("", font)); } else { conclusionTable.AddCell(new Phrase("", font)); conclusionTable.AddCell(cellYesNo); } conclusionTable.AddCell(new Phrase("Возможен ремонт ООО «Сбербанк-Сервис»", font)); if (_IsOrganizationRepair ?? false) { conclusionTable.AddCell(cellYesNo); conclusionTable.AddCell(new Phrase("", font)); } else { conclusionTable.AddCell(new Phrase("", font)); conclusionTable.AddCell(cellYesNo); } conclusionTable.AddCell(new Phrase("Требуется поставка запчастей", font)); if (_IsPartsSupply ?? false) { conclusionTable.AddCell(cellYesNo); conclusionTable.AddCell(new Phrase("", font)); } else { conclusionTable.AddCell(new Phrase("", font)); conclusionTable.AddCell(cellYesNo); } conclusionTable.AddCell(new Phrase("Пригодно к эксплуатации", font)); if (_IsServiceable ?? false) { conclusionTable.AddCell(cellYesNo); conclusionTable.AddCell(new Phrase("", font)); } else { conclusionTable.AddCell(new Phrase("", font)); conclusionTable.AddCell(cellYesNo); } conclusionTable.AddCell(new Phrase("Рекомендуется к списанию", font)); if (_IsForWriteoff ?? false) { conclusionTable.AddCell(cellYesNo); conclusionTable.AddCell(new Phrase("", font)); } else { conclusionTable.AddCell(new Phrase("", font)); conclusionTable.AddCell(cellYesNo); } doc.Add(conclusionTable); //picture.ScaleToFit(50f, 50f); //picture.Alignment = Image.ALIGN_RIGHT | Image.TEXTWRAP; //picture.IndentationLeft = 3f; //picture.SpacingAfter = 3f; //picture.BorderWidthTop = 6f; //doc.Add(picture); doc.Add(new Chunk("\n")); doc.Add(new Paragraph("Дополнительные рекомендации: " + _Conclusion, font)); doc.Add(new Paragraph("Представитель ООО «Сбербанк-Сервис»:", font)); //doc.Add(new Chunk("\n")); // Таблица для выполнившего акт и его подписи // Ячейка для подписи PdfPTable tableSign = new PdfPTable(2); tableSign.WidthPercentage = 100; tableSign.DefaultCell.Border = PdfPCell.NO_BORDER; tableSign.DefaultCell.VerticalAlignment = Element.ALIGN_BOTTOM; tableSign.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; // Ячейка для ФИО и должности PdfPCell cellText = new PdfPCell(new Phrase(_Staff, font)); cellText.NoWrap = true; cellText.BorderColor = BaseColor.WHITE; cellText.HorizontalAlignment = Element.ALIGN_LEFT; cellText.VerticalAlignment = Element.ALIGN_BOTTOM; tableSign.AddCell(cellText); PdfPCell cellSign; if (_ImgData != null) { Image picture = Image.GetInstance(_ImgData); picture.ScaleToFit(100f, 100f); picture.BorderWidthTop = 0f; //picture.Alignment = Image.ALIGN_RIGHT | Image.TEXTWRAP; cellSign = new PdfPCell(picture); } else { cellSign = new PdfPCell(); } cellSign.BorderColor = BaseColor.WHITE; cellSign.HorizontalAlignment = Element.ALIGN_CENTER; tableSign.AddCell(new PdfPCell(cellSign)); doc.Add(tableSign); doc.Add(new Paragraph("Управления по сервису Уральского Банка ООО «Сбербанк-Сервис»", font)); doc.Add(new Paragraph("Работы приняты:", font)); if (!string.IsNullOrWhiteSpace(_Staff2)) { doc.Add(new Paragraph(_Staff2, font)); } else { doc.Add(new Paragraph("_____________________________________________________________________ ")); } doc.Close(); stream = output.ToArray(); } return(stream); }
public MemoryStream GenerateReport(Project project, string serverPath) { var document = new Document(PageSize.A4, 50, 50, 25, 25); var date = System.DateTime.Now.ToLongDateString(); var documentName = project.Name + " Report " + date; var output = new MemoryStream(); var logoFont = FontFactory.GetFont("Verdana", 26, Font.BOLD); var projectNameFont = FontFactory.GetFont("Arial", 20, Font.BOLD); var boldTableFont = FontFactory.GetFont("Arial", 9, Font.BOLD); var tableFont = FontFactory.GetFont("Arial", 9, Font.NORMAL); var bodyFont = FontFactory.GetFont("Arial", 12, Font.NORMAL); var headerFont = FontFactory.GetFont("Verdana", 16, Font.NORMAL); var writer = PdfWriter.GetInstance(document, output); writer.PageEvent = this; document.Open(); #region logo var logoParagraph = new Paragraph("Project Manager", logoFont); logoParagraph.Alignment = Element.ALIGN_RIGHT; logoParagraph.SpacingAfter = 15; document.Add(logoParagraph); #endregion #region projectName var projectNameParagraph = new Paragraph(project.Name, projectNameFont); projectNameParagraph.Alignment = Element.ALIGN_CENTER; projectNameParagraph.SpacingAfter = 15; document.Add(projectNameParagraph); #endregion #region description var descriptionParagraph = new Paragraph(project.Description, bodyFont); descriptionParagraph.Alignment = Element.ALIGN_JUSTIFIED; descriptionParagraph.SpacingAfter = 20; document.Add(descriptionParagraph); #endregion #region sprintsTable if (project.Sprints.Count() != 0) { var sprintsParagraph = new Paragraph("Sprints", headerFont); sprintsParagraph.PaddingTop = 20; sprintsParagraph.Alignment = Element.ALIGN_CENTER; document.Add(sprintsParagraph); var sprintsTable = new PdfPTable(3); sprintsTable.HorizontalAlignment = 0; sprintsTable.SpacingBefore = 10; sprintsTable.SpacingAfter = 10; sprintsTable.DefaultCell.Border = 1; sprintsTable.WidthPercentage = 100; string[] SprintProperties = { "Name:", "Start date:", "End date:" }; foreach (var property in SprintProperties) { var phrase = new Phrase(property, boldTableFont); var cell = new PdfPHeaderCell(); cell.Phrase = phrase; sprintsTable.AddCell(cell); } foreach (var sprint in project.Sprints) { #region properites var name = sprint.Name ?? ""; string startDate; if (sprint.StartDate != null) { startDate = sprint.StartDate.ToString(); } else { startDate = ""; } string endDate; if (sprint.EndDate != null) { endDate = sprint.EndDate.ToString(); } else { endDate = ""; } string[] sprintProps = new string[3] { name, startDate, endDate }; #endregion foreach (var property in sprintProps) { var phrase = new Phrase(property, tableFont); var cell = new PdfPCell(); cell.Phrase = phrase; cell.PaddingBottom = 5; sprintsTable.AddCell(cell); } } sprintsTable.SpacingAfter = 20; document.Add(sprintsTable); } #endregion #region assignmentsTable if (project.Assignemnts.Count() != 0) { var assignmentsParagraph = new Paragraph("Assignments", headerFont); assignmentsParagraph.PaddingTop = 20; assignmentsParagraph.Alignment = Element.ALIGN_CENTER; document.Add(assignmentsParagraph); var asssignmentsTable = new PdfPTable(9); asssignmentsTable.HorizontalAlignment = 0; asssignmentsTable.SpacingBefore = 10; asssignmentsTable.SpacingAfter = 10; asssignmentsTable.DefaultCell.Border = 1; asssignmentsTable.WidthPercentage = 100; string[] properties = { "Name:", "Owner:", "Assigned to:", "Status:", "Priority:", "Category:", "Start:", "Stop:", "Estimation:" }; foreach (var property in properties) { var phrase = new Phrase(property, boldTableFont); var cell = new PdfPHeaderCell(); cell.Phrase = phrase; asssignmentsTable.AddCell(cell); } foreach (var assignment in project.Assignemnts) { #region properites var name = assignment.Name ?? ""; string owner; if (assignment.Owner != null) { owner = assignment.Owner.FirstName + " " + assignment.Owner.LastName; } else { owner = ""; } string assignedTo; if (assignment.AssignedTo != null && assignment.Owner != null) { assignedTo = assignment.AssignedTo.FirstName + " " + assignment.Owner.LastName; } else { assignedTo = ""; } string status; if (assignment.Status != null) { status = assignment.Status.Description; } else { status = ""; } string priority; if (assignment.Priority != null) { priority = assignment.Priority.Description; } else { priority = ""; } string category; if (assignment.Category != null) { category = assignment.Category.Description; } else { category = ""; } string startDateTime; if (assignment.StartDateTime != null) { startDateTime = assignment.StartDateTime.ToString(); } else { startDateTime = ""; } string stopDateTime; if (assignment.StopDateTime != null) { stopDateTime = assignment.StopDateTime.ToString(); } else { stopDateTime = ""; } string estimation; if (assignment.Estimation != null) { estimation = assignment.Estimation.ToString(); } else { estimation = ""; } string[] asignmentProps = new string[9] { name, owner, assignedTo, status, priority, category, startDateTime, stopDateTime, estimation }; #endregion foreach (var property in asignmentProps) { var phrase = new Phrase(property, tableFont); var cell = new PdfPCell(); cell.Phrase = phrase; cell.PaddingBottom = 5; asssignmentsTable.AddCell(cell); } } asssignmentsTable.SpacingAfter = 20; document.Add(asssignmentsTable); } #endregion #region membersTable if (project.Members.Count() != 0) { var membersParagraph = new Paragraph("Members", headerFont); membersParagraph.PaddingTop = 20; membersParagraph.Alignment = Element.ALIGN_CENTER; document.Add(membersParagraph); var membersTable = new PdfPTable(3); membersTable.HorizontalAlignment = 0; membersTable.SpacingBefore = 10; membersTable.SpacingAfter = 10; membersTable.DefaultCell.Border = 1; membersTable.WidthPercentage = 100; string[] membersProperties = { "First name:", "Last name:", "E-mail adress:" }; foreach (var property in membersProperties) { var phrase = new Phrase(property, boldTableFont); var cell = new PdfPHeaderCell(); cell.Phrase = phrase; membersTable.AddCell(cell); } foreach (var member in project.Members) { #region properites var firstName = member.FirstName ?? ""; var lastName = member.LastName ?? ""; var eMail = member.Email ?? ""; string[] memberProps = new string[] { firstName, lastName, eMail }; #endregion foreach (var property in memberProps) { var phrase = new Phrase(property, tableFont); var cell = new PdfPCell(); cell.Phrase = phrase; cell.PaddingBottom = 5; membersTable.AddCell(cell); } } document.Add(membersTable); } #endregion document.Close(); return(output); }
protected PdfPTable GetDailyEventsFor(DayOfWeek dayOfWeek) { using (WebhostEntities db = new WebhostEntities()) { PdfPTable table = new PdfPTable(3); PdfPHeaderCell headerCell = new PdfPHeaderCell() { Colspan = 3, Border = 0, Padding = 1f }; Paragraph hp = new Paragraph(WeekendDates.GetDayOfWeek(dayOfWeek).ToLongDateString(), HeaderFont); headerCell.AddElement(hp); table.AddCell(headerCell); Weekend weekend = db.Weekends.Where(w => w.id == WeekendId).Single(); List <WeekendTableItem> things = new List <WeekendTableItem>(); foreach (WeekendActivity activity in weekend.WeekendActivities.Where(act => !act.IsDeleted && act.DateAndTime.DayOfWeek == dayOfWeek).OrderBy(act => act.DateAndTime).ToList()) { things.Add(new WeekendTableItem(activity)); } foreach (WeekendDuty duty in weekend.WeekendDuties.Where(d => !d.IsDeleted && d.DateAndTime.DayOfWeek == dayOfWeek).OrderBy(d => d.DateAndTime).ToList()) { things.Add(new WeekendTableItem(duty)); } foreach (WeekendTableItem activity in things.OrderBy(act => act.DateAndTime)) { PdfPCell timeCell = new PdfPCell() { Border = 0, Padding = 1f };; PdfPCell actCell = new PdfPCell() { Border = 0, Padding = 1f };; PdfPCell adsCell = new PdfPCell() { Border = 0, Padding = 1f };; Paragraph time = new Paragraph(String.Format("{0}{1}", activity.DateAndTime.Hour == 0 ? "All Day" : activity.DateAndTime.ToShortTimeString(), activity.Duration == 0 ? "" : " ~ " + activity.DateAndTime.AddMinutes(activity.Duration).ToShortTimeString()), PageFont); timeCell.AddElement(time); table.AddCell(timeCell); Paragraph actP = new Paragraph(String.Format("{0}{1}", activity.Name, activity.Notes.Equals("") ? "" : String.Format(" ({0})", activity.Notes)), PageFont); actCell.AddElement(actP); table.AddCell(actCell); if (activity.Adults.Count < 4) { foreach (Faculty adult in activity.Adults) { Paragraph adp = new Paragraph(String.Format("{0} {1}", adult.FirstName, adult.LastName), PageFont); adsCell.AddElement(adp); } } else { Paragraph adp = new Paragraph("All Team", PageFont); adsCell.AddElement(adp); } table.AddCell(adsCell); } return(table); } }
public void CreateTaggedPdf17() { InitializeDocument("17"); PdfPTable table = new PdfPTable(2); PdfPCell cell = new PdfPCell(new Paragraph("h1")); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Paragraph("h2")); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Paragraph("footer 1")); cell.Colspan = 2; table.AddCell(cell); cell = new PdfPCell(new Paragraph("footer 2")); cell.Colspan = 2; table.AddCell(cell); table.HeaderRows = 4; table.FooterRows = 2; try { PdfPHeaderCell headerCell = null, headerCell2 = null; cell = null; for (int i = 1; i <= 2; i++) { if (i == 1) { headerCell = new PdfPHeaderCell(); headerCell.Scope = PdfPHeaderCell.ROW; headerCell.Phrase = new Phrase("header1"); headerCell.Name = "header1"; table.AddCell(headerCell); headerCell2 = new PdfPHeaderCell(); headerCell2.Scope = PdfPHeaderCell.ROW; headerCell2.Phrase = new Phrase("header2"); headerCell2.Name = "header2"; table.AddCell(headerCell2); } else { cell = new PdfPCell(new Phrase("row " + i + ", coumn 1")); cell.AddHeader(headerCell); table.AddCell(cell); cell = new PdfPCell(new Phrase("row " + i + ", coumn 2")); cell.AddHeader(headerCell2); cell.AddHeader(headerCell2); table.AddCell(cell); } } } catch (Exception e) { Trace.WriteLine(e.Message); } document.Add(table); document.Close(); int[] nums = new int[] { 27 }; CheckNums(nums); CompareResults("17"); }
// el metodo exporta el balance general en un documento pdf private void btnExportar_Click(object sender, EventArgs e) { using (SaveFileDialog saveFileDialog = new SaveFileDialog()) { saveFileDialog.Filter = "PDF (*.pdf)|*.pdf"; saveFileDialog.FileName = "Libro Diario.pdf"; bool fileError = false; if (saveFileDialog.ShowDialog() == DialogResult.OK) { if (File.Exists(saveFileDialog.FileName)) { try { File.Delete(saveFileDialog.FileName); } catch (Exception exception) { fileError = true; MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (!fileError) { try { PdfPTable pdfTable = new PdfPTable(tableLibroDiario.Columns.Count); pdfTable.DefaultCell.Padding = 3; pdfTable.WidthPercentage = 100; pdfTable.HorizontalAlignment = Element.ALIGN_LEFT; foreach (DataGridViewColumn column in tableLibroDiario.Columns) { PdfPHeaderCell pdfCell = new PdfPHeaderCell() { Phrase = new Phrase(column.HeaderText) }; pdfTable.AddCell(pdfCell); } foreach (DataGridViewRow row in tableLibroDiario.Rows) { foreach (DataGridViewCell cell in row.Cells) { pdfTable.AddCell(cell.Value.ToString()); } } using (FileStream stream = new FileStream(saveFileDialog.FileName, FileMode.Create)) { using (Document pdfDoc = new Document(PageSize.A4, 20f, 20f, 20f, 20f)) { PdfWriter.GetInstance(pdfDoc, stream); pdfDoc.Open(); pdfDoc.Add(title); pdfDoc.Add(periodo); pdfDoc.Add(pdfTable); pdfDoc.Close(); stream.Close(); } } } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }