How to save created PDF file into dynamically file - c#

In my case, I need to let the user shoose the folder and the file name.
I know that I have to make some changes to "PdfWriterGetInstance".
Then how can I change my code to make it as I want:
Document doc = new Document(iTextSharp.text.PageSize.A4, 10, 10, 42, 35);
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("Stock.pdf", FileMode.Create));
doc.Open();
Paragraph paragraphe = new Paragraph("Raport of Stock\n\n");
paragraphe.Alignment = Element.ALIGN_CENTER;
doc.Add(paragraphe);
DateTime now = new DateTime();
Paragraph paragraphe3 = new Paragraph(" " + now.ToString()+"\n\n\n");
paragraphe.Alignment = Element.ALIGN_LEFT;
doc.Add(paragraphe3);
PdfPTable table = new PdfPTable(dataGridView1.Columns.Count);
//add the header
for (int j=0; j < dataGridView1.Columns.Count; j++)
{
table.AddCell(new Phrase(dataGridView1.Columns[j].HeaderText));
}
//Flag the first row as a header
table.HeaderRows = 1;
for(int i = 0; i< dataGridView1.Rows.Count; i++)
{
for(int k = 0; k < dataGridView1.Columns.Count; k++)
{
if (dataGridView1[k, i].Value != null)
{
table.AddCell(new Phrase(dataGridView1[k, i].Value.ToString()));
}
}
}
doc.Add(table);
Paragraph paragraphe1 = new Paragraph(" " + "Total items: " +quaq1.ToString());
paragraphe.Alignment = Element.ALIGN_LEFT;
doc.Add(paragraphe1);
Paragraph paragraphe2 = new Paragraph(" " + "Total Price: " + tot1.ToString());
paragraphe.Alignment = Element.ALIGN_LEFT;
doc.Add(paragraphe2);
doc.Close();
Rq: I'm using iTextSharp Assembly.

Related

Switch document renderer - Cannot draw elements on already flushed pages

