public static void CreateHtml() { // Set a path to our HTML document. string htmlPath = @"Result.html"; // Let's create a simple HTML document. DocumentCore dc = new DocumentCore(); //DocumentCore.Serial = "put your serial here"; // Add new section. Section section = new Section(dc); dc.Sections.Add(section); // Add two paragraphs using different ways: // Way 1: Add 1st paragraph. Paragraph par1 = new Paragraph(dc); par1.ParagraphFormat.Alignment = HorizontalAlignment.Center; section.Blocks.Add(par1); // Let's create a characterformat for text in the 1st paragraph. CharacterFormat cf = new CharacterFormat() { FontName = "Verdana", Size = 16, FontColor = Color.Orange }; Run text1 = new Run(dc, "This is a first line in 1st paragraph!"); text1.CharacterFormat = cf; par1.Inlines.Add(text1); // Let's add a line break into our paragraph. par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); Run text2 = text1.Clone(); text2.Text = "Let's type a second line."; par1.Inlines.Add(text2); // Way 2 (easy): Add 2nd paragraph using ContentRange. dc.Content.End.Insert("\nThis is a first line in 2nd paragraph.", new CharacterFormat() { Size = 25, FontColor = Color.Blue, Bold = true }); SpecialCharacter lBr = new SpecialCharacter(dc, SpecialCharacterType.LineBreak); dc.Content.End.Insert(lBr.Content); dc.Content.End.Insert("This is a second line.", new CharacterFormat() { Size = 20, FontColor = Color.DarkGreen, UnderlineStyle = UnderlineType.Single }); // Save HTML document to a file. dc.Save(htmlPath, new HtmlFixedSaveOptions()); ShowResult(htmlPath); }
/// <summary> /// Creates a new PDF document using DOM directly. /// </summary> /// <remarks> /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/create-pdf-document-net-csharp-vb.php /// </remarks> public static void CreatePdfUsingDOM() { // Set a path to our document. string docPath = @"Result-DocumentCore.pdf"; // Create a new document. DocumentCore dc = new DocumentCore(); // Add new section. Section section = new Section(dc); dc.Sections.Add(section); // Let's set page size A4. section.PageSetup.PaperType = PaperType.A4; // Add two paragraphs Paragraph par1 = new Paragraph(dc); par1.ParagraphFormat.Alignment = HorizontalAlignment.Center; section.Blocks.Add(par1); // Let's create a characterformat for text in the 1st paragraph. CharacterFormat cf = new CharacterFormat() { FontName = "Verdana", Size = 16, FontColor = Color.Orange }; Run run1 = new Run(dc, "This is a first line in 1st paragraph!"); run1.CharacterFormat = cf; par1.Inlines.Add(run1); // Let's add a line break into the 1st paragraph. par1.Inlines.Add(new SpecialCharacter(dc, SpecialCharacterType.LineBreak)); // Copy the formatting. Run run2 = run1.Clone(); run2.Text = "Let's type a second line."; par1.Inlines.Add(run2); // Add 2nd paragraph. Paragraph par2 = new Paragraph(dc, new Run(dc, "This is a first line in 2nd paragraph.", new CharacterFormat() { Size = 25, FontColor = Color.Blue, Bold = true })); section.Blocks.Add(par2); SpecialCharacter lBr = new SpecialCharacter(dc, SpecialCharacterType.LineBreak); par2.Inlines.Add(lBr); Run run3 = new Run(dc, "This is a second line.", new CharacterFormat() { Size = 20, FontColor = Color.DarkGreen, UnderlineStyle = UnderlineType.Single }); par2.Inlines.Add(run3); // Add a graphics figure into the paragraph. Shape shape = new Shape(dc, new InlineLayout(new SautinSoft.Document.Drawing.Size(50, 50, LengthUnit.Millimeter))); // Specify outline and fill. shape.Outline.Fill.SetSolid(new SautinSoft.Document.Color("#358CCB")); shape.Outline.Width = 3; shape.Fill.SetSolid(SautinSoft.Document.Color.Orange); shape.Geometry.SetPreset(Figure.SmileyFace); par2.Inlines.Add(shape); // Save the document to the file in PDF format. dc.Save(docPath, new PdfSaveOptions() { Compliance = PdfCompliance.PDF_A1a }); // Open the result for demonstration purposes. System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(docPath) { UseShellExecute = true }); }