Exemplo n.º 1
0
        private void InsertPageHeaderFooter(WordDocument doc, IWSection section1)
        {
            // Add a new paragraph for header to the document.
            IWParagraph headerPar = new WParagraph(doc);

            // Add a new table to the header
            IWTable table = section1.HeadersFooters.Header.AddTable();

            RowFormat format = new RowFormat();

            // Setting Single table border style.
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;

            // Inserting table with a row and two columns.
            table.ResetCells(1, 2, format, 265);

            // Inserting logo image to the table first cell.
            headerPar = table[0, 0].AddParagraph() as WParagraph;
            string     basePath    = _hostingEnvironment.WebRootPath;
            FileStream imageStream = new FileStream(basePath + @"/images/DocIO/Northwind_logo.png", FileMode.Open, FileAccess.Read);

            headerPar.AppendPicture(imageStream);
            //Set Image size.
            (headerPar.Items[0] as WPicture).Width  = 232.5f;
            (headerPar.Items[0] as WPicture).Height = 54.75f;
            // Inserting text to the table second cell.
            headerPar = table[0, 1].AddParagraph() as WParagraph;
            IWTextRange txt = headerPar.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638.");

            txt.CharacterFormat.FontSize                  = 12;
            txt.CharacterFormat.CharacterSpacing          = 1.7f;
            headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;

            // Add a footer paragraph text to the document.
            WParagraph footerPar = new WParagraph(doc);

            footerPar.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader);
            // Add text.
            footerPar.AppendText("Copyright Northwind Inc. 2001 - 2017");
            // Add page and Number of pages field to the document.
            footerPar.AppendText("\tPage ");
            IWField ff = footerPar.AppendField("Page", FieldType.FieldPage);

            section1.HeadersFooters.Footer.Paragraphs.Add(footerPar);

            #region Page Number Settings
            section1.PageSetup.RestartPageNumbering = true;
            section1.PageSetup.PageStartingNumber   = 1;
            section1.PageSetup.PageNumberStyle      = PageNumberStyle.Arabic;
            #endregion Page Number Settings
        }
Exemplo n.º 2
0
        private void AddSubsectionTitle(IWSection section, string subsectionTile)
        {
            IWParagraph spacingParagraph = section.AddParagraph();

            spacingParagraph.AppendText("\n");
            IWParagraph title_paragraph = section.AddParagraph();
            IWTextRange title_text      = title_paragraph.AppendText(subsectionTile);

            title_text.CharacterFormat.Bold           = false;
            title_text.CharacterFormat.FontName       = "Times New Roman";
            title_text.CharacterFormat.UnderlineStyle = UnderlineStyle.Single;
            title_text.CharacterFormat.FontSize       = 14;
            title_paragraph.AppendText("\n");
        }
Exemplo n.º 3
0
        private void InsertPageHeaderFooter(WordDocument doc, IWSection section1)
        {
            // Add a new paragraph for header to the document.
            IWParagraph headerPar = new WParagraph(doc);

            // Add a new table to the header
            IWTable table = section1.HeadersFooters.Header.AddTable();

            RowFormat format = new RowFormat();

            // Setting Single table border style.
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;

            // Inserting table with a row and two columns.
            table.ResetCells(1, 2, format, 265);

            // Inserting logo image to the table first cell.
            headerPar = table[0, 0].AddParagraph() as WParagraph;
#if NETCORE
            headerPar.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\common\images\DocIO\Northwind_logo.png"));
#else
            headerPar.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\common\images\DocIO\Northwind_logo.png"));
#endif
            //Set Image size.
            (headerPar.Items[0] as WPicture).Width  = 232.5f;
            (headerPar.Items[0] as WPicture).Height = 54.75f;
            // Inserting text to the table second cell.
            headerPar = table[0, 1].AddParagraph() as WParagraph;
            IWTextRange txt = headerPar.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638.");
            txt.CharacterFormat.FontSize                  = 12;
            txt.CharacterFormat.CharacterSpacing          = 1.7f;
            headerPar.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;

            // Add a footer paragraph text to the document.
            WParagraph footerPar = new WParagraph(doc);
            footerPar.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader);
            // Add text.
            footerPar.AppendText("Copyright Northwind Inc. 2001 - 2017");
            // Add page and Number of pages field to the document.
            footerPar.AppendText("\tPage ");
            IWField ff = footerPar.AppendField("Page", Syncfusion.DocIO.FieldType.FieldPage);

            section1.HeadersFooters.Footer.Paragraphs.Add(footerPar);

            #region Page Number Settings
            section1.PageSetup.RestartPageNumbering = true;
            section1.PageSetup.PageStartingNumber   = Convert.ToInt32(this.numericUpDown1.Value);
            section1.PageSetup.PageNumberStyle      = (PageNumberStyle)Enum.Parse(typeof(PageNumberStyle), this.comboBox1.SelectedItem.ToString(), true);
            #endregion
        }
Exemplo n.º 4
0
 /// <summary>
 /// Create a child shape with its specified properties and add into specified group shape
 /// </summary>
 /// <param name="autoShapeType">Represent the AutoShapeType of child shape</param>
 /// <param name="bounds">Represent the bounds of child shape to be placed</param>
 /// <param name="rotation">Represent the rotation of child shape</param>
 /// <param name="flipH">Represent the horizontal flip of child shape</param>
 /// <param name="flipV">Represent the vertical flip of child shape</param>
 /// <param name="fillColor">Represent the fill color of child shape</param>
 /// <param name="text">Represent the text that to be append in child shape</param>
 /// <param name="groupShape">Represent the group shape to add a child shape</param>
 /// <param name="wordDocument">Represent the Word document instance</param>
 private static void CreateChildShape(AutoShapeType autoShapeType, RectangleF bounds, float rotation, bool flipH, bool flipV, Syncfusion.Drawing.Color fillColor, string text, GroupShape groupShape, WordDocument wordDocument)
 {
     //Creates new shape to add into group
     Shape shape = new Shape(wordDocument, autoShapeType);
     //Sets height and width for shape
     shape.Height = bounds.Height;
     shape.Width = bounds.Width;
     //Sets horizontal and vertical position
     shape.HorizontalPosition = bounds.X;
     shape.VerticalPosition = bounds.Y;
     //Set rotation and flipH for the shape
     if (rotation != 0)
         shape.Rotation = rotation;
     if (flipH)
         shape.FlipHorizontal = true;
     if (flipV)
         shape.FlipVertical = true;
     //Applies fill color for shape
     if (fillColor != Syncfusion.Drawing.Color.White)
     {
         shape.FillFormat.Fill = true;
         shape.FillFormat.Color = fillColor;
     }
     //Set wrapping style for shape
     shape.WrapFormat.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
     //Sets horizontal and vertical origin
     shape.HorizontalOrigin = HorizontalOrigin.Page;
     shape.VerticalOrigin = VerticalOrigin.Page;
     //Sets no line to RoundedRectangle shapes
     if (autoShapeType == AutoShapeType.RoundedRectangle)
         shape.LineFormat.Line = false;
     //Add paragraph for the shape textbody
     if (text != null)
     {
         IWParagraph paragraph = shape.TextBody.AddParagraph();
         //Set required textbody alignments
         shape.TextFrame.TextVerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
         //Set required paragraph alignments
         paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
         IWTextRange textRange = paragraph.AppendText(text);
         //Applies a required text formatting's
         textRange.CharacterFormat.FontName = "Calibri";
         textRange.CharacterFormat.FontSize = 15;
         textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.White;
         textRange.CharacterFormat.Bold = true;
         textRange.CharacterFormat.Italic = true;
     }
     //Adds the specified shape to group shape
     groupShape.Add(shape);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Inserts Header and Footer to all pages.
        /// </summary>
        private void InsertPageHeaderFooter(WordDocument doc, IWSection section1)
        {
            //Adds a new table to the header
            IWTable table = section1.HeadersFooters.Header.AddTable();

            RowFormat format = new();

            //Sets Single table border style.
            format.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Single;

            //Inserts table with a row and two columns.
            table.ResetCells(1, 2, format, 265);

            //Inserts logo image to the table first cell.
            IWParagraph headerPara  = table[0, 0].AddParagraph() as WParagraph;
            Stream      imageStream = assembly.GetManifestResourceStream("syncfusion.dociodemos.winui.Assets.DocIO.Northwindlogo.png");

            headerPara.AppendPicture(imageStream);
            //Sets Image size.
            (headerPara.Items[0] as WPicture).Width  = 232.5f;
            (headerPara.Items[0] as WPicture).Height = 54.75f;
            //Inserts text to the table second cell.
            headerPara = table[0, 1].AddParagraph() as WParagraph;
            IWTextRange txt = headerPara.AppendText("Company Headquarters,\n2501 Aerial Center Parkway,\nSuite 110, Morrisville, NC 27560,\nTEL 1-888-936-8638.");

            txt.CharacterFormat.FontSize                   = 12;
            txt.CharacterFormat.CharacterSpacing           = 1.7f;
            headerPara.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Right;

            //Adds a footer paragraph text to the document.
            WParagraph footerPara = new(doc);

            footerPara.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader);
            //Adds text.
            footerPara.AppendText("Copyright Northwind Inc. 2001 - 2021");
            //Adds page and Number of pages field to the document.
            footerPara.AppendText("\tPage ");
            footerPara.AppendField("Page", FieldType.FieldPage);
            footerPara.AppendText(" of ");
            footerPara.AppendField("NumPages", FieldType.FieldNumPages);
            section1.HeadersFooters.Footer.Paragraphs.Add(footerPara);

            #region Page Number Settings
            section1.PageSetup.RestartPageNumbering = true;
            section1.PageSetup.PageStartingNumber   = 1;
            section1.PageSetup.PageNumberStyle      = PageNumberStyle.Arabic;
            #endregion Page Number Settings
        }