According to this case's answer by Alexey, we can utilize different renderers with customized RootLayoutArea to achieve such layout behavior as below.
Here is the code:
public void ManipulatePdf(String dest)
{
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc, PageSize.A4);
doc.SetMargins(36, 36, 36, 36);
Paragraph p = new Paragraph();
p.SetBorder(new SolidBorder(0.5f));
for (int i = 1; i <= 500; i++)
{
p.Add(new Text(i + " "));
}
doc.Add(p);
RootLayoutArea endOfFullWidthContentArea = (RootLayoutArea)doc.GetRenderer().GetCurrentArea();
ExtendedDocumentRenderer renderer1 = new ExtendedDocumentRenderer(doc,
new RootLayoutArea(endOfFullWidthContentArea.GetPageNumber(), endOfFullWidthContentArea.GetBBox().Clone().SetWidth(200)));
doc.SetRightMargin(doc.GetRightMargin() + doc.GetPageEffectiveArea(PageSize.A4).GetWidth() - 200);
doc.SetRenderer(renderer1);
//The paragraph drawn in the left
Paragraph p1 = new Paragraph();
p1.SetBorder(new SolidBorder(0.5f));
for (int i = 1; i <= 500; i++)
{
p1.Add(new Text(i + " "));
}
doc.Add(p1);
ExtendedDocumentRenderer renderer2 = new ExtendedDocumentRenderer(doc,
new RootLayoutArea(endOfFullWidthContentArea.GetPageNumber(),
endOfFullWidthContentArea.GetBBox().Clone().MoveRight(200 + 20)
.SetWidth(endOfFullWidthContentArea.GetBBox().GetWidth() - 200 - 20)));
doc.SetRightMargin(36);
doc.SetLeftMargin(200 + 36 + 20);
doc.SetRenderer(renderer2);
Paragraph p2 = new Paragraph();
for (int i = 1; i <= 1000; i++)
{
p2.Add(new Text(i + " "));
}
doc.Add(p2);
//Compute which free area is lower in the document
RootLayoutArea areaColumn1 = (RootLayoutArea)renderer1.GetCurrentArea();
RootLayoutArea areaColumn2 = (RootLayoutArea)renderer2.GetCurrentArea();
RootLayoutArea downArea =
areaColumn1.GetPageNumber() > areaColumn2.GetPageNumber() ? areaColumn1 :
(areaColumn1.GetPageNumber() < areaColumn2.GetPageNumber() ? areaColumn2 :
(areaColumn1.GetBBox().GetTop() < areaColumn2.GetBBox().GetTop() ? areaColumn1 : areaColumn2));
doc.SetMargins(36, 36, 36, 36);
DocumentRenderer renderer3 = new ExtendedDocumentRenderer(doc,
new RootLayoutArea(downArea.GetPageNumber(), downArea.GetBBox().Clone().SetX(36).SetWidth(doc.GetPageEffectiveArea(PageSize.A4).GetWidth())));
doc.SetRenderer(renderer3);
Paragraph p3 = new Paragraph();
for (int i = 1; i <= 1000; i++)
{
p3.Add(new Text(i + " "));
}
doc.Add(p3);
doc.Close();
}
private class ExtendedDocumentRenderer : DocumentRenderer
{
public ExtendedDocumentRenderer(Document document, RootLayoutArea currentArea) : base(document)
{
this.currentArea = new RootLayoutArea(currentArea.GetPageNumber(), currentArea.GetBBox().Clone());
this.currentPageNumber = this.currentArea.GetPageNumber();
}
}
We can see that the Paragraph 1 in the left column spans two pages, and the Paragraph 2 spans three pages, under this scenario the code runs well.
But if we add more contents to Paragraph 1 and make it span 3 pages as following:
//The paragraph drawn in the left has more contents
Paragraph p1 = new Paragraph();
p1.SetBorder(new SolidBorder(0.5f));
for (int i = 1; i <= 800; i++)
{
p1.Add(new Text(i + " "));
}
doc.Add(p1);
When the Paragraph 2 is rendering, it throws the exception of "Cannot draw elements on already flushed pages". How to solve this problem? Thank you!
If you elements can span multiple pages then you need to apply immediateFlush=false setting of the DocumentRenderer which goes to its constructor.
You will need to modify your ExtendedDocumentRenderer custom implementation in the following way:
private class ExtendedDocumentRenderer : DocumentRenderer
{
public ExtendedDocumentRenderer(Document document, RootLayoutArea currentArea) : base(document, false)
{
this.currentArea = new RootLayoutArea(currentArea.GetPageNumber(), currentArea.GetBBox().Clone());
this.currentPageNumber = this.currentArea.GetPageNumber();
}
}
And then you will need to call Document#Flush whenever you are done with another document renderer. Essentially in your code sample that call needs to be done after adding each new element. Here is the full code:
Document doc = new Document(pdfDocument, PageSize.A4);
doc.SetMargins(36, 36, 36, 36);
Paragraph p = new Paragraph();
p.SetBorder(new SolidBorder(0.5f));
for (int i = 1; i <= 500; i++)
{
p.Add(new Text(i + " "));
}
doc.Add(p);
RootLayoutArea endOfFullWidthContentArea = (RootLayoutArea)doc.GetRenderer().GetCurrentArea();
ExtendedDocumentRenderer renderer1 = new ExtendedDocumentRenderer(doc,
new RootLayoutArea(endOfFullWidthContentArea.GetPageNumber(), endOfFullWidthContentArea.GetBBox().Clone().SetWidth(200)));
doc.SetRightMargin(doc.GetRightMargin() + doc.GetPageEffectiveArea(PageSize.A4).GetWidth() - 200);
doc.SetRenderer(renderer1);
//The paragraph drawn in the left
Paragraph p1 = new Paragraph();
p1.SetBorder(new SolidBorder(0.5f));
for (int i = 1; i <= 800; i++)
{
p1.Add(new Text(i + " "));
}
doc.Add(p1);
doc.Flush();
ExtendedDocumentRenderer renderer2 = new ExtendedDocumentRenderer(doc,
new RootLayoutArea(endOfFullWidthContentArea.GetPageNumber(),
endOfFullWidthContentArea.GetBBox().Clone().MoveRight(200 + 20)
.SetWidth(endOfFullWidthContentArea.GetBBox().GetWidth() - 200 - 20)));
doc.SetRightMargin(36);
doc.SetLeftMargin(200 + 36 + 20);
doc.SetRenderer(renderer2);
Paragraph p2 = new Paragraph();
for (int i = 1; i <= 1000; i++)
{
p2.Add(new Text(i + " "));
}
doc.Add(p2);
doc.Flush();
//Compute which free area is lower in the document
RootLayoutArea areaColumn1 = (RootLayoutArea)renderer1.GetCurrentArea();
RootLayoutArea areaColumn2 = (RootLayoutArea)renderer2.GetCurrentArea();
RootLayoutArea downArea =
areaColumn1.GetPageNumber() > areaColumn2.GetPageNumber() ? areaColumn1 :
(areaColumn1.GetPageNumber() < areaColumn2.GetPageNumber() ? areaColumn2 :
(areaColumn1.GetBBox().GetTop() < areaColumn2.GetBBox().GetTop() ? areaColumn1 : areaColumn2));
doc.SetMargins(36, 36, 36, 36);
DocumentRenderer renderer3 = new ExtendedDocumentRenderer(doc,
new RootLayoutArea(downArea.GetPageNumber(), downArea.GetBBox().Clone().SetX(36).SetWidth(doc.GetPageEffectiveArea(PageSize.A4).GetWidth())));
doc.SetRenderer(renderer3);
Paragraph p3 = new Paragraph();
for (int i = 1; i <= 1000; i++)
{
p3.Add(new Text(i + " "));
}
doc.Add(p3);
doc.Flush();
doc.Close();
After stepping on the pit before, you can try calling three parameter constructors and setting immediateflush to false.
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
// setting immediateflush to false
Document doc = new Document(pdfDoc, PageSize.A4, false);

