我有一个程序,当单击Button1时,应该使用FileSavedialog生成pdf文件。
工作正常..
我还有一个表,该表应该添加到文档中。
问题是我在点击Button1之前每次更新该表(添加行)。
创建并保存文档后,我将从表中删除所有行。
在第一次单击Button1之前,它总是添加第一个表,而不是添加包含其他行的表:
private void Button1_Click(object sender, EventArgs e)
{
Dialog.ShowDialog();
FileStream fr = new FileStream(Dialog.FileName+".pdf", FileMode.Create, FileAccess.Write, FileShare.None);
Document doc = new Document(rec, 40, 40, 30, 30);
PdfWriter pdfwriter = PdfWriter.GetInstance(doc, fr);
pdfwriter.PageEvent = new ITextEvents();
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
doc.Open();
doc.Add(table);
doc.Close();
fr.Close();
}
以下是Button2_Click
的代码private void Button2_Click(object sender,EventArgs e)
{
//declaring cells and row|
//getting values
table.Rows.Add(row);
}
我希望你能理解我。
更新:: 当我创建多个文件时,例如1.pdf 2.pdf 3.pdf .. 1.pdf正常,2.pdf有1.pdf和3.pdf的行有2.pdf应该有的行..
这是Button2_Click()
的代码table3.WidthPercentage = 100;
PdfPCell RedBr1 = new PdfPCell();
RedBr1.AddElement(new Paragraph(brFakture.ToString()));
brFakture++;
try
{
PdfPCell Naziv1 = new PdfPCell();
Naziv1.AddElement(new Paragraph(NazivTb.Text));
//kolicina
PdfPCell Kol1 = new PdfPCell();
double kolicina = Convert.ToDouble(KolTb.Text);
Kol1.AddElement(new Paragraph(kolicina.ToString("F")));
//jedinica mere
PdfPCell Jm1 = new PdfPCell();
Jm1.AddElement(new Paragraph(JmTb.Text));
//cena po jedinici
PdfPCell cenaPoJedinici1 = new PdfPCell();
double cena = Convert.ToDouble(CenaTb.Text);
cenaPoJedinici1.AddElement(new Paragraph(cena.ToString("F")));
double naknada = cena * kolicina;
PdfPCell UkupnaNaknada1 = new PdfPCell();
UkupnaNaknada1.AddElement(new Paragraph(naknada.ToString("F")));
SVE_UKUPNO += naknada;
table3.SetWidths(new float[6] { 10, 35, 7, 7, 18, 18 });
PdfPCell[] nizCelija1 = new PdfPCell[6] { RedBr1, Naziv1, Kol1, Jm1, cenaPoJedinici1, UkupnaNaknada1 };
PdfPRow pocetakTabele1 = new PdfPRow(nizCelija1);
table3.Rows.Add(pocetakTabele1);
}
catch (Exception)
{
MessageBox.Show("Uneti podatak nije broj!");
}