Как экспортировать данные listview в pdf в C# с помощью itextsharp
Hi. I want to export data in Listview in C# project using iTextSharp. I am beginner in C#, Please help me to solve this problem. The source code is as following:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; namespace Loan_Calculator { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.listView1.ColumnWidthChanging += new ColumnWidthChangingEventHandler(listView1_ColumnWidthChanging); } void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e) { Console.Write("Column Resizing"); e.NewWidth = this.listView1.Columns[e.ColumnIndex].Width; e.Cancel = true; } double kreditmeblegi; double illikfaiz; double fm; double value1; double ay; double il; double ayliqodenis; double umumiodenis; double esasborc; double faiz; double qaliqmebleg; double odenilenfaiz; int nomre; private void button1_Click(object sender, EventArgs e) { if (comboBox2.Text == "ay") { kreditmeblegi = Convert.ToDouble(textBox1.Text); illikfaiz = Convert.ToDouble(textBox2.Text); ay = Convert.ToDouble(textBox3.Text); fm = illikfaiz / (12 * 100); value1 = 1 - (1 / Math.Pow((1 + fm), ay)); ayliqodenis = (kreditmeblegi * fm) / value1; umumiodenis = ayliqodenis * ay; odenilenfaiz = umumiodenis - kreditmeblegi; DateTime date = this.dateTimePicker1.Value.Date; DateTime nyear = new DateTime(); string format = "dd / MM / yyyy"; qaliqmebleg = kreditmeblegi; for (int i = 1; i <= ay; i++) { nomre = nomre + 1; ListViewItem lvi = new ListViewItem(nomre.ToString()); nyear = date.AddMonths(i); lvi.SubItems.Add(nyear.ToString(format)); lvi.SubItems.Add(ayliqodenis.ToString("N2")); faiz = qaliqmebleg * fm; esasborc = ayliqodenis - faiz; qaliqmebleg = qaliqmebleg - esasborc; lvi.SubItems.Add(esasborc.ToString("N2")); lvi.SubItems.Add(faiz.ToString("N2")); lvi.SubItems.Add(qaliqmebleg.ToString("N2")); listView1.Items.Add(lvi); } button1.Enabled = false; } else { kreditmeblegi = Convert.ToDouble(textBox1.Text); illikfaiz = Convert.ToDouble(textBox2.Text); il = Convert.ToDouble(textBox3.Text) * 12; fm = illikfaiz / (12 * 100); value1 = 1 - (1 / Math.Pow((1 + fm), il)); ayliqodenis = (kreditmeblegi * fm) / value1; umumiodenis = ayliqodenis * il; odenilenfaiz = umumiodenis - kreditmeblegi; DateTime date = this.dateTimePicker1.Value.Date; DateTime nyear = new DateTime(); string format = "dd / MM / yyyy"; qaliqmebleg = kreditmeblegi; for (int j = 1; j <= il; j++) { nomre = nomre + 1; ListViewItem lvi = new ListViewItem(nomre.ToString()); nyear = date.AddMonths(j); lvi.SubItems.Add(nyear.ToString(format)); lvi.SubItems.Add(ayliqodenis.ToString("N2")); faiz = qaliqmebleg * fm; esasborc = ayliqodenis - faiz; qaliqmebleg = qaliqmebleg - esasborc; lvi.SubItems.Add(esasborc.ToString("N2")); lvi.SubItems.Add(faiz.ToString("N2")); lvi.SubItems.Add(qaliqmebleg.ToString("N2")); listView1.Items.Add(lvi); } button1.Enabled = false; } if (Convert.ToDouble(textBox1.Text) == 0 || Convert.ToDouble(textBox2.Text) == 0 || Convert.ToDouble(textBox3.Text) == 0) { MessageBox.Show("Sıfır daxil etmək olmaz!"); button1.Enabled = true; listView1.Items.Clear(); } label9.Text = ayliqodenis.ToString("N2") + " " + comboBox1.Text; label10.Text = umumiodenis.ToString("N2") + " " + comboBox1.Text; label12.Text = odenilenfaiz.ToString("N2") + " " + comboBox1.Text; } private void Form1_Load(object sender, EventArgs e) { } private void ExporttoPDFToolStripMenuItem_Click(object sender, EventArgs e) { FileStream fs = new FileStream("Loan Calculator.pdf", FileMode.Create, FileAccess.Write, FileShare.None); Document doc = new Document(PageSize.A4); PdfWriter writer = PdfWriter.GetInstance(doc, fs); doc.Open(); doc.Add(new Paragraph("Hello World")); doc.Close(); } } }
Что я уже пробовал:
Я могу экспортировать предложение Hello world в PDF, но я не знаю, как экспортировать Listview в PDF.