Auto Create Table On Next Line in ITextSharp

For Example in this Image , I have four Dates of record , may be in next PDF will have 10 dates of record then how to set maximum five number of Dates Record show in a First-Table and next five dates show in Second-Table just after First-Table (Second Table Auto Generate) in iTextSharp
for (int c = 4; c < dt.Columns.Count; c++)
{
cell = new PdfPCell(new Phrase(dt.Columns[c].ToString(), fntMainHeading));
cell.Padding = 2;
cell.BorderColor = new Color(217, 217, 217);
table.AddCell(cell);
}
for (int i = 0; i < dt.Rows.Count; i++)
{
if (ServiceCode == 0 || ServiceCode != Convert.ToInt32(dt.Rows[i]["ServiceCode"]))
{
ServiceCode = Convert.ToInt32(dt.Rows[i]["ServiceCode"]);
cell = new PdfPCell(new Phrase(Convert.ToString(dt.Rows[i]["ServiceName"]), fntHeading));
cell.Padding = 2;
cell.Colspan = col;
cell.BorderColor = new Color(217, 217, 217);
table.AddCell(cell);
}
for (int j = 4; j < dt.Columns.Count; j++)
{
cell = new PdfPCell(new Phrase(Convert.ToString(dt.Rows[i][j]), fntNormalText));
cell.Padding = 2;
cell.BorderColor = new Color(217, 217, 217);
table.AddCell(cell);
}
}
table.SpacingBefore = 10;
table.SpacingAfter = 10;
doc.Add(table);
}

Repeat Heading to table in pdf

