private Document GeneratePDF(string use) { List <Bottles> listBottle = new List <Bottles>(); //check which order by is selected, select the correct list depending on that if (radColor.Checked) { listBottle = Bottles.OrderByColor(); } else if (radCountry.Checked) { listBottle = Bottles.OrderByCountry(); } else if (radManufacturer.Checked) { listBottle = Bottles.OrderByManufacturer(); } else if (radVariety.Checked) { listBottle = Bottles.OrderByVarietal(); } else if (txtResearch.Text != "") { listBottle = Bottles.ResearchByKeyword(txtResearch.Text); } //if no ordering, select all bottles as they are in DB else { listBottle = Bottles.ShowAllBottles(); } string jour = DateTime.Today.Day.ToString() + "." + DateTime.Today.Month.ToString() + "." + DateTime.Today.Year.ToString(); // Must have write permissions to the path folder PdfWriter writer; if (use == "def") { writer = new PdfWriter("C:\\ListeBouteilles_" + jour + ".pdf"); } else { writer = new PdfWriter("C:\\temp\\list" + jour + ".pdf"); } //it is necessary to specify, because the class PdfDocument exist in both iText and Spire iText.Kernel.Pdf.PdfDocument pdf = new iText.Kernel.Pdf.PdfDocument(writer); Document document = new Document(pdf); Paragraph header = new Paragraph("Liste de bouteilles stockées") .SetTextAlignment(TextAlignment.CENTER) .SetFontSize(14); document.Add(header); Table table = CreateTable(listBottle); document.Add(table); document.Close(); return(document); }
/** * method to order the list by country */ private void radCountry_Click(object sender, EventArgs e) { lstBottle = Bottles.OrderByCountry(); // method to reload the data, specifying the data to use LoadData(lstBottle); }