Exemplo n.º 6
0
        private IWParagraph AddTitleToSection(IWSection section, string title)
        {
            IWParagraph title_paragraph = section.AddParagraph();

            title_paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;

            IWTextRange title_text = title_paragraph.AppendText(title);

            title_text.CharacterFormat.Bold           = true;
            title_text.CharacterFormat.FontName       = "Times New Roman";
            title_text.CharacterFormat.UnderlineStyle = UnderlineStyle.Single;
            title_text.CharacterFormat.FontSize       = 16;
            title_paragraph.AppendText("\n");

            return(title_paragraph);
        }
        /// <summary>
        /// Insert a content controls and maps Customer details to it.
        /// </summary>
        /// <param name="document">Word document instance.</param>
        /// <param name="customerNode">CustomXMLNode of customer.</param>
        /// <param name="docIOxmlPart">CustomXMLPart instance.</param>
        /// <param name="empPath">Current employee index.</param>
        /// <param name="custIndex">Current customer index.</param>
        private void InsertAndMapCustomer(WordDocument document, CustomXMLNode customerNode, CustomXMLPart docIOxmlPart, string empPath, int custIndex)
        {
            //Column names of Customer element.
            string[] customersDetails = { "CustomerID", "EmployeeID", "CompanyName", "ContactName", "City", "Country" };

            document.LastSection.AddParagraph();

            //Adds new paragraph to the section
            IWParagraph paragraph = document.LastSection.AddParagraph();

            paragraph.ParagraphFormat.BackColor  = Color.Green;
            paragraph.ParagraphFormat.LeftIndent = 72;

            IWTextRange textrange = paragraph.AppendText("Customers");

            textrange.CharacterFormat.TextColor = Color.White;
            textrange.CharacterFormat.Bold      = true;
            textrange.CharacterFormat.FontSize  = 14;

            int    orderIndex    = 1;
            int    custChild     = 0;
            bool   isFirstOrder  = true;
            string customerXpath = empPath + "Customers[" + custIndex + "]/";

            foreach (CustomXMLNode customerChild in customerNode.ChildNodes)
            {
                if (customerChild.HasChildNodes())
                {
                    //Insert a content controls and maps Orders details to it.
                    InsertAndMapOrders(document, customerChild, docIOxmlPart, customerXpath, orderIndex, isFirstOrder);
                    document.LastSection.AddParagraph();
                    isFirstOrder = false;
                    orderIndex++;
                }
                else
                {
                    //Insert a content controls and maps Customer details other than Order details to it.
                    paragraph = document.LastSection.AddParagraph();
                    paragraph.ParagraphFormat.LeftIndent = 72;

                    paragraph.AppendText(customersDetails[custChild] + ":");
                    MapCustomXMLPart(paragraph, customerXpath + customersDetails[custChild], docIOxmlPart);
                }
                custChild++;
            }
        }
Exemplo n.º 8
0
 static void Main(string[] args)
 {
     //Creates new Word document instance for Word processing
     using (WordDocument document = new WordDocument())
     {
         //Adds a section to the Word document
         IWSection section = document.AddSection();
         //Sets the page margin
         section.PageSetup.Margins.All = 72;
         //Adds a paragrah to the section
         IWParagraph paragraph = section.AddParagraph();
         paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
         paragraph.ParagraphFormat.AfterSpacing        = 20;
         IWTextRange textRange = paragraph.AppendText("Suppliers");
         textRange.CharacterFormat.FontSize  = 14;
         textRange.CharacterFormat.Bold      = true;
         textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(255, 50, 62, 79);
         //Modifies the font size as 10 for default paragraph style
         WParagraphStyle style = document.Styles.FindByName("Normal") as WParagraphStyle;
         style.CharacterFormat.FontSize = 10;
         //Adds a table to the section
         WTable table = section.AddTable() as WTable;
         table.ResetCells(1, 6);
         table[0, 0].Width = 52f;
         table[0, 0].AddParagraph().AppendText("Supplier ID");
         table[0, 1].Width = 128f;
         table[0, 1].AddParagraph().AppendText("Company Name");
         table[0, 2].Width = 70f;
         table[0, 2].AddParagraph().AppendText("Contact Name");
         table[0, 3].Width = 92f;
         table[0, 3].AddParagraph().AppendText("Address");
         table[0, 4].Width = 66.5f;
         table[0, 4].AddParagraph().AppendText("City");
         table[0, 5].Width = 56f;
         table[0, 5].AddParagraph().AppendText("Country");
         //Imports data to the table.
         ImportDataToTable(table);
         //Applies the built-in table style (Medium Shading 1 Accent 1) to the table
         table.ApplyStyle(BuiltinTableStyle.MediumShading1Accent1);
         //Saves the file in the given path
         Stream docStream = File.Create(Path.GetFullPath(@"Result.docx"));
         document.Save(docStream, FormatType.Docx);
         docStream.Dispose();
     }
 }
        private void ProductDetailsInNumbers()
        {
            // Adding a new paragraph to the document.
            section1.AddParagraph();
            paragraph = section1.AddParagraph();

            // Writing text to the document with formatting.
            textRange = paragraph.AppendText("List of Fruits.");
            paragraph.ListFormat.ApplyDefNumberedStyle();
            textRange.CharacterFormat.FontName = "Monotype Corsiva";
            textRange.CharacterFormat.FontSize = 15;

            // Writing Product details to the document with the specified list type.
            section1.AddParagraph();
            foreach (string s in products)
            {
                section1.AddParagraph();
                paragraph = section1.AddParagraph();
                paragraph.AppendText(s);
                paragraph.ListFormat.ContinueListNumbering();

                paragraph.ListFormat.ListLevelNumber = 1;
                section1.AddParagraph();
                foreach (string s1 in forms)
                {
                    if (String.Equals(s, "Plums"))
                    {
                        paragraph = section1.AddParagraph();
                        paragraph.AppendText(s1);
                        paragraph.ListFormat.ContinueListNumbering();

                        paragraph.ListFormat.ListLevelNumber = 2;
                        break;
                    }
                    else
                    {
                        paragraph = section1.AddParagraph();
                        paragraph.AppendText(s1);
                        paragraph.ListFormat.ContinueListNumbering();

                        paragraph.ListFormat.ListLevelNumber = 2;
                    }
                }
            }
        }
        protected void ClickToEncrypt_Click(object sender, EventArgs e)
        {
            if (this.FileUpload1.HasFile && System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName).StartsWith(".doc"))
            {
                Stream readFile = this.FileUpload1.PostedFile.InputStream;

                //Open the document
                WordDocument document = new WordDocument(readFile);
                // Getting last section of the document.
                IWSection section = document.LastSection;

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

                // Writing text
                IWTextRange text = paragraph.AppendText("This document was encrypted with password");
                text.CharacterFormat.FontSize = 16f;
                text.CharacterFormat.FontName = "Bitstream Vera Serif";

                // Encrypt the document by giving password
                document.EncryptDocument(txtEnOpen.Text);

                # region Save Document

                if (rdButtonDoc.Checked)
                {
                    //Save as .doc format
                    document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment);
                }
                //Save as .docx format
                else if (rdButtonDocx.Checked)
                {
                    try
                    {
                        document.Save("Sample.docx", FormatType.Docx, Response, HttpContentDisposition.Attachment);
                    }
                    catch (Win32Exception ex)
                    {
                        Response.Write("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                        Console.WriteLine(ex.ToString());
                    }
                }
                # endregion
            }