I am using the Itextsharp PDF tool to generate PDF using asp.net and C# , In that in one PDFPtable the last row data is repeating on next page means part of a table forwarded to next page. so want to show header for that Table on next page.
This is my code.
Document doc = new Document(iTextSharp.text.PageSize.A4.Rotate(), 10, 10, 20, 10);
string pdfFilePath = Server.MapPath(".") + "/pdf/myPdf" + Guid.NewGuid().ToString("N") + ".pdf";
try
{
//Create Document class object and set its size to letter and give space left, right, Top, Bottom Margin
FileStream fs = new FileStream(pdfFilePath, FileMode.Create);
//
PdfWriter wri = PdfWriter.GetInstance(doc, fs);
//Header Section
string strImagePath = Server.MapPath("Images");
string strReportName = oReportDTO.strReportName + " " + oReportDTO.oDateRange.FromDate.ToString(DateFormat);
Chunk headerchunk = new Chunk(strReportName, new Font(1, 8.0f));
HeaderFooter oHeader = new HeaderFooter(new Phrase(headerchunk), false);
oHeader.Border = Rectangle.NO_BORDER;
oHeader.Alignment = 1;
doc.Header = oHeader;
//Footer Section
string name ="Logged in as : " +currentLoggedInUser.UserName + new string(' ',70)+ "Page Number : " + doc.PageNumber;
Chunk Footerchunk1 = new Chunk(name, new Font(1, 5.0f));
HeaderFooter oFooter1 = new HeaderFooter(new Phrase(Footerchunk1), true);
oFooter1.Border = Rectangle.NO_BORDER;
oFooter1.Alignment = 1;
doc.Footer = oFooter1;
iTextSharp.text.Image imgFooter = iTextSharp.text.Image.GetInstance(System.Drawing.Image.FromFile(strImagePath + "/TransRisk Logo168x97.png"), System.Drawing.Imaging.ImageFormat.Jpeg);
imgFooter.ScaleAbsolute(80, 50);
Chunk footerchunk = new Chunk(imgFooter, 260.0f, 0.0f);
HeaderFooter oFooter = new HeaderFooter(new Phrase(name),new Phrase(footerchunk));
oFooter.Border =Rectangle.NO_BORDER;
doc.Footer = oFooter;
doc.Open();//Open Document to write
Font font8 = FontFactory.GetFont("ARIAL", 7);
HtmlTable dt = customMatrixReport;
if (dt.Rows.Count > 0)
{
//Craete instance of the pdf table and set the number of column in that table
int startColumnPosition = 1;
int endColumnPosition = 13;//End Column number in Pdf Page
int NoOfReports = Convert.ToInt32(Math.Ceiling((decimal)(dt.Rows[0].Cells.Count - 1) / endColumnPosition));//Count How many Pages to show
int pageRowCount = 0;
List<PdfPCell> lstHeaderCells = new List<PdfPCell>();
PdfPTable oPdfTable = null;
PdfPCell oPdfPCell = null;
for (int report = 1; report <= NoOfReports; ++report)
{
doc.Add(oHeader);
//ColumnText.ShowTextAligned(
int noOfColumns = -1;
if (endColumnPosition > dt.Rows[0].Cells.Count - 1) { endColumnPosition = dt.Rows[0].Cells.Count - 1; noOfColumns = (endColumnPosition - startColumnPosition) + 2; oPdfTable = new PdfPTable(noOfColumns); }
else
{
oPdfTable = new PdfPTable(14);
//Widths Count
noOfColumns = 14;
}
oPdfTable.TotalWidth = 650f;
List<float> lstwidths = new List<float>();
lstwidths.Add(100f);
for (int i = 2; i <= noOfColumns; ++i)
{
lstwidths.Add(80f);
}
oPdfTable.SetTotalWidth(lstwidths.ToArray());
pageRowCount = 0;
for (int rows = 0; rows < dt.Rows.Count; rows++)
{
//PageRowCount
pageRowCount = pageRowCount + 1;
//Description celll
if (rows == 0 )
{
//Background color for table header
oPdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows].Cells[0].InnerText, new Font(1, 8.0f, 1, Color.WHITE))));
oPdfPCell.BackgroundColor = new Color(118, 147, 199);
oPdfTable.AddCell(oPdfPCell);
}
else
{
//background color for Table cells
oPdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows].Cells[0].InnerText,new Font(1, 8.0f))));
oPdfPCell.BackgroundColor = new Color(232, 237, 255);
oPdfTable.AddCell(oPdfPCell);
}
//for header cel
if (rows == 0)
{
lstHeaderCells.Add(oPdfPCell);
}
for (int column = startColumnPosition; column <= endColumnPosition; column++)
{
if (rows == 0)
{
oPdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows].Cells[column].InnerText, new Font(1, 8.0f, 1, Color.WHITE))));
oPdfPCell.BackgroundColor = new Color(118, 147, 199);
oPdfTable.AddCell(oPdfPCell);
}
else
{
oPdfPCell = new PdfPCell(new Phrase(new Chunk(dt.Rows[rows].Cells[column].InnerText, new Font(1, 8.0f))));
oPdfPCell.BackgroundColor = new Color(232, 237, 255);
oPdfPCell.Column.Alignment = 2;
oPdfTable.AddCell(oPdfPCell);
}
if (rows == 0)
{
lstHeaderCells.Add(oPdfPCell);
}
}
if (pageRowCount >= 40 && rows != (dt.Rows.Count - 1))
{
pageRowCount = 0; doc.Add(oPdfTable); doc.NewPage(); doc.Add(oHeader); oPdfTable = new PdfPTable(noOfColumns); oPdfTable.SetTotalWidth(lstwidths.ToArray()); foreach (PdfPCell oHeaderCell in lstHeaderCells) { oPdfTable.AddCell(oHeaderCell); }
}
}
startColumnPosition = endColumnPosition + 1;
endColumnPosition = endColumnPosition + 13;
oPdfTable.SpacingBefore = 10;
oPdfTable.SpacingAfter = 10;
doc.Add(oPdfTable);
//doc.NewPage();
}
}
else
doc.Add(oHeader);
}
finally
{
doc.Close();
}
help me..
Change this line-
if (endColumnPosition > dt.Rows[0].Cells.Count - 1) { endColumnPosition = dt.Rows[0].Cells.Count - 1; noOfColumns = (endColumnPosition - startColumnPosition) + 2; oPdfTable = new PdfPTable(noOfColumns); }
To this-
if (endColumnPosition > dt.Rows[0].Cells.Count - 1) { endColumnPosition = dt.Rows[0].Cells.Count - 1; noOfColumns = (endColumnPosition - startColumnPosition) + 2; oPdfTable = new PdfPTable(noOfColumns); oPdfTable.HeaderRows = 1;}
After this line-
oPdfTable = new PdfPTable(14);
Add this-
oPdfTable.HeaderRows = 1;
Change this line-
pageRowCount = 0; doc.Add(oPdfTable); doc.NewPage(); doc.Add(oHeader); oPdfTable = new PdfPTable(noOfColumns); oPdfTable.SetTotalWidth(lstwidths.ToArray()); foreach (PdfPCell oHeaderCell in lstHeaderCells) { oPdfTable.AddCell(oHeaderCell); }
To this-
pageRowCount = 0; doc.Add(oPdfTable); doc.NewPage(); doc.Add(oHeader); oPdfTable = new PdfPTable(noOfColumns); oPdfTable.HeaderRows = 1; oPdfTable.SetTotalWidth(lstwidths.ToArray()); foreach (PdfPCell oHeaderCell in lstHeaderCells) { oPdfTable.AddCell(oHeaderCell); }

