/// <summary> /// Make table of given contacts collection and writes it into PDF file. Writes only header if the collection is empty /// </summary> /// <param name="document"></param> /// <param name="contacts"></param> private static void processContactsToBandExport(Document document, ArrayList contacts) { PdfFont font = PdfFontFactory.CreateFont(StandardFonts.HELVETICA); PdfFont bold = PdfFontFactory.CreateFont(StandardFonts.HELVETICA_BOLD); //set number of table columns and their width relative to each other (that works weird, changing values has no affection) Table table = new Table(new float[] { 1, 1, 1, 1 }); //table width related to page table.SetWidth(UnitValue.CreatePercentValue(100)); //process header string headerLine = "Jméno, Funkce, Telefon, Email"; process(table, headerLine, bold, true); if (contacts.Count != 0) { foreach (BandContact contact in contacts) { string line; string phone; string email; if (Regex.IsMatch(contact.phone, @"^(\d{9}|\+\d{12})$")) { phone = contact.phone; } else { phone = "NIL"; } if (contact.email.Count() > 3) { email = contact.email; } else { email = "NIL"; } line = string.Format("{0}, {1}, {2}, {3}", contact.fName + contact.lName, contact.function, phone, email); //process data rows into table process(table, line, font, false); } } document.Add(table); }