private byte[] CreatePDF(string html) { Document document = new Document(); document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate()); document.SetMargins(50, 50, 10, 40); var output = new MemoryStream(); var writer = PdfWriter.GetInstance(document, output); writer.PageEvent = new ImpactAnalysisHeaderHandler(); document.Open(); PdfPTable frontPage = CreateFrontPage(); document.Add(frontPage); iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet(); var elem = HTMLWorker.ParseToList(new StringReader(html), styles); foreach (IElement item in elem) { if (item is PdfPTable) { PdfPTable t = item as PdfPTable; if (t != null) { t.SplitLate = false; t.KeepTogether = true; PdfPHelper.FixTables(t); PdfPHelper.FixMainRowsPadding(t); document.Add(t); } } } document.Close(); return(output.ToArray()); }
private PdfPTable CreateFrontPage() { PdfPTable table = new PdfPTable(2); table.SetWidths(new float[] { 25, 75 }); table.WidthPercentage = 100; table.AddCell(new PdfPCell() { Phrase = new Phrase(GlobalStringResource.ForOfficialUseOnly, FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 20)), Colspan = 2, Border = 0, PaddingTop = 70 }); table.AddCell( new PdfPCell() { Phrase = new Phrase("Impact Analysis Report", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 36)), Colspan = 2, Border = 0, PaddingLeft = 0, PaddingBottom = 150 }); table.AddCell( PdfPHelper.CreatePaddingCell() ); table.AddCell( PdfPHelper.CreatePaddingCell() ); table.AddCell( PdfPHelper.CreatePlainCell("Agenda", BaseColor.LIGHT_GRAY) ); table.AddCell( PdfPHelper.CreatePlainCell(this.filter.AgendaFilterText) ); table.AddCell( PdfPHelper.CreatePlainCell("Business Policy", BaseColor.LIGHT_GRAY) ); table.AddCell( PdfPHelper.CreatePlainCell(this.filter.PolicyFilterText) ); table.AddCell( PdfPHelper.CreatePlainCell("Business Rule", BaseColor.LIGHT_GRAY) ); table.AddCell( PdfPHelper.CreatePlainCell(this.filter.RuleFilterText) ); table.AddCell( PdfPHelper.CreatePlainCell("Process", BaseColor.LIGHT_GRAY) ); table.AddCell( PdfPHelper.CreatePlainCell(this.filter.ProcessFilterText) ); table.AddCell( PdfPHelper.CreatePlainCell("Application", BaseColor.LIGHT_GRAY) ); table.AddCell( PdfPHelper.CreatePlainCell(this.filter.ApplicationFilterText) ); table.AddCell( PdfPHelper.CreatePlainCell("Sub-Process", BaseColor.LIGHT_GRAY) ); table.AddCell( PdfPHelper.CreatePlainCell(this.filter.SubProcessFilterText) ); table.AddCell( PdfPHelper.CreatePlainCell("Module", BaseColor.LIGHT_GRAY) ); table.AddCell( PdfPHelper.CreatePlainCell(this.filter.ModuleFilterText) ); table.AddCell( new PdfPCell() { Border = 0, PaddingBottom = 100, Colspan = 2 } ); return(table); }