C# Export to PDF and ONLY add Columns, not include buttons

I've made a Password manager app.
Im trying to only export Name, Username, Password and Chaged date rows.
But for now, it also export the column buttons.
Any hints?
When I Export with this code:
private void exportToPDFToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "Pdf File |*.pdf";
if (sfd.ShowDialog() == DialogResult.OK)
{
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(sfd.FileName, FileMode.Create));
doc.Open();//Open Document to write
Paragraph paragraph = new Paragraph("data Exported From PassVault!\n\n");
PdfPTable table = new PdfPTable(dgvPasswords.Columns.Count);
//Add the headers
for (int j = 0; j < dgvPasswords.Columns.Count; j++)
{
table.AddCell(new Phrase(dgvPasswords.Columns[j].HeaderText));
}
//Flag the first row as header
table.HeaderRows = 1;
//Add the actual rows from the DGV to the table
for (int i = 0; i < dgvPasswords.Columns.Count; i++)
{
for (int k = 0; k < dgvPasswords.Rows.Count; k++)
{
if (dgvPasswords[k, i].Value != null)
{
table.AddCell(new Phrase(dgvPasswords[k, i].Value.ToString()));
}
}
}
doc.Add(paragraph);
doc.Add(table);
doc.Close();
// MessageBox.Show("Exported as Export-List.pdf to \n\n" + Application.StartupPath + " /Export-List.pdf", "PDF Exported", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
It also includes the column Copy and Column New button..
Made It perfect, but now Im not sure where I did miss.
How do I only export: Name, Username, Password and Changed Date from DgvPassword?
You are attempting to access outside the bounds of the dgvPasswords array due to using the incorrect upper limit for k
for (int k = 0; k < dgvPasswords.Columns.Count; k++)
{
should read
for (int k = 0; k < dgvPasswords.Rows.Count; k++)
{

Grouping elements while exporting dataGridView to PDF using iTextSharp

I'm trying to export my datagridview to PDF however while doing that I want to group the rows which have the same Group name.
The code I use to export to pdf is at the below;
private void PrintReport_Click(object sender, EventArgs e)
{
try
{
//create iTextSharp table
PdfPTable pdfTable = new PdfPTable(dataGridView1.ColumnCount);
pdfTable.DefaultCell.Padding = 3;
pdfTable.WidthPercentage = 30;
pdfTable.HorizontalAlignment = Element.ALIGN_LEFT;
pdfTable.DefaultCell.BorderWidth = 1;
//Adding Header row
PdfPCell cell = new PdfPCell(new Phrase("Report"));
cell.Colspan = 11;
cell.BackgroundColor = new iTextSharp.text.Color(50, 50, 120);
cell.HorizontalAlignment = 1;
pdfTable.TotalWidth = 1200f;
pdfTable.LockedWidth = true;
pdfTable.AddCell(cell);
pdfTable.AddCell("Group");
pdfTable.AddCell("Numara");
pdfTable.AddCell("Müşteri ID");
pdfTable.AddCell("Tanım");
pdfTable.AddCell("IP Adresi");
pdfTable.AddCell("Kullanıcı");
pdfTable.AddCell("Şifre");
pdfTable.AddCell("Domain");
pdfTable.AddCell("2.IP");
pdfTable.AddCell("2.Kullanıcı");
pdfTable.AddCell("2.Kullanıcı Şifre");
//Adding DataRow
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
if (dataGridView1.Rows[i].Cells[j].Value != null)
{
if (j == 6|| j == 10)
{
pdfTable.AddCell("*****");
}
else if(j==0)
{
pdfTable.AddCell(dataGridView1.Rows[i].Cells[6].Value.ToString());
}
else if(j==6)
{
pdfTable.AddCell(dataGridView1.Rows[i].Cells[0].Value.ToString());
}
else
{
pdfTable.AddCell(dataGridView1.Rows[i].Cells[j - 1].Value.ToString());
}
}
else
{
pdfTable.AddCell(" ");
}
}
}
//pdfTable.AddCell(cells.Value.ToString());
//Exporting to PDF
string folderPath = "C:\\PDFs\\";
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
using (FileStream stream = new FileStream(folderPath + "Rapor.pdf", FileMode.Create))
{
Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
PdfWriter.GetInstance(pdfDoc, stream);
pdfDoc.Open();
pdfDoc.Add(pdfTable);
pdfDoc.Close();
stream.Close();
}
MessageBox.Show("C:\\PDFs uzantısına rapor kaydedildi!");
}
catch (Exception msg)
{
MessageBox.Show(msg.Message, "Error");
}
}
Code works pretty well, it exports the datagridview to pdf file but it does not work the way I want, It does not group columns by 'Group Name'
I'm stuck in this problem any help would be appreciated.
Can you just sort the results, create a pdfTable for each 'group' that has data?
I have solved the problem with a little trick, I have listed all the groups in a list named 'testlist' So I can manage the handle the sutiation within 1 pdfTable
There is the code snippet:
for (int element = 0; element < testList.Count;element++ )
{
string name = testList.ElementAt(element).ToString();
PdfPCell cell1 = new PdfPCell(new Phrase(name));
cell1.BackgroundColor = new iTextSharp.text.Color(160, 160, 210);
cell1.Colspan = 11;
cell1.HorizontalAlignment = 1;
pdfTable.AddCell(cell1);
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
if (dataGridView1.Rows[i].Cells[j].Value != null)
{
if(dataGridView1.Rows[i].Cells[6].Value.ToString() == name.ToString())
{
if (j == 6 || j == 10)
{
pdfTable.AddCell("*****");
}
else if (j == 0)
{
pdfTable.AddCell(dataGridView1.Rows[i].Cells[6].Value.ToString());
}
else if (j == 6)
{
pdfTable.AddCell(dataGridView1.Rows[i].Cells[0].Value.ToString());
}
else
{
pdfTable.AddCell(dataGridView1.Rows[i].Cells[j - 1].Value.ToString());
}
}
}
else
{
pdfTable.AddCell(" ");
}
}
}
}

Categories

Resources