Exemplo n.º 11
0
        public MemoryStream GetWord(List <Book> books)
        {
            var         word    = new WordDocument();
            IWSection   section = word.AddSection();
            IWTextRange title   = section.AddParagraph().AppendText("Filtered Books");

            title.CharacterFormat.Bold = true;
            section.AddParagraph();

            IWTable table = section.AddTable();

            table.Title       = "Filtered books";
            table.Description = "Books found based on applied filters";

            var headers = new List <string>()
            {
                "Title", "Author", "Price", "Bestseller", "Availability"
            };

            table.ResetCells(books.Count + 1, headers.Count);

            //Add table row with headers
            for (int i = 0; i < headers.Count; i++)
            {
                table[0, i].AddParagraph().AppendText(headers[i]);
            }

            //Add table rows with book values
            for (int i = 0; i < books.Count; i++)
            {
                table[i + 1, 0].AddParagraph().AppendText(books[i].Title);
                table[i + 1, 1].AddParagraph().AppendText(GetAuthorString(books[i].Author));;
                table[i + 1, 2].AddParagraph().AppendText(GetPriceString(books[i].Price));
                table[i + 1, 3].AddParagraph().AppendText(GetBestsellerString(books[i].IsBestSeller));
                table[i + 1, 4].AddParagraph().AppendText(GetStockString(books[i].AvailableStock));
            }

            MemoryStream stream = new MemoryStream();

            word.Save(stream, FormatType.Docx);

            return(stream);
        }
        public ActionResult Forms(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }
            #region CreateForm
            // 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();

            #region Document formatting
            //Set background color.
            document.Background.Gradient.Color1         = Color.FromArgb(232, 232, 232);
            document.Background.Gradient.Color2         = Color.FromArgb(255, 255, 255);
            document.Background.Type                    = BackgroundType.Gradient;
            document.Background.Gradient.ShadingStyle   = GradientShadingStyle.Horizontal;
            document.Background.Gradient.ShadingVariant = GradientShadingVariant.ShadingDown;

            section.PageSetup.Margins.All = 30f;
            section.PageSetup.PageSize    = new SizeF(600, 600f);
            #endregion

            #region Title Section
            IWTable table = section.Body.AddTable();
            table.ResetCells(1, 2);

            WTableRow row = table.Rows[0];
            row.Height = 25f;

            IWParagraph          cellPara = row.Cells[0].AddParagraph();
            string               s        = ResolveApplicationDataPath("image.jpg", "Images\\DocIO");
            System.Drawing.Image img      = System.Drawing.Image.FromFile(s);
            IWPicture            pic      = cellPara.AppendPicture(img);
            pic.Height = 80;
            pic.Width  = 180;

            cellPara = row.Cells[1].AddParagraph();
            row.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
            row.Cells[1].CellFormat.BackColor         = Color.FromArgb(173, 215, 255);
            IWTextRange txt = cellPara.AppendText("Job Application Form");
            cellPara.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
            txt.CharacterFormat.Bold     = true;
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 18f;

            row.Cells[0].Width = 200;
            row.Cells[1].Width = 300;
            //row.Cells[1].CellFormat.FitText = true;
            row.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
            #endregion

            section.AddParagraph();

            #region General Information
            table = section.Body.AddTable();
            table.TableFormat.Paddings.All = 5.4f;
            table.ResetCells(2, 1);
            row                = table.Rows[0];
            row.Height         = 20;
            row.Cells[0].Width = 500;
            cellPara           = row.Cells[0].AddParagraph();
            row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Thick;
            row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
            row.Cells[0].CellFormat.BackColor          = Color.FromArgb(198, 227, 255);
            row.Cells[0].CellFormat.VerticalAlignment  = VerticalAlignment.Middle;
            txt = cellPara.AppendText(" General Information");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.Bold     = true;
            txt.CharacterFormat.FontSize = 11f;

            row                = table.Rows[1];
            cellPara           = row.Cells[0].AddParagraph();
            row.Cells[0].Width = 500;
            row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
            row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
            row.Cells[0].CellFormat.BackColor          = Color.FromArgb(222, 239, 255);

            txt = cellPara.AppendText("\n Full Name:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            WTextFormField txtField = cellPara.AppendTextFormField("John");
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.TextRange.CharacterFormat.FontSize  = 11f;

            txt = cellPara.AppendText("\n\n Birth Date:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txtField = cellPara.AppendTextFormField("BirthDayField", DateTime.Now.ToString("M/d/yyyy"));
            txtField.StringFormat = "M/d/yyyy";
            txtField.Type         = TextFormFieldType.DateText;
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.TextRange.CharacterFormat.FontSize  = 11f;
            txtField.CharacterFormat.TextColor           = Color.MidnightBlue;
            txtField.CharacterFormat.FontName            = "Arial";
            txtField.CharacterFormat.FontSize            = 11f;

            txt = cellPara.AppendText("\n\n Address:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txtField      = cellPara.AppendTextFormField("221b Baker Street");
            txtField.Type = TextFormFieldType.RegularText;
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.TextRange.CharacterFormat.FontSize  = 11f;

            txt = cellPara.AppendText("\n\n Phone:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txtField = cellPara.AppendTextFormField("(206)555-3412");
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.TextRange.CharacterFormat.FontSize  = 11f;

            txt = cellPara.AppendText("\n\n Email:\t\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txtField = cellPara.AppendTextFormField("*****@*****.**");
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.TextRange.CharacterFormat.FontSize  = 11f;
            cellPara.AppendText("\n");
            #endregion

            section.AddParagraph();

            #region Educational Qualification
            table = section.Body.AddTable();
            table.ResetCells(2, 1);
            table.TableFormat.Paddings.All = 5.4f;
            row                = table.Rows[0];
            row.Height         = 20;
            row.Cells[0].Width = 500;
            cellPara           = row.Cells[0].AddParagraph();
            row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Thick;
            row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
            row.Cells[0].CellFormat.BackColor          = Color.FromArgb(198, 227, 255);
            row.Cells[0].CellFormat.VerticalAlignment  = VerticalAlignment.Middle;
            txt = cellPara.AppendText(" Educational Qualification");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.Bold     = true;
            txt.CharacterFormat.FontSize = 11f;

            row                = table.Rows[1];
            cellPara           = row.Cells[0].AddParagraph();
            row.Cells[0].Width = 500;
            row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
            row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
            row.Cells[0].CellFormat.BackColor          = Color.FromArgb(222, 239, 255);

            txt = cellPara.AppendText("\n Type:\t\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            WDropDownFormField dropField = cellPara.AppendDropDownFormField();
            dropField.DropDownItems.Add("Higher");
            dropField.DropDownItems.Add("Vocational");
            dropField.DropDownItems.Add("Universal");
            dropField.CharacterFormat.TextColor = Color.MidnightBlue;
            dropField.CharacterFormat.FontName  = "Arial";
            dropField.CharacterFormat.FontSize  = 11f;

            txt = cellPara.AppendText("\n\n Institution:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txtField = cellPara.AppendTextFormField("Michigan University");
            txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
            txtField.TextRange.CharacterFormat.FontName  = "Arial";
            txtField.CharacterFormat.FontSize            = 11f;

            txt = cellPara.AppendText("\n\n Programming Languages:");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 11f;
            txt = cellPara.AppendText("\n\n\t C#:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 9f;
            dropField = cellPara.AppendDropDownFormField();
            dropField.DropDownItems.Add("Perfect");
            dropField.DropDownItems.Add("Good");
            dropField.DropDownItems.Add("Excellent");
            dropField.CharacterFormat.TextColor = Color.MidnightBlue;
            dropField.CharacterFormat.FontName  = "Arial";
            dropField.CharacterFormat.FontSize  = 11f;

            txt = cellPara.AppendText("\n\n\t VB:\t\t\t\t");
            txt.CharacterFormat.FontName = "Arial";
            txt.CharacterFormat.FontSize = 9f;
            dropField = cellPara.AppendDropDownFormField();
            dropField.DropDownItems.Add("Perfect");
            dropField.DropDownItems.Add("Good");
            dropField.DropDownItems.Add("Excellent");
            dropField.CharacterFormat.TextColor = Color.MidnightBlue;
            dropField.CharacterFormat.FontName  = "Arial";
            dropField.CharacterFormat.FontSize  = 11f;
            #endregion
            //Protect document
            document.ProtectionType = ProtectionType.AllowOnlyFormFields;
            MemoryStream st = new MemoryStream();
            document.Save(st, FormatType.Doc);
            st.Seek(0, SeekOrigin.Begin);
            #endregion CreateForm

            #region FillForm
            // Create a new document.
            WordDocument       document1 = new WordDocument(st, FormatType.Doc);
            IWSection          sec       = document1.LastSection;
            WTextFormField     textFF;
            WDropDownFormField dropFF;

            //Access the text field
            textFF = sec.Body.FormFields[0] as WTextFormField;

            //Fill value for the textfield
            textFF.TextRange.Text = "John";

            //Access the form field with feild name
            textFF = sec.Body.FormFields["BirthDayField"] as WTextFormField;
            textFF.TextRange.Text = "5.13.1980";

            textFF = sec.Body.FormFields[2] as WTextFormField;
            textFF.TextRange.Text = "221b Baker Street";

            textFF = sec.Body.FormFields[3] as WTextFormField;
            textFF.TextRange.Text = "(206)555-3412";

            textFF = sec.Body.FormFields[4] as WTextFormField;
            textFF.TextRange.Text = "*****@*****.**";

            dropFF = sec.Body.FormFields[5] as WDropDownFormField;

            //Set the value
            dropFF.DropDownSelectedIndex = 1;

            textFF = sec.Body.FormFields[6] as WTextFormField;
            textFF.TextRange.Text = "Michigan University";

            dropFF = sec.Body.FormFields[7] as WDropDownFormField;
            dropFF.DropDownSelectedIndex = 1;

            dropFF = sec.Body.FormFields[8] as WDropDownFormField;
            dropFF.DropDownSelectedIndex = 2;

            //Allow only to fill the form.
            document1.ProtectionType = ProtectionType.AllowOnlyFormFields;
            #endregion FillForm

            #region Document save option
            //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));
            }
            #endregion Document save option
            return(View());
        }
Exemplo n.º 13
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly assembly = typeof(CreateEquation).GetTypeInfo().Assembly;

#if COMMONSB
            string rootPath = "SampleBrowser.Samples.DocIO.Samples.Templates.";
#else
            string rootPath = "SampleBrowser.DocIO.Samples.Templates.";
#endif
            Stream inputStream = assembly.GetManifestResourceStream(rootPath + "CreateEquation.docx");

            // Loads the stream into Word Document.
            WordDocument document = new WordDocument(inputStream, Syncfusion.DocIO.FormatType.Automatic);
            //Gets the last section in the document
            WSection section = document.LastSection;
            //Sets page margins
            document.LastSection.PageSetup.Margins.All = 72;
            //Adds new paragraph to the section
            IWParagraph paragraph = section.AddParagraph();

            //Appends text to paragraph
            IWTextRange textRange = paragraph.AppendText("Mathematical equations");
            textRange.CharacterFormat.FontSize            = 28;
            paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
            paragraph.ParagraphFormat.AfterSpacing        = 12;

            #region Sum to the power of n
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n.");
            //Creates an equation with sum to the power of N
            CreateSumToThePowerOfN(paragraph);
            #endregion

            #region Fourier series
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L");
            //Creates a Fourier series equation
            CreateFourierseries(paragraph);
            #endregion

            #region Triple scalar product
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of triple scalar product");
            //Creates a triple scalar product equation
            CreateTripleScalarProduct(paragraph);
            #endregion

            #region Gamma function
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of gamma function");
            //Creates a gamma function equation
            CreateGammaFunction(paragraph);
            #endregion

            #region Vector relation
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of vector relation ");
            //Creates a vector relation equation
            CreateVectorRelation(paragraph);
            #endregion

            string       filename     = "";
            string       contenttype  = "";
            MemoryStream outputStream = new MemoryStream();
            if (this.pdfButton.IsChecked != null && (bool)this.pdfButton.IsChecked)
            {
                filename    = "CreateEquation.pdf";
                contenttype = "application/pdf";
                DocIORenderer renderer = new DocIORenderer();
                PdfDocument   pdfDoc   = renderer.ConvertToPDF(document);
                pdfDoc.Save(outputStream);
                pdfDoc.Close();
            }
            else
            {
                filename    = "CreateEquation.docx";
                contenttype = "application/msword";
                document.Save(outputStream, FormatType.Docx);
            }
            document.Close();

            if (Device.RuntimePlatform == Device.UWP)
            {
                Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save(filename, contenttype, outputStream);
            }
            else
            {
                Xamarin.Forms.DependencyService.Get <ISave>().Save(filename, contenttype, outputStream);
            }
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
0
        void converter_DrawHeader(object sender, DocHeaderFooterEventArgs e)
        {
            IWTextRange txt = e.Header.AddParagraph().AppendText("\t\t\t\tSyncfusion Inc.\n");

            txt.CharacterFormat.Font = new Font("verdana", 12f, FontStyle.Bold);
        }
        void CreateEndNote(WordDocument document)
        {
            //Add a new section to the document.
            IWSection section = document.AddSection();

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

            IWTextRange textRange = paragraph.AppendText("\t\t\t\t\tDemo for Endnote");

            textRange.CharacterFormat.TextColor = Color.Black;
            textRange.CharacterFormat.Bold      = true;
            textRange.CharacterFormat.FontSize  = 20;

            section.AddParagraph();
            section.AddParagraph();
            paragraph = section.AddParagraph();
            WFootnote footnote = new WFootnote(document);

            footnote = paragraph.AppendFootnote(FootnoteType.Endnote);
            footnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript;

            //Insert Text into the paragraph
            paragraph.AppendText("Google").CharacterFormat.Bold = true;
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
#if NETCORE
            paragraph.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\..\Common\images\DocIO\google.png"));
#else
            paragraph.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\Common\images\DocIO\google.png"));
#endif

            paragraph = footnote.TextBody.AddParagraph();
            paragraph.AppendText(" Google is the most famous search engines in the Word ");

            section           = document.AddSection();
            section.BreakCode = SectionBreakCode.NoBreak;
            //Adding a new paragraph to the section.
            paragraph = section.AddParagraph();

            paragraph = section.AddParagraph();
            footnote  = paragraph.AppendFootnote(FootnoteType.Endnote);
            footnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript;


            //Insert Text into the paragraph
            paragraph.AppendText("Yahoo").CharacterFormat.Bold = true;
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
#if NETCORE
            paragraph.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\..\Common\images\DocIO\yahoo.gif"));
#else
            paragraph.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\Common\images\DocIO\yahoo.gif"));
#endif

            paragraph = footnote.TextBody.AddParagraph();
            paragraph.AppendText(" Yahoo experience makes it easier to discover the news and information that you care about most. ");

            section           = document.AddSection();
            section.BreakCode = SectionBreakCode.NoBreak;
            //Adding a new paragraph to the section.
            paragraph = section.AddParagraph();

            paragraph = section.AddParagraph();
            footnote  = paragraph.AppendFootnote(FootnoteType.Endnote);
            footnote.MarkerCharacterFormat.SubSuperScript = SubSuperScript.SuperScript;

            //Insert Text into the paragraph
            paragraph.AppendText("Northwind Traders").CharacterFormat.Bold = true;
            paragraph = section.AddParagraph();
            paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
#if NETCORE
            paragraph.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\..\Common\images\DocIO\Northwind_logo.png"));
#else
            paragraph.AppendPicture(Image.FromFile(@"..\..\..\..\..\..\..\Common\images\DocIO\Northwind_logo.png"));
#endif
            paragraph = footnote.TextBody.AddParagraph();
            paragraph.AppendText(" The Northwind sample database (Northwind.mdb) is included with all versions of Access. It provides data you can experiment with and database objects that demonstrate features you might want to implement in your own databases ");

            //Set the number format for the Endnote.
            document.EndnoteNumberFormat    = Syncfusion.DocIO.FootEndNoteNumberFormat.LowerCaseRoman;
            document.RestartIndexForEndnote = Syncfusion.DocIO.EndnoteRestartIndex.DoNotRestart;
            //Set the Endnote position.
            document.EndnotePosition = Syncfusion.DocIO.EndnotePosition.DisplayEndOfSection;
        }
Exemplo n.º 17
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            string   resourcePath = "SampleBrowser.Samples.DocIO.Templates.CreateEquation.docx";
            Assembly assembly     = Assembly.GetExecutingAssembly();
            Stream   fileStream   = assembly.GetManifestResourceStream(resourcePath);

            // Loads the stream into Word Document.
            WordDocument document = new WordDocument(fileStream, Syncfusion.DocIO.FormatType.Automatic);
            //Gets the last section in the document
            WSection section = document.LastSection;

            //Sets page margins
            document.LastSection.PageSetup.Margins.All = 72;
            //Adds new paragraph to the section
            IWParagraph paragraph = section.AddParagraph();

            //Appends text to paragraph
            IWTextRange textRange = paragraph.AppendText("Mathematical equations");

            textRange.CharacterFormat.FontSize            = 28;
            paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
            paragraph.ParagraphFormat.AfterSpacing        = 12;

            #region Sum to the power of n
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n.");
            //Creates an equation with sum to the power of N
            CreateSumToThePowerOfN(paragraph);
            #endregion

            #region Fourier series
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L");
            //Creates a Fourier series equation
            CreateFourierseries(paragraph);
            #endregion

            #region Triple scalar product
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of triple scalar product");
            //Creates a triple scalar product equation
            CreateTripleScalarProduct(paragraph);
            #endregion

            #region Gamma function
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of gamma function");
            //Creates a gamma function equation
            CreateGammaFunction(paragraph);
            #endregion

            #region Vector relation
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of vector relation ");
            //Creates a vector relation equation
            CreateVectorRelation(paragraph);
            #endregion

            MemoryStream stream = new MemoryStream();
            //Set file content type
            string contentType = null;
            string fileName    = null;
            if (docxButton.Checked)
            {
                fileName    = "CreateEquation.docx";
                contentType = "application/msword";
                document.Save(stream, FormatType.Docx);
            }
            else
            {
                fileName    = "CreateEquation.pdf";
                contentType = "application/pdf";
                DocIORenderer renderer = new DocIORenderer();
                PdfDocument   pdfDoc   = renderer.ConvertToPDF(document);
                pdfDoc.Save(stream);

                pdfDoc.Close();
            }

            document.Dispose();
            if (stream != null)
            {
                SaveAndroid androidSave = new SaveAndroid();
                androidSave.Save(fileName, contentType, stream, m_context);
            }
        }
Exemplo n.º 18
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Creates a new word document instance
                WordDocument document = new WordDocument();
                //Adds new section to the document
                IWSection section = document.AddSection();
                //Sets page margins
                document.LastSection.PageSetup.Margins.All = 72;
                //Adds new paragraph to the section
                IWParagraph paragraph = section.AddParagraph();

                //Appends text to paragraph
                IWTextRange textRange = paragraph.AppendText("Mathematical equations");
                textRange.CharacterFormat.FontSize            = 28;
                paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                paragraph.ParagraphFormat.AfterSpacing        = 12;

                #region Sum to the power of n
                //Adds new paragraph to the section
                paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n.");
                //Creates an equation with sum to the power of N
                CreateSumToThePowerOfN(paragraph);
                #endregion

                #region Fourier series
                //Adds new paragraph to the section
                paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L");
                //Creates a Fourier series equation
                CreateFourierseries(paragraph);
                #endregion

                #region Triple scalar product
                //Adds new paragraph to the section
                paragraph = AddParagraph(section, "This is an expansion of triple scalar product");
                //Creates a triple scalar product equation
                CreateTripleScalarProduct(paragraph);
                #endregion

                #region Gamma function
                //Adds new paragraph to the section
                paragraph = AddParagraph(section, "This is an expansion of gamma function");
                //Creates a gamma function equation
                CreateGammaFunction(paragraph);
                #endregion

                #region Vector relation
                //Adds new paragraph to the section
                paragraph = AddParagraph(section, "This is an expansion of vector relation ");
                //Creates a vector relation equation
                CreateVectorRelation(paragraph);
                #endregion

                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());
                    }
                }

                // Exit
                this.Close();
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 19
0
        void OnButtonClicked(object sender, EventArgs e)
        {
            Assembly     assembly = Assembly.GetExecutingAssembly();
            WordDocument document = null;

            if (encryptDocument.Checked == true)
            {
                //create worddocument instances
                document = new WordDocument();

                document.EnsureMinimal();

                // Getting last section of the document.
                IWSection section = document.LastSection;

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

                // Writing text
                IWTextRange text = paragraph.AppendText("This document was encrypted with password");
                text.CharacterFormat.FontSize = 16f;
                text.CharacterFormat.FontName = "Bitstream Vera Serif";

                // Encrypt the document by giving password
                document.EncryptDocument("syncfusion");
            }
            else
            {
                // Open an existing template document with single section.
                document = new WordDocument();
                Stream inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Security Settings.docx");
                // Open an existing template document.
                document.Open(inputStream, FormatType.Docx, "syncfusion");
                inputStream.Dispose();

                // Getting last section of the document.
                IWSection section = document.LastSection;

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

                // Writing text
                IWTextRange text = paragraph.AppendText("\nDemo For Document Decryption with Essential DocIO");
                text.CharacterFormat.FontSize = 16f;
                text.CharacterFormat.FontName = "Bitstream Vera Serif";

                text = paragraph.AppendText("\nThis document is Decrypted");
                text.CharacterFormat.FontSize = 16f;
                text.CharacterFormat.FontName = "Bitstream Vera Serif";
            }
            MemoryStream ms = new MemoryStream();

            //Set file content type
            string contentType = null;
            string fileName    = null;

            //Save the document as docx
            fileName    = "Encrypt and Decrypt.docx";
            contentType = "application/msword";
            document.Save(ms, FormatType.Docx);
            document.Dispose();

            if (ms != null)
            {
                SaveAndroid androidSave = new SaveAndroid();
                androidSave.Save(fileName, contentType, ms, m_context);
            }
        }
Exemplo n.º 20
0
        private void Bwprint_DoWork(object sender, DoWorkEventArgs e)
        {
            if (done)
            {
                try
                {
                    WordDocument document = new WordDocument(System.Windows.Forms.Application.StartupPath + @"\Samples\defaulters_sample.docx", FormatType.Docx);

                    var schoolname = db.Randoms.Where(c => c.ID == 1).FirstOrDefault();
                    var address    = db.Randoms.Where(c => c.ID == 2).FirstOrDefault();
                    var contact    = db.Randoms.Where(c => c.ID == 3).FirstOrDefault();
                    var email      = db.Randoms.Where(c => c.ID == 4).FirstOrDefault();

                    #region SchoolName
                    TextSelection textSelection = document.Find("{SchoolName}", false, true);
                    IWTextRange   textRange     = textSelection.GetAsOneRange();

                    //Modifies the text

                    textRange.Text = schoolname.Text.ToString();
                    textRange.CharacterFormat.FontName = "Times New Roman";
                    #endregion

                    #region Address
                    textSelection = document.Find("{Address}", false, true);
                    WTextRange addr = textSelection.GetAsOneRange();

                    addr.Text = address.Text.ToString();

                    #endregion

                    #region Contact
                    textSelection = document.Find("{Contact}", false, true);
                    WTextRange con = textSelection.GetAsOneRange();

                    con.Text = contact.Text.ToString();
                    #endregion

                    #region Email
                    textSelection = document.Find("{Email}", false, true);
                    WTextRange Email = textSelection.GetAsOneRange();

                    Email.Text = email.Text.ToString();
                    #endregion

                    #region Class Section
                    textSelection = document.Find("{ClassSection}", false, true);
                    WTextRange classsection = textSelection.GetAsOneRange();

                    classsection.Text = comboboxclass.Text + " " + comboboxsection.Text;
                    #endregion

                    #region Month Year
                    textSelection = document.Find("{MonthYear}", false, true);

                    WTextRange MonthYear = textSelection.GetAsOneRange();

                    MonthYear.Text = DateTime.Now.ToString("MMMM yyyy");
                    #endregion

                    #region Total Defaulters
                    textSelection = document.Find("{Defaulters}", false, true);

                    WTextRange Defaulters = textSelection.GetAsOneRange();

                    Defaulters.Text = DefaultArray.ToArray().Length.ToString();
                    #endregion



                    IWSection section = document.Sections[0];
                    IWTable   table   = section.AddTable();

                    ArrayList namearray    = new ArrayList();
                    ArrayList Fatherarray  = new ArrayList();
                    ArrayList montharray   = new ArrayList();
                    ArrayList arrearsarray = new ArrayList();

                    for (int i = 0; i <= DefaultArray.ToArray().Length - 1; i++)
                    {
                        int ids  = (Convert.ToInt32(DefaultArray[i]));
                        var data = db.StudentDatas.Where(c => c.ID == ids).FirstOrDefault();
                        namearray.Add(data.StudentName.ToString());
                        Fatherarray.Add(data.FatherName.ToString());

                        var list  = db.StudentFees.Where(c => c.ID == data.ID).FirstOrDefault();
                        int month = TutionFee((Convert.ToInt32(DefaultArray[i]))) + list.TransportFee + list.ExamFee + list.OthersFee;

                        montharray.Add(month.ToString());

                        arrearsarray.Add(list.Arrears.ToString());
                    }

                    table.ResetCells(DefaultArray.ToArray().Length + 1, 4);

                    //Header 1
                    IWParagraph wParagraph = table[0, 0].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                    textRange = wParagraph.AppendText("Student’s Name");
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = true;


                    //Header 2
                    wParagraph = table[0, 1].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                    textRange = wParagraph.AppendText("Father's Name");
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = true;

                    //Header 3
                    wParagraph = table[0, 2].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    textRange = wParagraph.AppendText("This Month");
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = true;

                    //Header 4
                    wParagraph = table[0, 3].AddParagraph();
                    wParagraph.ParagraphFormat.AfterSpacing        = 2f;
                    wParagraph.ParagraphFormat.BeforeSpacing       = 2f;
                    wParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                    textRange = wParagraph.AppendText("Arrears");
                    textRange.CharacterFormat.FontName = "Century Gothic";
                    textRange.CharacterFormat.FontSize = 9;
                    textRange.CharacterFormat.Bold     = true;


                    for (int i = 0; i <= DefaultArray.ToArray().Length - 1; i++)
                    {
                        int         index     = i + 1;
                        IWParagraph Paragraph = table[index, 0].AddParagraph();
                        Paragraph.ParagraphFormat.AfterSpacing        = 2f;
                        Paragraph.ParagraphFormat.BeforeSpacing       = 2f;
                        Paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                        textRange = Paragraph.AppendText(namearray[i].ToString());
                        textRange.CharacterFormat.FontName = "Century Gothic";
                        textRange.CharacterFormat.FontSize = 9;
                        textRange.CharacterFormat.Bold     = false;

                        Paragraph = table[index, 1].AddParagraph();
                        Paragraph.ParagraphFormat.AfterSpacing        = 2f;
                        Paragraph.ParagraphFormat.BeforeSpacing       = 2f;
                        Paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left;
                        textRange = Paragraph.AppendText(Fatherarray[i].ToString());
                        textRange.CharacterFormat.FontName = "Century Gothic";
                        textRange.CharacterFormat.FontSize = 9;
                        textRange.CharacterFormat.Bold     = false;

                        Paragraph = table[index, 2].AddParagraph();
                        Paragraph.ParagraphFormat.AfterSpacing        = 2f;
                        Paragraph.ParagraphFormat.BeforeSpacing       = 2f;
                        Paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                        textRange = Paragraph.AppendText("Rs. " + montharray[i].ToString());
                        textRange.CharacterFormat.FontName = "Century Gothic";
                        textRange.CharacterFormat.FontSize = 9;
                        textRange.CharacterFormat.Bold     = false;

                        Paragraph = table[index, 3].AddParagraph();
                        Paragraph.ParagraphFormat.AfterSpacing        = 2f;
                        Paragraph.ParagraphFormat.BeforeSpacing       = 2f;
                        Paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                        textRange = Paragraph.AppendText("Rs. " + arrearsarray[i].ToString());
                        textRange.CharacterFormat.FontName = "Century Gothic";
                        textRange.CharacterFormat.FontSize = 9;
                        textRange.CharacterFormat.Bold     = false;
                    }


                    //Saves the document in the given name and format

                    string savepath = "DefaulterList-" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".docx";
                    document.Save(savepath, FormatType.Docx);

                    //Releases the resources occupied by WordDocument instance

                    document.Close();

                    PrintWord(System.Windows.Forms.Application.StartupPath + @"\" + savepath, "Microsoft Print to PDF");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString(), "Error - Student Management System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 21
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // 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();


                #region Document formatting
                //Set background color.
                document.Background.Gradient.Color1         = Color.FromArgb(232, 232, 232);
                document.Background.Gradient.Color2         = Color.FromArgb(255, 255, 255);
                document.Background.Type                    = BackgroundType.Gradient;
                document.Background.Gradient.ShadingStyle   = GradientShadingStyle.Horizontal;
                document.Background.Gradient.ShadingVariant = GradientShadingVariant.ShadingDown;

                section.PageSetup.Margins.All = 72f;
                section.PageSetup.PageSize    = new SizeF(612, 792);

                #endregion

                #region Title Section
                IWTable table = section.Body.AddTable();
                table.ResetCells(1, 2);

                WTableRow row = table.Rows[0];
                row.Height = 25f;

                IWParagraph cellPara = row.Cells[0].AddParagraph();
                Image       img      = Image.FromFile(@"..\..\..\..\..\..\..\Common\images\DocIO\Image.jpg");
                IWPicture   pic      = cellPara.AppendPicture(img);
                pic.Height = 80;
                pic.Width  = 180;

                cellPara = row.Cells[1].AddParagraph();
                row.Cells[1].CellFormat.VerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                row.Cells[1].CellFormat.BackColor         = Color.FromArgb(173, 215, 255);
                IWTextRange txt = cellPara.AppendText("Job Application Form");
                cellPara.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                txt.CharacterFormat.Bold     = true;
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 18f;

                row.Cells[0].Width = 200;
                row.Cells[1].Width = 300;
                row.Cells[1].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
                #endregion

                section.AddParagraph();

                #region General Information
                table = section.Body.AddTable();
                table.TableFormat.Paddings.All = 5.4f;
                table.ResetCells(2, 1);
                row                = table.Rows[0];
                row.Height         = 20;
                row.Cells[0].Width = 500;
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Thick;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(198, 227, 255);
                row.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                txt = cellPara.AppendText(" General Information");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.Bold     = true;
                txt.CharacterFormat.FontSize = 11f;

                row                = table.Rows[1];
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].Width = 500;
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(222, 239, 255);

                txt = cellPara.AppendText("\n Full Name:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                WTextFormField txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Birth Date:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField("BirthDayField", DateTime.Now.ToString("M/d/yyyy"));
                txtField.StringFormat = "M/d/yyyy";
                txtField.Type         = TextFormFieldType.DateText;
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;
                txtField.CharacterFormat.TextColor           = Color.MidnightBlue;
                txtField.CharacterFormat.FontName            = "Arial";
                txtField.CharacterFormat.FontSize            = 11f;

                txt = cellPara.AppendText("\n\n Address:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField      = cellPara.AppendTextFormField(null);
                txtField.Type = TextFormFieldType.RegularText;
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Phone:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Email:\t\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.TextRange.CharacterFormat.FontSize  = 11f;
                cellPara.AppendText("\n");
                #endregion

                section.AddParagraph();

                #region Educational Qualification
                table = section.Body.AddTable();
                table.TableFormat.Paddings.All = 5.4f;
                table.ResetCells(2, 1);
                row                = table.Rows[0];
                row.Height         = 20;
                row.Cells[0].Width = 500;
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Thick;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(198, 227, 255);
                row.Cells[0].CellFormat.VerticalAlignment  = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                txt = cellPara.AppendText(" Educational Qualification");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.Bold     = true;
                txt.CharacterFormat.FontSize = 11f;

                row                = table.Rows[1];
                cellPara           = row.Cells[0].AddParagraph();
                row.Cells[0].Width = 500;
                row.Cells[0].CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Hairline;
                row.Cells[0].CellFormat.Borders.Color      = Color.FromArgb(155, 205, 255);
                row.Cells[0].CellFormat.BackColor          = Color.FromArgb(222, 239, 255);

                txt = cellPara.AppendText("\n Type:\t\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                WDropDownFormField dropField = cellPara.AppendDropDownFormField();
                dropField.DropDownItems.Add("Higher");
                dropField.DropDownItems.Add("Vocational");
                dropField.DropDownItems.Add("Universal");
                dropField.CharacterFormat.TextColor = Color.MidnightBlue;
                dropField.CharacterFormat.FontName  = "Arial";
                dropField.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n Institution:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txtField = cellPara.AppendTextFormField(null);
                txtField.TextRange.CharacterFormat.TextColor = Color.MidnightBlue;
                txtField.TextRange.CharacterFormat.FontName  = "Arial";
                txtField.CharacterFormat.FontSize            = 11f;

                txt = cellPara.AppendText("\n\n Programming Languages:");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 11f;
                txt = cellPara.AppendText("\n\n\t C#:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 9f;
                dropField = cellPara.AppendDropDownFormField();
                dropField.DropDownItems.Add("Perfect");
                dropField.DropDownItems.Add("Good");
                dropField.DropDownItems.Add("Excellent");
                dropField.CharacterFormat.TextColor = Color.MidnightBlue;
                dropField.CharacterFormat.FontName  = "Arial";
                dropField.CharacterFormat.FontSize  = 11f;

                txt = cellPara.AppendText("\n\n\t VB:\t\t\t\t");
                txt.CharacterFormat.FontName = "Arial";
                txt.CharacterFormat.FontSize = 9f;
                dropField = cellPara.AppendDropDownFormField();
                dropField.DropDownItems.Add("Perfect");
                dropField.DropDownItems.Add("Good");
                dropField.DropDownItems.Add("Excellent");
                dropField.CharacterFormat.TextColor = Color.MidnightBlue;
                dropField.CharacterFormat.FontName  = "Arial";
                dropField.CharacterFormat.FontSize  = 11f;
                #endregion

                btnFill.Enabled = true;

                //Protect document
                document.ProtectionType = ProtectionType.AllowOnlyFormFields;
                document.Save("Sample.doc", FormatType.Doc);
                //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]
                        System.Diagnostics.Process.Start("Sample.doc");
                        //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]
                            System.Diagnostics.Process.Start("Sample.docx");
                            //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
                        {
                            System.Diagnostics.Process.Start("Sample.pdf");
                            //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);
            }
        }
Exemplo n.º 22
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //Initialize Word document
                WordDocument doc = new WordDocument();
                //Ensure Minimum
                doc.EnsureMinimal();
                //Append AutoShape
                Shape shape = doc.LastParagraph.AppendShape(AutoShapeType.RoundedRectangle, 130, 45);
                //Set horizontal alignment
                shape.HorizontalAlignment = ShapeHorizontalAlignment.Center;
                //Set horizontal origin
                shape.HorizontalOrigin = HorizontalOrigin.Page;
                //Set vertical origin
                shape.VerticalOrigin = VerticalOrigin.Page;
                //Set vertical position
                shape.VerticalPosition = 50;
                //Set AllowOverlap to true for overlapping shapes
                shape.WrapFormat.AllowOverlap = true;
                //Set Fill Color
                shape.FillFormat.Color = Color.Blue;
                //Set Content vertical alignment
                shape.TextFrame.TextVerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                //Add Texbody contents to Shape
                IWParagraph para = shape.TextBody.AddParagraph();
                para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                IWTextRange textRange = para.AppendText("Requirement");
                textRange.CharacterFormat.Bold      = true;
                textRange.CharacterFormat.TextColor = Color.White;
                textRange.CharacterFormat.FontSize  = 12;
                textRange.CharacterFormat.FontName  = "Verdana";

                shape = doc.LastParagraph.AppendShape(AutoShapeType.DownArrow, 45, 45);
                shape.HorizontalAlignment     = ShapeHorizontalAlignment.Center;
                shape.HorizontalOrigin        = HorizontalOrigin.Page;
                shape.VerticalOrigin          = VerticalOrigin.Page;
                shape.VerticalPosition        = 95;
                shape.WrapFormat.AllowOverlap = true;

                shape = doc.LastParagraph.AppendShape(AutoShapeType.RoundedRectangle, 130, 45);
                shape.HorizontalAlignment             = ShapeHorizontalAlignment.Center;
                shape.HorizontalOrigin                = HorizontalOrigin.Page;
                shape.VerticalOrigin                  = VerticalOrigin.Page;
                shape.VerticalPosition                = 140;
                shape.WrapFormat.AllowOverlap         = true;
                shape.FillFormat.Color                = Color.Orange;
                shape.TextFrame.TextVerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                para = shape.TextBody.AddParagraph();
                para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                textRange = para.AppendText("Design");
                textRange.CharacterFormat.Bold      = true;
                textRange.CharacterFormat.TextColor = Color.White;
                textRange.CharacterFormat.FontSize  = 12;
                textRange.CharacterFormat.FontName  = "Verdana";

                shape = doc.LastParagraph.AppendShape(AutoShapeType.DownArrow, 45, 45);
                shape.HorizontalAlignment     = ShapeHorizontalAlignment.Center;
                shape.HorizontalOrigin        = HorizontalOrigin.Page;
                shape.VerticalOrigin          = VerticalOrigin.Page;
                shape.VerticalPosition        = 185;
                shape.WrapFormat.AllowOverlap = true;

                shape = doc.LastParagraph.AppendShape(AutoShapeType.RoundedRectangle, 130, 45);
                shape.HorizontalAlignment             = ShapeHorizontalAlignment.Center;
                shape.HorizontalOrigin                = HorizontalOrigin.Page;
                shape.VerticalOrigin                  = VerticalOrigin.Page;
                shape.VerticalPosition                = 230;
                shape.WrapFormat.AllowOverlap         = true;
                shape.FillFormat.Color                = Color.Blue;
                shape.TextFrame.TextVerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                para = shape.TextBody.AddParagraph();
                para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                textRange = para.AppendText("Execution");
                textRange.CharacterFormat.Bold      = true;
                textRange.CharacterFormat.TextColor = Color.White;
                textRange.CharacterFormat.FontSize  = 12;
                textRange.CharacterFormat.FontName  = "Verdana";

                shape = doc.LastParagraph.AppendShape(AutoShapeType.DownArrow, 45, 45);
                shape.HorizontalAlignment     = ShapeHorizontalAlignment.Center;
                shape.HorizontalOrigin        = HorizontalOrigin.Page;
                shape.VerticalOrigin          = VerticalOrigin.Page;
                shape.VerticalPosition        = 275;
                shape.WrapFormat.AllowOverlap = true;

                shape = doc.LastParagraph.AppendShape(AutoShapeType.RoundedRectangle, 130, 45);
                shape.HorizontalAlignment             = ShapeHorizontalAlignment.Center;
                shape.HorizontalOrigin                = HorizontalOrigin.Page;
                shape.VerticalOrigin                  = VerticalOrigin.Page;
                shape.VerticalPosition                = 320;
                shape.WrapFormat.AllowOverlap         = true;
                shape.FillFormat.Color                = Color.Violet;
                shape.TextFrame.TextVerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                para = shape.TextBody.AddParagraph();
                para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                textRange = para.AppendText("Testing");
                textRange.CharacterFormat.Bold      = true;
                textRange.CharacterFormat.TextColor = Color.White;
                textRange.CharacterFormat.FontSize  = 12;
                textRange.CharacterFormat.FontName  = "Verdana";

                shape = doc.LastParagraph.AppendShape(AutoShapeType.DownArrow, 45, 45);
                shape.HorizontalAlignment     = ShapeHorizontalAlignment.Center;
                shape.HorizontalOrigin        = HorizontalOrigin.Page;
                shape.VerticalOrigin          = VerticalOrigin.Page;
                shape.VerticalPosition        = 365;
                shape.WrapFormat.AllowOverlap = true;

                shape = doc.LastParagraph.AppendShape(AutoShapeType.RoundedRectangle, 130, 45);
                shape.HorizontalAlignment             = ShapeHorizontalAlignment.Center;
                shape.HorizontalOrigin                = HorizontalOrigin.Page;
                shape.VerticalOrigin                  = VerticalOrigin.Page;
                shape.VerticalPosition                = 410;
                shape.WrapFormat.AllowOverlap         = true;
                shape.FillFormat.Color                = Color.PaleVioletRed;
                shape.TextFrame.TextVerticalAlignment = Syncfusion.DocIO.DLS.VerticalAlignment.Middle;
                para = shape.TextBody.AddParagraph();
                para.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center;
                textRange = para.AppendText("Release");
                textRange.CharacterFormat.Bold      = true;
                textRange.CharacterFormat.TextColor = Color.White;
                textRange.CharacterFormat.FontSize  = 12;
                textRange.CharacterFormat.FontName  = "Verdana";

                //Save as docx format
                if (wordDocxRadioBtn.Checked)
                {
                    //Saving the document as .docx
                    doc.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(doc);
                    //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);
            }
        }
Exemplo n.º 23
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Creating a new document.
                WordDocument document = new WordDocument();
                document.EnsureMinimal();
                //Set Margin of the document
                document.LastSection.PageSetup.Margins.All = 72;
                // Reading Arabic text from text file.
#if NETCORE
                StreamReader s = new StreamReader(@"..\..\..\..\..\..\..\common\Data\DocIO\Arabic.txt", System.Text.Encoding.ASCII);
#else
                StreamReader s = new StreamReader(@"..\..\..\..\..\..\common\Data\DocIO\Arabic.txt", System.Text.Encoding.ASCII);
#endif
                string text = s.ReadToEnd();

                // Appending Arabic text to the document.
                document.LastParagraph.ParagraphFormat.Bidi = true;
                IWTextRange txtRange = document.LastParagraph.AppendText(text);
                txtRange.CharacterFormat.Bidi = true;

                // Set the RTL text font size.
                txtRange.CharacterFormat.FontSizeBidi = 16;

                //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);
                    document.Close();
                    converter.Dispose();
                    //Save the pdf file
                    pdfDoc.Save("Sample.pdf");
                    pdfDoc.Close(true);
                    //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);
            }
        }
Exemplo n.º 24
0
        public IActionResult CreateEquation(string Button)
        {
            if (Button == null)
            {
                return(View());
            }

            //Creates a new word document instance
            WordDocument document = new WordDocument();
            //Adds new section to the document
            IWSection section = document.AddSection();

            //Sets page margins
            document.LastSection.PageSetup.Margins.All = 72;
            //Adds new paragraph to the section
            IWParagraph paragraph = section.AddParagraph();

            //Appends text to paragraph
            IWTextRange textRange = paragraph.AppendText("Mathematical equations");

            textRange.CharacterFormat.FontSize            = 28;
            paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
            paragraph.ParagraphFormat.AfterSpacing        = 12;

            #region Sum to the power of n
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of the sum (1+X) to the power of n.");
            //Creates an equation with sum to the power of N
            CreateSumToThePowerOfN(paragraph);
            #endregion

            #region Fourier series
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is a Fourier series for the function of period 2L");
            //Creates a Fourier series equation
            CreateFourierseries(paragraph);
            #endregion

            #region Triple scalar product
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of triple scalar product");
            //Creates a triple scalar product equation
            CreateTripleScalarProduct(paragraph);
            #endregion

            #region Gamma function
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of gamma function");
            //Creates a gamma function equation
            CreateGammaFunction(paragraph);
            #endregion

            #region Vector relation
            //Adds new paragraph to the section
            paragraph = AddParagraph(section, "This is an expansion of vector relation ");
            //Creates a vector relation equation
            CreateVectorRelation(paragraph);
            #endregion

            FormatType type        = FormatType.Docx;
            string     filename    = "Sample.docx";
            string     contenttype = "application/vnd.ms-word.document.12";

            MemoryStream ms = new MemoryStream();
            document.Save(ms, type);
            document.Close();
            ms.Position = 0;
            return(File(ms, contenttype, filename));
        }
Exemplo n.º 25
0
        /// <summary>
        /// Encrypt the selected Word document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.txtEncryptSource.Text != null && this.txtEncryptSource.Text != "")
            {
                WordDocument document = new WordDocument(this.txtEncryptSource.Text);

                // Getting last section of the document.
                IWSection section = document.LastSection;

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

                // Writing text
                IWTextRange text = paragraph.AppendText("This document was encrypted with password");
                text.CharacterFormat.FontSize = 16f;
                text.CharacterFormat.FontName = "Bitstream Vera Serif";

                // Encrypt the document by giving password
                document.EncryptDocument(txtEnOpen.Text);

                # region Save Document
                //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());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
                # endregion
            }
        public ActionResult DocumentSettings(string Group1)
        {
            if (Group1 == null)
            {
                return(View());
            }
            //A new document is created.
            WordDocument document = new WordDocument();

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

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

            #region DocVariable
            string name    = "John Smith";
            string address = "Cary, NC";
            //Get the variables in the existing document
            DocVariables dVariable = document.Variables;
            //Add doc variables
            dVariable.Add("Customer Name", name);
            dVariable.Add("Customer Address", address);
            #endregion DocVariable

            #region Document Properties
            //Setting document Properties
            document.BuiltinDocumentProperties.Author          = "Essential DocIO";
            document.BuiltinDocumentProperties.ApplicationName = "Essential DocIO";
            document.BuiltinDocumentProperties.Category        = "Document Generator";
            document.BuiltinDocumentProperties.Comments        = "This document was generated using Essential DocIO";
            document.BuiltinDocumentProperties.Company         = "Syncfusion Inc";
            document.BuiltinDocumentProperties.Subject         = "Native Word Generator";
            document.BuiltinDocumentProperties.Keywords        = "Syncfusion";
            document.BuiltinDocumentProperties.Manager         = "Sync Manager";
            document.BuiltinDocumentProperties.Title           = "Essential DocIO";

            // Add a custom document Property
            document.CustomDocumentProperties.Add("My_Doc_Date", DateTime.Today);
            document.CustomDocumentProperties.Add("My_Doc", true);
            document.CustomDocumentProperties.Add("My_ID", 1031);
            document.CustomDocumentProperties.Add("My_Comment", "Essential DocIO");
            //Remove a custome property
            document.CustomDocumentProperties.Remove("My_Doc");
            #endregion Document Properties

            IWTextRange text = paragraph.AppendText("");
            text.CharacterFormat.FontName = "Calibri";
            text.CharacterFormat.FontSize = 13;
            text = paragraph.AppendText("This document is created with various Document Properties Summary Information and page settings information \n\n You can view Document Properties through: File -> Properties -> Summary/Custom.");
            text.CharacterFormat.FontName = "Calibri";
            text.CharacterFormat.FontSize = 13;

            #region Page setup
            // Write section properties
            section.PageSetup.PageSize             = new System.Drawing.SizeF(500, 750);
            section.PageSetup.Orientation          = PageOrientation.Landscape;
            section.PageSetup.Margins.Bottom       = 100;
            section.PageSetup.Margins.Top          = 100;
            section.PageSetup.Margins.Left         = 50;
            section.PageSetup.Margins.Right        = 50;
            section.PageSetup.PageBordersApplyType = PageBordersApplyType.AllPages;
            section.PageSetup.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.DoubleWave;
            section.PageSetup.Borders.Color        = System.Drawing.Color.DarkBlue;
            section.PageSetup.VerticalAlignment    = PageAlignment.Middle;
            #endregion Page setup

            paragraph = section.AddParagraph();
            text      = paragraph.AppendText("");
            text.CharacterFormat.FontName = "Calibri";
            text.CharacterFormat.FontSize = 13;

            text = paragraph.AppendText("\n\n You can view Page setup options through File -> PageSetup.");
            text.CharacterFormat.FontName = "Calibri";
            text.CharacterFormat.FontSize = 13;

            #region Get document variables
            paragraph = document.LastSection.AddParagraph();
            dVariable = document.Variables;
            text      = paragraph.AppendText("\n\n Document Variables\n");
            text.CharacterFormat.FontName = "Calibri";
            text.CharacterFormat.FontSize = 13;
            text.CharacterFormat.Bold     = true;
            text = paragraph.AppendText("\n" + dVariable.GetNameByIndex(1) + ": " + dVariable.GetValueByIndex(1));
            text.CharacterFormat.FontName = "Calibri";
            text.CharacterFormat.FontSize = 13;
            //Display the current variable count
            text = paragraph.AppendText("\n\nDocument Variables Count: " + dVariable.Count);
            text.CharacterFormat.FontName = "Calibri";
            text.CharacterFormat.FontSize = 13;
            #endregion Get document variables

            //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));
            }
            return(View());
        }
Exemplo n.º 27
0
        /// <summary>
        /// Encrypt the word document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void encrypt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (this.textBox1.Text != null && this.textBox1.Text != string.Empty)
                {
                    WordDocument document = new WordDocument(this.textBox1.Text);

                    // Getting last section of the document.
                    IWSection section = document.LastSection;

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

                    // Writing text
                    IWTextRange text = paragraph.AppendText("This document was encrypted with password");
                    text.CharacterFormat.FontSize = 16f;
                    text.CharacterFormat.FontName = "Bitstream Vera Serif";

                    // Encrypt the document by giving password
                    document.EncryptDocument(this.passwordBox1.Password);

                    # region Save Document
                    //Save as doc format
                    if (worddoc.IsChecked.Value)
                    {
                        try
                        {
                            //Saving the document to disk.
                            document.Save("Sample.doc");

                            //Message box confirmation to view the created document.
                            if (MessageBox.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.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.doc")
                                    {
                                        UseShellExecute = true
                                    };
                                    process.Start();
#else
                                    System.Diagnostics.Process.Start("Sample.doc");
#endif
                                    //Exit
                                    this.Close();
                                }
                                catch (Win32Exception ex)
                                {
                                    MessageBox.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                                    Console.WriteLine(ex.ToString());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (ex is IOException)
                            {
                                MessageBox.Show("Please close the file (" + Directory.GetCurrentDirectory() + "\\Sample.doc" + ") then try generating the document.", "File is already open",
                                                MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                            else
                            {
                                MessageBox.Show("Document could not be generated, Could you please email the error details to [email protected] for trouble shooting" + "\r\n" + ex.ToString(), "Error",
                                                MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                    }

                    //Save as docx format
                    else if (worddocx.IsChecked.Value)
                    {
                        try
                        {
                            //Saving the document as .docx
                            document.Save("Sample.docx", FormatType.Docx);
                            //Message box confirmation to view the created document.
                            if (MessageBox.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.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)
                                {
                                    MessageBox.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system");
                                    Console.WriteLine(ex.ToString());
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (ex is IOException)
                            {
                                MessageBox.Show("Please close the file (" + Directory.GetCurrentDirectory() + "\\Sample.doc" + ") then try generating the document.", "File is already open",
                                                MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                            else
                            {
                                MessageBox.Show("Document could not be generated, Could you please email the error details to [email protected] for trouble shooting" + "\r\n" + ex.ToString(), "Error",
                                                MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        }
                    }
                    else
                    {
                        // Exit
                        this.Close();
                    }
                    # endregion
                }
                else
                {
                    MessageBox.Show("Please browse a Word document to encrypt");
                }
            }
Exemplo n.º 28
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);
            }
        }
Exemplo n.º 29
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            try
            {
                //A new document is created.
                WordDocument document = new WordDocument();

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

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

                #region DocVariable
                string name    = "John Smith";
                string address = "Cary, NC";
                //Get the variables in the existing document
                DocVariables dVariable = document.Variables;
                //Add doc variables
                dVariable.Add("Customer Name", name);
                dVariable.Add("Customer Address", address);
                #endregion DocVariable

                #region Document Properties
                //Setting document Properties
                document.BuiltinDocumentProperties.Author          = "Essential DocIO";
                document.BuiltinDocumentProperties.ApplicationName = "Essential DocIO";
                document.BuiltinDocumentProperties.Category        = "Document Generator";
                document.BuiltinDocumentProperties.Comments        = "This document was generated using Essential DocIO";
                document.BuiltinDocumentProperties.Company         = "Syncfusion Inc";
                document.BuiltinDocumentProperties.Subject         = "Native Word Generator";
                document.BuiltinDocumentProperties.Keywords        = "Syncfusion";
                document.BuiltinDocumentProperties.Manager         = "Sync Manager";
                document.BuiltinDocumentProperties.Title           = "Essential DocIO";

                // Add a custom document Property
                document.CustomDocumentProperties.Add("My_Doc_Date", DateTime.Today);
                document.CustomDocumentProperties.Add("My_Doc", true);
                document.CustomDocumentProperties.Add("My_ID", 1031);
                document.CustomDocumentProperties.Add("My_Comment", "Essential DocIO");
                //Remove a custome property
                document.CustomDocumentProperties.Remove("My_Doc");

                #endregion


                IWTextRange text = paragraph.AppendText("");
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;
                text = paragraph.AppendText("This document is created with various Document Properties Summary Information and page settings information \n\n You can view Document Properties through: File -> Properties -> Summary/Custom.");
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;


                #region Page setup

                // Write section properties
                section.PageSetup.PageSize             = new SizeF(500, 750);
                section.PageSetup.Orientation          = PageOrientation.Landscape;
                section.PageSetup.Margins.Bottom       = 100;
                section.PageSetup.Margins.Top          = 100;
                section.PageSetup.Margins.Left         = 50;
                section.PageSetup.Margins.Right        = 50;
                section.PageSetup.PageBordersApplyType = PageBordersApplyType.AllPages;
                section.PageSetup.Borders.BorderType   = Syncfusion.DocIO.DLS.BorderStyle.DoubleWave;
                section.PageSetup.Borders.Color        = Color.DarkBlue;
                section.PageSetup.VerticalAlignment    = PageAlignment.Middle;

                #endregion

                paragraph = section.AddParagraph();
                text      = paragraph.AppendText("");
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;
                text = paragraph.AppendText("\n\n You can view Page setup options through File -> PageSetup.");
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;

                #region Get document variables
                paragraph = document.LastSection.AddParagraph();
                dVariable = document.Variables;
                text      = paragraph.AppendText("\n\n Document Variables\n");
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;
                text.CharacterFormat.Bold     = true;
                text = paragraph.AppendText("\n" + dVariable.GetNameByIndex(1) + ": " + dVariable.GetValueByIndex(1));
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;
                //Display the current variable count
                text = paragraph.AppendText("\n\nDocument Variables Count: " + dVariable.Count);
                text.CharacterFormat.FontName = "Calibri";
                text.CharacterFormat.FontSize = 13;

                #endregion Get document variables

                //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());
                        }
                    }
                }
                else
                {
                    // Exit
                    this.Close();
                }
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message);
            }
        }
Exemplo n.º 30
0
        public async Task <IActionResult> GenerateDocument(int Id, string tokenId)
        {
            var LabTest = _context.TblLabTests
                          .Include(x => x.MethodNavigation)
                          .Include(x => x.BiodataNavigation)
                          .Include(x => x.BiodataNavigation.GenderNavigation)
                          .Include(x => x.TblLabTestsIndicatorsValues)
                          .Include(x => x.TblLabTestsSpecimen)
                          .FirstOrDefault(x => x.Id == Id);

            if (LabTest == null)
            {
                return(NotFound());
            }

            //Loads or opens an existing word document through Open method of WordDocument class
            Stream fs = new FileStream("Templates/result.docx", FileMode.Open, FileAccess.Read, FileShare.Read);

            WordDocument document = new WordDocument(fs, FormatType.Docx);

            if (document.Sections.Count < 1)
            {
                throw new Exception("Result template empty. Please contact your Application support.");
            }
            IWSection section = document.Sections[0];

            IWTable table = section.Tables[0];

            WParagraph p = (WParagraph)table.Rows[0].Cells[1].ChildEntities[0];

            p.AppendText(LabTest.BiodataNavigation.Fullname);

            p = (WParagraph)table.Rows[1].Cells[1].ChildEntities[0];
            string gardian = LabTest.BiodataNavigation.LegalGardianName;

            gardian = string.IsNullOrEmpty(gardian) ? "-" : gardian;
            p.AppendText(gardian);

            p = (WParagraph)table.Rows[2].Cells[1].ChildEntities[0];

            p.AppendText(LabTest.BiodataNavigation.Dateofbirth.ToString("dd/MMM/yyyy"));

            //skip 3


            //Repos.GenderRepos genders = new Repos.GenderRepos();


            int g_id = 1;

            foreach (var g in _context.TlkpGenders)
            {
                string tmp = g.Gender.Substring(0, 2).Trim().Trim('=');
                try
                {
                    p = (WParagraph)table.Rows[3].Cells[g_id].ChildEntities[0];
                    WCheckBox checkbox = p.AppendCheckBox();

                    if (LabTest.BiodataNavigation.Gender == g_id)
                    {
                        checkbox.Checked = true;
                    }

                    p.AppendText(" " + tmp);

                    g_id++;
                }
                catch
                {
                }
            }

            p = (WParagraph)table.Rows[4].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.BiodataNavigation.EpidNo);

            //skip 5 for local phone number
            p = (WParagraph)table.Rows[5].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.BiodataNavigation.LocalPhone ?? "-");

            p = (WParagraph)table.Rows[6].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.BiodataNavigation.HomePhone ?? "-");

            p = (WParagraph)table.Rows[7].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.BiodataNavigation.ResidentialAddress);

            //next table
            table = section.Tables[1];

            p = (WParagraph)table.Rows[0].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.MethodNavigation.Methodname);

            int k = 1;


            foreach (var i in LabTest.TblLabTestsIndicatorsValues)
            {
                var iname = _context.TlkpTestIndicators.FirstOrDefault(x => x.Id == i.Indicator).IndicatorName;

                p = (WParagraph)table.Rows[k].Cells[0].ChildEntities[0];
                p.AppendText(iname);

                p = (WParagraph)table.Rows[k].Cells[1].ChildEntities[0];
                p.AppendText(i.IndicatorValue.Value.ToString());

                k++;
            }



            /*Dictionary<int, string> _dict = new Dictionary<int, string> {
             *  { 1, "POSITIVE"},
             *  { 2, "NEGATIVE"},
             *  { 97, "NO RESULT"}
             * };*/
            var p1 = (WParagraph)table.Rows[k].Cells[0].ChildEntities[0];

            p = (WParagraph)table.Rows[k].Cells[1].ChildEntities[0];
            WCheckBox checkbox1 = p.AppendCheckBox();

            if (LabTest.Interpretation == 2)
            {
                checkbox1.Checked = true;
                p1.AppendText("INTERPRETATION: NEGATIVE RESULT");
            }
            else if (LabTest.Interpretation > 2)
            {
                p1.AppendText("INTERPRETATION: UNKNOWN");
            }

            p.AppendText(" NEGATIVE");

            p         = (WParagraph)table.Rows[k + 1].Cells[1].ChildEntities[0];
            checkbox1 = p.AppendCheckBox();
            if (LabTest.Interpretation == 1)
            {
                checkbox1.Checked = true;
                p1.AppendText("INTERPRETATION: POSITIVE RESULT");
            }

            p.AppendText(" POSITIVE");

            //next table
            table = section.Tables[2];

            DateTime d1 = DateTime.Today;               // any date will do

            p = (WParagraph)table.Rows[0].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.TestingDate.Value.ToString("dd/MMM/yyyy"));

            p = (WParagraph)table.Rows[1].Cells[1].ChildEntities[0];
            TimeSpan t   = LabTest.TestingTime.Value;
            string   chg = (d1 + t).ToString("hh:mm tt");

            p.AppendText(chg);

            p = (WParagraph)table.Rows[2].Cells[1].ChildEntities[0];
            p.AppendText(LabTest.ReportingDate.Value.ToString("dd/MMM/yyyy"));

            p   = (WParagraph)table.Rows[3].Cells[1].ChildEntities[0];
            t   = LabTest.ReportingTime.Value;
            chg = (d1 + t).ToString("hh:mm tt");
            p.AppendText(chg);

            //next table
            table = section.Tables[3];

            //Repos.SpecimenRepos _specimen = new Repos.SpecimenRepos();

            k = 1;
            foreach (var s in LabTest.TblLabTestsSpecimen)
            {
                bool other = s.Specimen == 99;

                var sname = _context.TlkpSpecimen.FirstOrDefault(x => x.Id == s.Specimen).Type;
                p = (WParagraph)table.Rows[k].Cells[0].ChildEntities[0];

                IWTextRange textRange = p.AppendText(sname + (other ? " (Specify)" : ""));
                textRange.CharacterFormat.FontSize = 8;


                p.ApplyStyle(BuiltinStyle.BlockText);
                p = (WParagraph)table.Rows[k].Cells[1].ChildEntities[0];
                if (other && !string.IsNullOrEmpty(s.SpecimenOther))
                {
                    textRange = p.AppendText(s.SpecimenOther);
                    textRange.CharacterFormat.FontSize = 10;
                }

                p         = (WParagraph)table.Rows[k].Cells[2].ChildEntities[0];
                checkbox1 = p.AppendCheckBox();
                if (s.Checked)
                {
                    checkbox1.Checked = true;
                }

                k++;
            }


            //
            //table = section.Tables[1];
            // p = (WParagraph)table.Rows[6].Cells[1].ChildEntities[0];
            //p.AppendText(LabTest.BioData.ResidentialAddress);


            DocIORenderer render = new DocIORenderer();
            //Converts Word document to PDF.
            PdfDocument pdfDocument = render.ConvertToPDF(document);

            //Release the resources used by the Word document and DocIO Renderer objects.

            render.Dispose();
            render.Dispose();
            document.Dispose();

            //add barcode
            PdfQRBarcode barcode = new PdfQRBarcode();

            barcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.High;
            //Set XDimension
            barcode.XDimension = 2.5f;
            //https://localhost:44353/LabTests/Details/
            string endpoint = configuration.GetConnectionString("ServerEndpoint");

            barcode.Text = string.Format("{0}LabTests/Details/{1}", endpoint, Id);
            //Creating new PDF Document
            //PdfDocument doc = new PdfDocument();
            //Adding new page to PDF document
            PdfPage page = pdfDocument.Pages[0];

            //Printing barcode on to the Pdf.
            //barcode.Draw(page, new PointF(25, 70));
            barcode.Draw(page, new PointF(250, 650));

            if (!string.IsNullOrEmpty(tokenId))
            {
                Response.Cookies.Append("fileDownloadToken", tokenId);
            }

            MemoryStream stream = new MemoryStream();

            //document.Save(stream, FormatType.Docx);
            pdfDocument.Save(stream);
            //return File(stream, "application/msword", "Sample.docx");
            return(File(stream.ToArray(), "application/octet-stream", "Draft.pdf"));
            //return RedirectToAction(nameof(Index));
        }