private PdfPTable FormatPDF(char formOrigin) { //Default PDF Format var myfont = FontFactory.GetFont("Arial", 10, BaseColor.BLACK); var headerfont = FontFactory.GetFont("Arial", 11, BaseColor.BLACK); var pdfTable = new PdfPTable(GetDataGridViewData(formOrigin).ColumnCount); pdfTable.SetWidths(Reports.GetPDFFormat(formOrigin)); pdfTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE; pdfTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; pdfTable.DefaultCell.Padding = 3; pdfTable.WidthPercentage = 30; pdfTable.DefaultCell.BorderWidth = 1; pdfTable.HorizontalAlignment = 1; pdfTable.TotalWidth = 1000f; pdfTable.LockedWidth = true; //Add Headers Here pdfTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; pdfTable.AddCell(new Phrase("Client Name", headerfont)); pdfTable.AddCell(new Phrase("Status", headerfont)); pdfTable.AddCell(new Phrase("Client Address", headerfont)); pdfTable.AddCell(new Phrase("Manager", headerfont)); pdfTable.AddCell(new Phrase("Contact Person", headerfont)); pdfTable.AddCell(new Phrase("Contact Number", headerfont)); //Add Data to PDF foreach (DataGridViewRow row in GetDataGridViewData(formOrigin).Rows) { foreach (DataGridViewCell cell in row.Cells) { var newcell = new PdfPCell(new Phrase(cell.Value.ToString(), myfont)); newcell.PaddingTop = 5f; newcell.PaddingBottom = 8f; pdfTable.AddCell(newcell); } } return(pdfTable); }
public void FormatPDF(char formOrigin) { //Default PDF Format GReportGRD.DataSource = Reports.GetList(formOrigin); String strcheck = ""; if (formOrigin == 'd') { for (int x = 0; x < GReportGRD.RowCount; x++) { if (GReportGRD.Rows[x].Cells[0].Value.ToString() != strcheck) { strcheck = GReportGRD.Rows[x].Cells[0].Value.ToString(); } else { GReportGRD.Rows[x].Cells[0].Value = ""; } } } // var myfont = FontFactory.GetFont("Arial", 8, BaseColor.BLACK); var pdfTable = new PdfPTable(GReportGRD.ColumnCount); pdfTable.SetWidths(Reports.GetPDFFormat(formOrigin)); pdfTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE; //pdfTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT; pdfTable.DefaultCell.Padding = 3; pdfTable.WidthPercentage = 30; pdfTable.DefaultCell.BorderWidth = 1; pdfTable.HorizontalAlignment = 1; pdfTable.TotalWidth = 1000f; pdfTable.LockedWidth = true; PdfPTable pdfReportHeader = new PdfPTable(1); pdfReportHeader.DefaultCell.Padding = 3; pdfReportHeader.WidthPercentage = 30; pdfReportHeader.DefaultCell.BorderWidth = 0; pdfReportHeader.TotalWidth = 1000f; pdfReportHeader.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; //Add Headers Here pdfTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER; Reports r = new Reports(); pdfReportHeader.AddCell(r.getTitlePhrase(formOrigin)); pdfTable = AddHeaders(pdfTable, formOrigin); //Add Data to PDF foreach (DataGridViewRow row in GReportGRD.Rows) { foreach (DataGridViewCell cell in row.Cells) { var newcell = new PdfPCell(new Phrase(cell.Value.ToString(), myfont)) { PaddingTop = 5f, PaddingBottom = 8f }; if (cell.ColumnIndex != 0 && formOrigin == 's') { newcell.HorizontalAlignment = Element.ALIGN_RIGHT; pdfTable.AddCell(newcell); } else if (formOrigin == 'g') { if (!(cell.ColumnIndex == 0 || cell.ColumnIndex == 1)) { newcell.HorizontalAlignment = Element.ALIGN_RIGHT; pdfTable.AddCell(newcell); } else { pdfTable.AddCell(newcell); } } else { newcell.HorizontalAlignment = Element.ALIGN_LEFT; pdfTable.AddCell(newcell); } } } r.ExportToPDF(pdfReportHeader, pdfTable, formOrigin); }