public string GetFormattedText() { var dl = new DataTable(); dl.Columns.Add("Left"); dl.Columns.Add("Right"); Pdf = new PdfCreator(StyleSet) { Increment = Schritt, BackColor = BackColor, TableBorderColor = TableBorderColor }; Pdf.SetDocInfo(Title, Subject, Author); Pdf.SetHeader(Author, "Header", LogoImagePath); Pdf.SetFooter($"{DateTime.Now:dd.MM.yyyy}\t<<page>>"); // Pdf.BackgroundImagePath = BackgroundImagePath; Pdf.CreateTocSection("Inhaltsverzeichnis"); Pdf.CreateContentSection(); for (var i = 0; i < StructuredText.TextItems.Count; i++) { var ti = StructuredText.TextItems[i]; var content = ti.Content.Replace("??br??", "\r\n"); switch (ti.LogicalType) { case TextItemType.H1: Pdf.AddParagraph(content, "Heading1"); break; case TextItemType.H2: Pdf.AddParagraph(content, "Heading2"); break; case TextItemType.H3: Pdf.AddParagraph(content, "Heading3"); break; case TextItemType.H4: Pdf.AddParagraph(content, "Heading4"); break; case TextItemType.P: Pdf.AddParagraph(content, "Normal"); break; case TextItemType.ListItem: Pdf.AddParagraph(content, "Bullet1"); break; case TextItemType.DefinitionListLine: var isfirst = false; var islast = false; if (i == 0) { isfirst = true; } else if (i == StructuredText.TextItems.Count - 1) { islast = true; } else { var itemBefore = StructuredText.TextItems[i - 1]; if (itemBefore.LogicalType != TextItemType.DefinitionListLine) { isfirst = true; } var itemAfter = StructuredText.TextItems[i + 1]; if (itemAfter.LogicalType != TextItemType.DefinitionListLine) { islast = true; } } if (isfirst) { dl.Clear(); } var dlitem = (DefinitionListTextItem)ti; var row = dl.Rows.Add(); row["Left"] = dlitem.Content; row["Right"] = dlitem.Content2; if (islast) { Pdf.AddDefinitionList(dl, "Normal", "Normal"); } break; case TextItemType.Xml: case TextItemType.Code: Pdf.AddParagraph(content, "Code"); break; case TextItemType.Table: GetTable((TableTextItem)ti); break; default: break; } } return(null); }
private void CreateFile(string fileName, bool landscape = false) { var code = FileHelper.GetTextResource("code1.txt"); if (File.Exists(fileName)) { File.Delete(fileName); } var styleset = new DefaultStyleSet(); if (landscape) { LoadLandScapeSettings(styleset); } var pdf = new PdfCreator(styleset); pdf.SetDocInfo("Test", "Susbject", "Author"); pdf.SetHeader("Kopfzeile", "Header1", @"\\192.168.10.121\softwarestore$\Logos\Intern\logo_bre.png"); pdf.SetFooter("Footer \t<<page>> / <<pages>>"); pdf.CreateTocSection("Inhaltsverzeichnis"); pdf.CreateContentSection(); pdf.AddParagraph("Überschrift 1", "Heading1"); pdf.AddParagraph(TestHelper.Masstext1, "Normal"); pdf.AddParagraph(code, "Code"); pdf.AddParagraph(TestHelper.Masstext1, "Normal"); pdf.AddDefinitionList(TestHelper.GetDefinitionList(), "Normal", "Normal"); pdf.AddParagraph(TestHelper.Masstext1, "Normal"); pdf.AddTable(TestHelper.GetDataTable(), "Tabellenüberschrift", "NoHeading1", "some additional info", "Details", pdf.Width); pdf.AddTableFrame(TestHelper.GetDataTable(), "Tabellenüberschrift Frame", "NoHeading1", "some additional info", "Details", pdf.Width / 2); pdf.AddTableFrame(TestHelper.GetDataTable(), "Tabellenüberschrift Frame", "NoHeading1", null, "Details", pdf.Width / 2); pdf.AddParagraph("Überschrift 2", "Heading1"); pdf.AddParagraph(TestHelper.Masstext1, "Normal"); pdf.AddParagraph("Überschrift 2-1", "Heading2"); pdf.AddParagraph(TestHelper.Masstext1, "Normal"); pdf.AddImage(@"\\192.168.10.121\softwarestore$\Logos\Intern\logo_bre.png", 150, 50); pdf.AddParagraph("Überschrift 2-2", "Heading2"); pdf.AddParagraph(TestHelper.Masstext1, "Normal"); pdf.AddParagraph("Aufzählung 1", "Bullet1"); pdf.AddParagraph("Aufzählung 2", "Bullet1"); pdf.AddParagraph("Aufzählung 3", "Bullet1"); pdf.AddParagraph("Aufzählung 4", "Bullet1"); pdf.AddParagraph(TestHelper.Masstext1, "Normal"); pdf.AddParagraph(code, "Code"); pdf.AddParagraph(TestHelper.Masstext1, "Normal"); pdf.RenderToPdf(fileName, false); Assert.IsTrue(File.Exists(fileName)); TestHelper.OpenFile(fileName); }