Esempio n. 1
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Random number generator.
                Random r = new Random();

                // List of FontNames.
                string[] fontNames = { "Arial", "Times New Roman", "Monotype Corsiva", " Book Antiqua ", "Bitstream Vera Sans", "Comic Sans MS", "Microsoft Sans Serif", "Batang" };

                // Create a new document.
                WordDocument document = new WordDocument();

                // Adding new section to the document.
                IWSection section = document.AddSection();
                // Set Margin for the document
                section.PageSetup.Margins.All = 72;
                // Adding new paragraph to the section.
                IWParagraph paragraph = section.AddParagraph();

                paragraph.AppendText("This sample demonstrates various text and paragraph formatting support.");
                section.AddParagraph();
                section.AddParagraph();

                section           = document.AddSection();
                section.BreakCode = SectionBreakCode.NoBreak;
                //Adding two columns to the section.
                section.AddColumn(250, 20);
                section.AddColumn(250, 20);

                #region Text Formatting
                //Create a TextRange
                IWTextRange text = null;

                // Writing Text with different Formatting styles.
                for (int i = 8, j = 0, k = 0; i <= 20; i++, j++, k++)
                {
                    if (j >= fontNames.Length)
                    {
                        j = 0;
                    }
                    paragraph = section.AddParagraph();
                    text      = paragraph.AppendText("This is " + "[" + fontNames[j] + "] Font");
                    text.CharacterFormat.FontName       = fontNames[j];
                    text.CharacterFormat.UnderlineStyle = (UnderlineStyle)k;
                    text.CharacterFormat.FontSize       = i;
                    text.CharacterFormat.TextColor      = Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
                }

                // More formatting options.
                section.AddParagraph();
                paragraph.ParagraphFormat.ColumnBreakAfter = true;
                paragraph = section.AddParagraph();
                text      = paragraph.AppendText("More formatting Options List...");
                text.CharacterFormat.FontName = fontNames[2];
                text.CharacterFormat.FontSize = 18;

                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.AppendText("AllCaps \n\n").CharacterFormat.AllCaps           = true;
                paragraph.AppendText("Bold \n\n").CharacterFormat.Bold                 = true;
                paragraph.AppendText("DoubleStrike \n\n").CharacterFormat.DoubleStrike = true;
                paragraph.AppendText("Emboss \n\n").CharacterFormat.Emboss             = true;
                paragraph.AppendText("Engrave \n\n").CharacterFormat.Engrave           = true;
                paragraph.AppendText("Italic \n\n").CharacterFormat.Italic             = true;
                paragraph.AppendText("Shadow \n\n").CharacterFormat.Shadow             = true;
                paragraph.AppendText("SmallCaps \n\n").CharacterFormat.SmallCaps       = true;
                paragraph.AppendText("Strikeout \n\n").CharacterFormat.Strikeout       = true;
                paragraph.AppendText("Some Text");
                paragraph.AppendText("SubScript \n\n").CharacterFormat.SubSuperScript = SubSuperScript.SubScript;
                paragraph.AppendText("Some Text");
                paragraph.AppendText("SuperScript \n\n").CharacterFormat.SubSuperScript = SubSuperScript.SuperScript;
                paragraph.AppendText("TextBackgroundColor \n\n").CharacterFormat.TextBackgroundColor = Color.LightBlue;

                #endregion

                #region Paragraph formattings

                section           = document.AddSection();
                section.BreakCode = SectionBreakCode.NewPage;
                paragraph         = section.AddParagraph();
                paragraph.AppendText("Following paragraphs illustrates various paragraph formattings");

                paragraph = section.AddParagraph();
                paragraph.AppendText("This paragraph demonstrates several paragraph formats. It will be used to illustrate Space Before, Space After, and Line Spacing. Space Before tells Microsoft Word how much space to leave before the paragraph. Space After tells Microsoft Word how much space to leave after the paragraph. Line Spacing sets the space between lines within a paragraph.It also explains about first line indentation,backcolor and paragraph border.");
                paragraph.ParagraphFormat.BeforeSpacing      = 20f;
                paragraph.ParagraphFormat.AfterSpacing       = 30f;
                paragraph.ParagraphFormat.BackColor          = Color.LightGray;
                paragraph.ParagraphFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
                paragraph.ParagraphFormat.FirstLineIndent    = 20f;
                paragraph.ParagraphFormat.LineSpacing        = 20f;

                paragraph = section.AddParagraph();
                paragraph.AppendText("This is a sample paragraph. It is used to illustrate alignment. Left-justified text is aligned on the left. Right-justified text is aligned with on the right. Centered text is centered between the left and right margins. You can use Center to center your titles. Justified text is flush on both sides.");
                paragraph.ParagraphFormat.LineSpacing         = 20f;
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;
                paragraph.ParagraphFormat.LineSpacingRule     = LineSpacingRule.Exactly;

                section.AddParagraph();

                //Adding new paragraph to the section.
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.Keep = true;
                paragraph.AppendText("KEEP TOGETHER ").CharacterFormat.Bold = true;
                paragraph.AppendText("This is a sample paragraph. It is used to illustrate Keep together of MsWord. You can control where Microsoft Word positions automatic page breaks (page break: The point at which one page ends and another begins. Microsoft Word inserts an 'automatic' (or soft) page break for you, or you can force a page break at a specific location by inserting a 'manual' (or hard) page break.) by setting pagination options.It keeps the lines in a paragraph together when there is page break ").CharacterFormat.FontSize = 12f;
                for (int i = 0; i < 10; i++)
                {
                    paragraph.AppendText("Text Body_Text Body_Text Body_Text Body_Text Body_Text Body_Text Body").CharacterFormat.FontSize = 12f;
                    paragraph.ParagraphFormat.LineSpacing = 20f;
                }
                paragraph.AppendText(" KEEP TOGETHER END").CharacterFormat.Bold = true;

                #endregion

                #region Bullets and Numbering
                // Adding a new section to the document.
                section = document.AddSection();
                //Set Margin of the document
                section.PageSetup.Margins.Top    = 20;
                section.PageSetup.Margins.Bottom = 20;
                section.PageSetup.Margins.Left   = 50;
                section.PageSetup.Margins.Right  = 20;
                // Adding a new paragraph to the document.
                paragraph = section.AddParagraph();
                // Writing text to the current paragraph.
                paragraph.AppendText("This document demonstrates the Bullets and Numbering functionality. Here fruits are taken as an example to demonstrate the lists. \n\n\n\n");

                //Add a new section
                section1 = document.AddSection();
                //Adding two columns to the section.
                section1.Columns.Add(new Column(document));
                section1.Columns.Add(new Column(document));
                //Set the columns to be of equal width.
                section1.MakeColumnsEqual();

                // Set section break code as NoBreak.
                section1.BreakCode = SectionBreakCode.NoBreak;

                // Set formatting.
                ProductDetailsInBullets();

                // Set Formatting.
                ProductDetailsInNumbers();
                #endregion  Bullets and Numbering

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Sample.doc");
#endif
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.docx");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.pdf");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Getting Image files Path.
                string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\Images\DocIO\";

                //Getting text files Path.
                string dataPath1 = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\Data\";

                //Creating a new document
                WordDocument document = new WordDocument();
                //Adding a new section.
                IWSection   section   = document.AddSection();
                IWParagraph paragraph = section.AddParagraph();
                paragraph = section.AddParagraph();
                section.PageSetup.Margins.All = 72f;
                IWTextRange text = paragraph.AppendText("Adventure products");
                //Formatting Text
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;
                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group ");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

                #region Line break
                paragraph.AppendBreak(BreakType.LineBreak);
                paragraph.AppendBreak(BreakType.LineBreak);
                #endregion

                section = document.AddSection();

                section.BreakCode             = SectionBreakCode.NoBreak;
                section.PageSetup.Margins.All = 72f;
                //Adding three columns to section.
                section.AddColumn(100, 15);
                section.AddColumn(100, 15);
                section.AddColumn(100, 15);
                //Set the columns to be of equal width.
                section.MakeColumnsEqual();

                //Adding a new paragraph to the section.
                paragraph = section.AddParagraph();
                //Adding text.
                text = paragraph.AppendText("Mountain-200");
                //Formatting Text
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;
                //Adding a new paragraph to the section.
                section.AddParagraph();
                paragraph = section.AddParagraph();
                //Inserting an Image.
                WPicture picture = paragraph.AppendPicture(new Bitmap(Path.Combine(dataPath, "Mountain-200.jpg"))) as WPicture;
                picture.Width  = 120f;
                picture.Height = 90f;
                //Adding a new paragraph to the section.
                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                //Adding text.
                paragraph.AppendText(@"Product No:BK-M68B-38" + "\n" + "Size: 38" + "\n" + "Weight: 25\n" + "Price: $2,294.99");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

                // Set column break as true. It navigates the cursor position to the next Column.
                paragraph.ParagraphFormat.ColumnBreakAfter = true;

                paragraph = section.AddParagraph();
                text      = paragraph.AppendText("Mountain-300");
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;

                section.AddParagraph();
                paragraph      = section.AddParagraph();
                picture        = paragraph.AppendPicture(new Bitmap(Path.Combine(dataPath, "Mountain-300.jpg"))) as WPicture;
                picture.Width  = 120f;
                picture.Height = 90f;
                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                paragraph.AppendText(@"Product No:BK-M4-38" + "\n" + "Size: 35\n" + "Weight: 22" + "\n" + " Price: $1,079.99");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

                paragraph.ParagraphFormat.ColumnBreakAfter = true;

                paragraph = section.AddParagraph();
                text      = paragraph.AppendText("Road-150");
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;

                section.AddParagraph();
                paragraph      = section.AddParagraph();
                picture        = paragraph.AppendPicture(new Bitmap(Path.Combine(dataPath, "Road-550-W.jpg"))) as WPicture;
                picture.Width  = 120f;
                picture.Height = 90f;
                section.AddParagraph();
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                paragraph.AppendText(@"Product No: BK-R93R-44" + "\n" + "Size: 44" + "\n" + "Weight: 14" + "\n" + "Price: $3,578.27");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

                section                       = document.AddSection();
                section.BreakCode             = SectionBreakCode.NoBreak;
                section.PageSetup.Margins.All = 72f;

                text = section.AddParagraph().AppendText("First Look\n");
                //Formatting Text
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;

                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                paragraph.AppendText("Adventure Works Cycles, the fictitious company, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;
                paragraph.ParagraphFormat.PageBreakAfter      = true;

                paragraph = section.AddParagraph();
                text      = paragraph.AppendText("Introduction\n");
                //Formatting Text
                text.CharacterFormat.FontName = "Bitstream Vera Sans";
                text.CharacterFormat.FontSize = 12f;
                text.CharacterFormat.Bold     = true;
                paragraph = section.AddParagraph();
                paragraph.ParagraphFormat.LineSpacing = 20f;
                paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.");
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

                //Save as doc format
                if (wordDocRadioBtn.Checked)
                {
                    //Saving the document to disk.
                    document.Save("Sample.doc");

                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                        System.Diagnostics.Process process = new System.Diagnostics.Process();
                        process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc")
                        {
                            UseShellExecute = true
                        };
                        process.Start();
#else
                        System.Diagnostics.Process.Start("Sample.doc");
#endif
                        //Exit
                        this.Close();
                    }
                }
                //Save as docx format
                else if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    document.Save("Sample.docx", FormatType.Docx);
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer]
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.docx");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Win32Exception ex)
                        {
                            MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                //Save as pdf format
                else if (pdfRadioBtn.Checked)
                {
                    DocToPDFConverter converter = new DocToPDFConverter();
                    //Convert word document into PDF document
                    PdfDocument pdfDoc = converter.ConvertToPDF(document);
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    //Message box confirmation to view the created document.
                    if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
#if NETCORE
                            System.Diagnostics.Process process = new System.Diagnostics.Process();
                            process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf")
                            {
                                UseShellExecute = true
                            };
                            process.Start();
#else
                            System.Diagnostics.Process.Start("Sample.pdf");
#endif
                            //Exit
                            this.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBoxAdv.Show("PDF Viewer is not installed in this system");
                            Console.WriteLine(ex.ToString());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
        public ActionResult FormatText(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }
            //Random number generator.
            Random r = new Random();

            // List of FontNames.
            string[] fontNames = { "Arial",               "Times New Roman", "Monotype Corsiva",     " Book Antiqua ",
                                   "Bitstream Vera Sans", "Comic Sans MS",   "Microsoft Sans Serif", "Batang" };

            // Create a new document.
            WordDocument document = new WordDocument();

            // Adding a new section to the document.
            IWSection section = document.AddSection();

            // Adding a new paragraph to the section.
            IWParagraph paragraph = section.AddParagraph();

            paragraph.AppendText("This sample demonstrates various text and paragraph formatting support.");
            section.AddParagraph();
            section.AddParagraph();

            section           = document.AddSection();
            section.BreakCode = SectionBreakCode.NoBreak;
            //Adding two columns to the section.
            section.AddColumn(250, 20);
            section.AddColumn(250, 20);

            #region Text Formatting
            //Create a TextRange
            IWTextRange text = null;

            // Writing Text with different Formatting styles.
            for (int i = 8, j = 0, k = 0; i <= 20; i++, j++, k++)
            {
                if (j >= fontNames.Length)
                {
                    j = 0;
                }
                paragraph = section.AddParagraph();
                text      = paragraph.AppendText("This is " + "[" + fontNames[j] + "]");
                text.CharacterFormat.FontName       = fontNames[j];
                text.CharacterFormat.UnderlineStyle = (UnderlineStyle)k;
                text.CharacterFormat.FontSize       = i;
                text.CharacterFormat.TextColor      = Syncfusion.Drawing.Color.FromArgb(r.Next(0, 255), r.Next(0, 255), r.Next(0, 255));
            }

            // More formatting options.
            section.AddParagraph();
            paragraph.ParagraphFormat.ColumnBreakAfter = true;
            paragraph = section.AddParagraph();
            text      = paragraph.AppendText("More formatting Options List...");
            text.CharacterFormat.FontName = fontNames[2];
            text.CharacterFormat.FontSize = 18;

            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.AppendText("AllCaps \n\n").CharacterFormat.AllCaps           = true;
            paragraph.AppendText("Bold \n\n").CharacterFormat.Bold                 = true;
            paragraph.AppendText("DoubleStrike \n\n").CharacterFormat.DoubleStrike = true;
            paragraph.AppendText("Emboss \n\n").CharacterFormat.Emboss             = true;
            paragraph.AppendText("Engrave \n\n").CharacterFormat.Engrave           = true;
            paragraph.AppendText("Italic \n\n").CharacterFormat.Italic             = true;
            paragraph.AppendText("Shadow \n\n").CharacterFormat.Shadow             = true;
            paragraph.AppendText("SmallCaps \n\n").CharacterFormat.SmallCaps       = true;
            paragraph.AppendText("Strikeout \n\n").CharacterFormat.Strikeout       = true;
            paragraph.AppendText("Some Text");
            paragraph.AppendText("SubScript \n\n").CharacterFormat.SubSuperScript = SubSuperScript.SubScript;
            paragraph.AppendText("Some Text");
            paragraph.AppendText("SuperScript \n\n").CharacterFormat.SubSuperScript = SubSuperScript.SuperScript;
            paragraph.AppendText("TextBackgroundColor \n\n").CharacterFormat.TextBackgroundColor = Syncfusion.Drawing.Color.LightBlue;
            #endregion

            #region Paragraph formattings

            section           = document.AddSection();
            section.BreakCode = SectionBreakCode.NewPage;
            paragraph         = section.AddParagraph();
            paragraph.AppendText("Following paragraphs illustrates various paragraph formattings");

            paragraph = section.AddParagraph();
            paragraph.AppendText("We will use this paragraph to illustrate several Microsoft Word features using Essential DocIO. It will be used to illustrate Space Before, Space After, and Line Spacing. Space Before tells Microsoft Word how much space to leave before the paragraph. Space After tells Microsoft Word how much space to leave after the paragraph. Line Spacing sets the space between lines within a paragraph.It also explains about first line indentation,backcolor and paragraph border.");
            paragraph.ParagraphFormat.BeforeSpacing      = 20f;
            paragraph.ParagraphFormat.AfterSpacing       = 30f;
            paragraph.ParagraphFormat.BackColor          = Syncfusion.Drawing.Color.LightGray;
            paragraph.ParagraphFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;
            paragraph.ParagraphFormat.FirstLineIndent    = 20f;
            paragraph.ParagraphFormat.LineSpacing        = 20f;

            paragraph = section.AddParagraph();
            paragraph.AppendText("This is a sample paragraph. It is used to illustrate alignment. Left-justified text is aligned on the left. Right-justified text is aligned with on the right. Centered text is centered between the left and right margins. You can use Center to center your titles. Justified text is flush on both sides.");
            paragraph.ParagraphFormat.LineSpacing         = 20f;
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;
            paragraph.ParagraphFormat.LineSpacingRule     = LineSpacingRule.Exactly;

            section.AddParagraph();

            //Adding a new paragraph to the section.
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.Keep = true;
            paragraph.AppendText("KEEP TOGETHER").CharacterFormat.Bold = true;
            paragraph.AppendText("This is a sample paragraph. It is used to illustrate Keep together of MsWord. You can control where Microsoft Word positions automatic page breaks (page break: The point at which one page ends and another begins. Microsoft Word inserts an 'automatic' (or soft) page break for you, or you can force a page break at a specific location by inserting a 'manual' (or hard) page break.) by setting pagination options.It keeps the lines in a paragraph together when there is page break").CharacterFormat.FontSize = 12f;
            for (int i = 0; i < 10; i++)
            {
                paragraph.AppendText("Text Body_Text Body_Text Body_Text Body_Text Body_Text Body_Text Body").CharacterFormat.FontSize = 12f;
                paragraph.ParagraphFormat.LineSpacing = 20f;
            }
            paragraph.AppendText("KEEP TOGETHER END").CharacterFormat.Bold = true;
            #endregion

            #region Bullets and Numbering
            // Adding a new section to the document.
            section = document.AddSection();
            // Adding a new paragraph to the document.
            paragraph = section.AddParagraph();
            // Writing text to the current paragraph.
            paragraph.AppendText("This document demonstrates the Bullets and Numbering functionality available in Essential DocIO");

            //Add a new section
            section1 = document.AddSection();
            //Adding two columns to the section.
            section1.Columns.Add(new Column(document));
            section1.Columns.Add(new Column(document));
            //Set the columns to be of equal width.
            section1.MakeColumnsEqual();

            // Set section break code as NoBreak.
            section1.BreakCode = SectionBreakCode.NoBreak;

            // Set formatting.
            ProductDetailsInBullets();

            // Set Formatting.
            ProductDetailsInNumbers();
            #endregion  Bullets and Numbering

            FormatType type        = FormatType.Docx;
            string     filename    = "Sample.docx";
            string     contenttype = "application/vnd.ms-word.document.12";
            #region Document SaveOption
            //Save as .doc format
            if (Group1 == "WordDoc")
            {
                type        = FormatType.Doc;
                filename    = "Sample.doc";
                contenttype = "application/msword";
            }
            //Save as .xml format
            else if (Group1 == "WordML")
            {
                type        = FormatType.WordML;
                filename    = "Sample.xml";
                contenttype = "application/msword";
            }
            #endregion Document SaveOption
            MemoryStream ms = new MemoryStream();
            document.Save(ms, type);
            document.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }
        public ActionResult InsertBreak(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }

            //Creating a new document
            WordDocument document = new WordDocument();
            //Adding a new section.
            IWSection   section   = document.AddSection();
            IWParagraph paragraph = section.AddParagraph();

            paragraph = section.AddParagraph();
            section.PageSetup.Margins.All = 20f;
            IWTextRange text = paragraph.AppendText("Adventure products");

            //Formatting Text
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;
            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group ");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

            #region Line break
            paragraph.AppendBreak(BreakType.LineBreak);
            paragraph.AppendBreak(BreakType.LineBreak);
            #endregion Line break

            section = document.AddSection();

            section.BreakCode             = SectionBreakCode.NoBreak;
            section.PageSetup.Margins.All = 20f;
            //Adding three columns to section.
            section.AddColumn(100, 15);
            section.AddColumn(100, 15);
            section.AddColumn(100, 15);
            //Set the columns to be of equal width.
            section.MakeColumnsEqual();

            //Adding a new paragraph to the section.
            paragraph = section.AddParagraph();
            //Adding text.
            text = paragraph.AppendText("Mountain-200");
            //Formatting Text
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;
            //Adding a new paragraph to the section.
            section.AddParagraph();
            paragraph = section.AddParagraph();
            //Inserting an Image.
            WPicture picture = paragraph.AppendPicture(new Bitmap(ResolveApplicationDataPath("Mountain-200.jpg", "Content\\DocIO"))) as WPicture;
            picture.Width  = 120f;
            picture.Height = 90f;
            //Adding a new paragraph to the section.
            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            //Adding text.
            paragraph.AppendText(@"Product No:BK-M68B-38" + "\n" + "Size: 38" + "\n" + "Weight: 25\n" + "Price: $2,294.99");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

            // Set column break as true. It navigates the cursor position to the next Column.
            paragraph.ParagraphFormat.ColumnBreakAfter = true;

            paragraph = section.AddParagraph();
            text      = paragraph.AppendText("Mountain-300");
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;

            section.AddParagraph();
            paragraph      = section.AddParagraph();
            picture        = paragraph.AppendPicture(new Bitmap(ResolveApplicationDataPath("Mountain-300.jpg", "Content\\DocIO"))) as WPicture;
            picture.Width  = 120f;
            picture.Height = 90f;
            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            paragraph.AppendText(@"Product No:BK-M4-38" + "\n" + "Size: 35\n" + "Weight: 22" + "\n" + "Price: $1,079.99");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

            paragraph.ParagraphFormat.ColumnBreakAfter = true;

            paragraph = section.AddParagraph();
            text      = paragraph.AppendText("Road-150");
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;

            section.AddParagraph();
            paragraph      = section.AddParagraph();
            picture        = paragraph.AppendPicture(new Bitmap(ResolveApplicationDataPath("Road-550-W.jpg", "Content\\DocIO"))) as WPicture;
            picture.Width  = 120f;
            picture.Height = 90f;
            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            paragraph.AppendText(@"Product No: BK-R93R-44" + "\n" + "Size: 44" + "\n" + "Weight: 14" + "\n" + "Price: $3,578.27");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

            section                       = document.AddSection();
            section.BreakCode             = SectionBreakCode.NoBreak;
            section.PageSetup.Margins.All = 20f;

            text = section.AddParagraph().AppendText("First Look\n");
            //Formatting Text
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;

            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            paragraph.AppendText(@"Adventure Works Cycles, the fictitious company, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;
            paragraph.ParagraphFormat.PageBreakAfter      = true;

            paragraph = section.AddParagraph();
            text      = paragraph.AppendText("Introduction\n");
            //Formatting Text
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            paragraph.AppendText(@"In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

            //Save as .doc format
            if (Group1 == "WordDoc")
            {
                return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            //Save as .docx format
            else if (Group1 == "WordDocx")
            {
                return(document.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            // Save as WordML(.xml) format
            else if (Group1 == "WordML")
            {
                return(document.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment));
            }
            //Save as .pdf format
            else if (Group1 == "Pdf")
            {
                DocToPDFConverter converter = new DocToPDFConverter();
                PdfDocument       pdfDoc    = converter.ConvertToPDF(document);

                return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save));
            }
            return(View());
        }
        public ActionResult InsertBreak(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }

            //Creating a new document
            WordDocument document = new WordDocument();
            //Adding a new section.
            IWSection   section   = document.AddSection();
            IWParagraph paragraph = section.AddParagraph();

            paragraph = section.AddParagraph();
            section.PageSetup.Margins.All = 20f;
            IWTextRange text = paragraph.AppendText("Adventure products");

            //Formatting Text
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;
            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group ");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

            #region Line break
            paragraph.AppendBreak(BreakType.LineBreak);
            paragraph.AppendBreak(BreakType.LineBreak);
            #endregion Line break

            section = document.AddSection();

            section.BreakCode             = SectionBreakCode.NoBreak;
            section.PageSetup.Margins.All = 20f;
            //Adding three columns to section.
            section.AddColumn(100, 15);
            section.AddColumn(100, 15);
            section.AddColumn(100, 15);
            //Set the columns to be of equal width.
            section.MakeColumnsEqual();

            //Adding a new paragraph to the section.
            paragraph = section.AddParagraph();
            //Adding text.
            text = paragraph.AppendText("Mountain-200");
            //Formatting Text
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;
            //Adding a new paragraph to the section.
            section.AddParagraph();
            paragraph = section.AddParagraph();
            string     basePath    = _hostingEnvironment.WebRootPath;
            FileStream imageStream = new FileStream(basePath + @"/images/DocIO/Mountain-200.jpg", FileMode.Open, FileAccess.Read);
            //Inserting an Image.
            WPicture picture = paragraph.AppendPicture(imageStream) as WPicture;
            picture.Width  = 120f;
            picture.Height = 90f;
            //Adding a new paragraph to the section.
            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            //Adding text.
            paragraph.AppendText(@"Product No:BK-M68B-38" + "\n" + "Size: 38" + "\n" + "Weight: 25\n" + "Price: $2,294.99");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

            // Set column break as true. It navigates the cursor position to the next Column.
            paragraph.ParagraphFormat.ColumnBreakAfter = true;

            paragraph = section.AddParagraph();
            text      = paragraph.AppendText("Mountain-300");
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;

            section.AddParagraph();
            paragraph = section.AddParagraph();

            imageStream    = new FileStream(basePath + @"/images/DocIO/Mountain-300.jpg", FileMode.Open, FileAccess.Read);
            picture        = paragraph.AppendPicture(imageStream) as WPicture;
            picture.Width  = 120f;
            picture.Height = 90f;
            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            paragraph.AppendText(@"Product No:BK-M4-38" + "\n" + "Size: 35\n" + "Weight: 22" + "\n" + "Price: $1,079.99");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;
            paragraph.ParagraphFormat.ColumnBreakAfter    = true;

            paragraph = section.AddParagraph();
            text      = paragraph.AppendText("Road-150");
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;

            section.AddParagraph();
            paragraph = section.AddParagraph();

            imageStream    = new FileStream(basePath + @"/images/DocIO/Road-550-W.jpg", FileMode.Open, FileAccess.Read);
            picture        = paragraph.AppendPicture(imageStream) as WPicture;
            picture.Width  = 120f;
            picture.Height = 90f;
            section.AddParagraph();
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            paragraph.AppendText(@"Product No: BK-R93R-44" + "\n" + "Size: 44" + "\n" + "Weight: 14" + "\n" + "Price: $3,578.27");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

            section                       = document.AddSection();
            section.BreakCode             = SectionBreakCode.NoBreak;
            section.PageSetup.Margins.All = 20f;

            text = section.AddParagraph().AppendText("First Look\n");
            //Formatting Text
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;

            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            paragraph.AppendText(@"Adventure Works Cycles, the fictitious company, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base.");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;
            paragraph.ParagraphFormat.PageBreakAfter      = true;

            paragraph = section.AddParagraph();
            text      = paragraph.AppendText("Introduction\n");
            //Formatting Text
            text.CharacterFormat.FontName = "Bitstream Vera Sans";
            text.CharacterFormat.FontSize = 12f;
            text.CharacterFormat.Bold     = true;
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.LineSpacing = 20f;
            paragraph.AppendText(@"In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group.");
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify;

            FormatType type        = FormatType.Docx;
            string     filename    = "Sample.docx";
            string     contenttype = "application/vnd.ms-word.document.12";
            #region Document SaveOption
            //Save as .doc format
            if (Group1 == "WordDoc")
            {
                type        = FormatType.Doc;
                filename    = "Sample.doc";
                contenttype = "application/msword";
            }
            //Save as .xml format
            else if (Group1 == "WordML")
            {
                type        = FormatType.WordML;
                filename    = "Sample.xml";
                contenttype = "application/msword";
            }
            #endregion Document SaveOption
            MemoryStream ms = new MemoryStream();
            document.Save(ms, type);
            document.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }