I would like to format the sizes of your cells and your text for PDF export.
protectedvoidExportPDF(){intcolCount=_gvConsultaRelatorio.Columns.Count-1;PdfPTabletable=newPdfPTable(colCount);table.HorizontalAlignment=0;int[]colWidths=newint[_gvConsultaRelatorio.Columns.Count];PdfPCellcell;stringcellText;//CriandoHeaderfor(intcolIndex=0;colIndex<colCount;colIndex++){colWidths[colIndex]=(int)_gvConsultaRelatorio.Columns[colIndex].ItemStyle.Width.Value;cellText=Server.HtmlDecode(_gvConsultaRelatorio.HeaderRow.Cells[colIndex].Text);cell=newPdfPCell(newPhrase(cellText));cell.BackgroundColor=newBaseColor(System.Drawing.ColorTranslator.FromHtml("#d1dbe0"));
table.AddCell(cell);
}
//Exportar dados da Grid para Tabela
for (int rowIndex = 0; rowIndex < _gvConsultaRelatorio.Rows.Count; rowIndex++)
{
if (_gvConsultaRelatorio.Rows[rowIndex].RowType == DataControlRowType.DataRow)
{
for (int j = 0; j < _gvConsultaRelatorio.Columns.Count - 1; j++)
{
cellText = Server.HtmlDecode(_gvConsultaRelatorio.Rows[rowIndex].Cells[j].Text);
cell = new PdfPCell(new Phrase(cellText));
if (rowIndex % 2 != 0)
{
cell.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#9ab2ca"));
}
else
{
cell.BackgroundColor = new BaseColor(System.Drawing.ColorTranslator.FromHtml("#f1f5f6"));
}
table.AddCell(cell);
}
}
}
Document pdfDoc = new Document(PageSize.A4, 10f, 0f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
pdfDoc.Add(table);
pdfDoc.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;" + "filename=RelatorioPDF.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Write(pdfDoc);
Response.End();
//this._gvConsultaRelatorio.AllowPaging = true;
}