{
PdfPTable pdfTable1 = new PdfPTable(viev1.ColumnCount);
pdfTable1.HorizontalAlignment = 10; //
pdfTable1.TotalWidth = 1170f; // A4 GENİŞLİĞİ BELİRLEDİK
pdfTable1.LockedWidth = true;
float[] widths = new float[] { 1f, 120f, 70f, 135f, 40f, 60f, 30f, 135f, 60f, 60f, 50f, 40f, 50f, 1f }; // STÜN GENİŞLİKLERİ
pdfTable1.SetWidths(widths);
pdfTable1.HorizontalAlignment = Element.ALIGN_LEFT; // HERŞEY SAĞA HİZALI - SIKINTI YOK
pdfTable1.DefaultCell.BorderWidth = 1;
foreach (DataGridViewColumn column in viev1.Columns)
{
PdfPCell cell = new PdfPCell(new Phrase(column.HeaderText));
pdfTable1.AddCell(cell);
}
foreach (DataGridViewRow row in viev1.Rows)
{
foreach (DataGridViewCell cell in row.Cells)
{
pdfTable1.AddCell(cell.Value.ToString());
}
}
try
{
File.Delete(Application.StartupPath + "\\rapor.pdf");
using (FileStream stream = new FileStream(Application.StartupPath + "\\rapor.pdf", FileMode.Create))
{
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(PageSize.A2, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
pdfDoc.Add(pdfTable1);
pdfDoc.Close();
stream.Close();
Process pdfac = new Process();
pdfac.StartInfo.FileName = Application.StartupPath + "//kur//pdf.exe";
pdfac.StartInfo.Arguments = " rapor.pdf";
pdfac.Start();
}
}
catch
{
MessageBox.Show("Açık Olan Rapor Ekranını Kapatınız.", "Uyarı !!", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
}