private string PrintPosseListToFile(int p) { var fn = tfh.get("pdf"); using (MemoryStream myMemoryStream = new MemoryStream()) { Document document = PdfPages.get(); PdfWriter w = PdfWriter.GetInstance(document, new FileStream(fn, FileMode.Create)); w.PageEvent = new PdfHeaderFooter($"Posse #{p}", Global.CurrentMatch.ToString()); document.Open(); Font fnt = new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD); PdfPTable s = new PdfPTable(6); s.DefaultCell.Border = 0; s.HeaderRows = 1; s.WidthPercentage = 100; int[] pw2 = { 10, 10, 20, 20, 20, 20 }; s.SetWidths(pw2); PdfPCell[] hc = new PdfPCell[] { new PdfPCell(new Phrase(new Chunk("RO-CH", fnt))) { Border = 0 }, new PdfPCell(new Phrase(new Chunk("RO-DEP", fnt))) { Border = 0 }, new PdfPCell(new Phrase(new Chunk("Surname", fnt))) { Border = 0 }, new PdfPCell(new Phrase(new Chunk("First Name", fnt))) { Border = 0 }, new PdfPCell(new Phrase(new Chunk("Nick name", fnt))) { Border = 0 }, new PdfPCell(new Phrase(new Chunk("Weapon class", fnt))) { Border = 0 } }; s.Rows.Add(new PdfPRow(hc)); fnt = new Font(Font.FontFamily.HELVETICA, 12f, Font.NORMAL); var mp_list = _ctx.MatchParticipations.Include("Shooter").Where(x => (x.MatchID == Global.CurrentMatch.MatchID && x.Posse == p)).ToList(); foreach (MatchParticipation mp in mp_list) { PdfPCell[] lc = new PdfPCell[] { new PdfPCell(new Phrase(new Chunk("", fnt))), new PdfPCell(new Phrase(new Chunk("", fnt))), new PdfPCell(new Phrase(new Chunk(mp.Shooter.Surname, fnt))), new PdfPCell(new Phrase(new Chunk(mp.Shooter.FirstName, fnt))), new PdfPCell(new Phrase(new Chunk(mp.Shooter.Nickname, fnt))), new PdfPCell(new Phrase(new Chunk(mp.Category, fnt))) }; s.Rows.Add(new PdfPRow(lc)); } document.Add(s); document.Close(); return(fn); } }