private void AddAnnexSection() { AddSectionWithTitle("Anexos"); Image table1 = Properties.Resources.Quadro1; Image table2 = Properties.Resources.Quadro2; Image table3 = Properties.Resources.Quadro3; Image table4 = Properties.Resources.Quadro4; AddSubsectionTitle(GetCurrentSection(), "Quadro1"); IWPicture table1pic = GetCurrentSection().AddParagraph().AppendPicture(table1); table1pic.Height = 400; table1pic.Width = 500; AddSubsectionTitle(GetCurrentSection(), "Quadro2"); IWPicture table2pic = GetCurrentSection().AddParagraph().AppendPicture(table2); table2pic.Height = 300; table2pic.Width = 450; AddSubsectionTitle(GetCurrentSection(), "Quadro3"); IWPicture table3pic = GetCurrentSection().AddParagraph().AppendPicture(table3); table3pic.Height = 300; table3pic.Width = 450; AddSubsectionTitle(GetCurrentSection(), "Quadro4"); IWPicture table4pic = GetCurrentSection().AddParagraph().AppendPicture(table4); table4pic.Height = 250; table4pic.Width = 500; }
private void SetStyle(IWPicture picture, string style) { string[] lstStyle = style.Split('-'); switch (lstStyle[0].ToLower()) { case "w": picture.Width = float.Parse(lstStyle[1]); break; case "h": picture.Height = float.Parse(lstStyle[1]); break; default: break; } }
private void SetTagValue() { if (lstTag.Count > 0) { foreach (ITagWord iTag in lstTag) { string tagName = Contains.START_TAG + iTag.TagName + Contains.END_TAG; switch (iTag.TagType) { case TagWordType.Text: Document.Replace(tagName, iTag.Data.ToString(), false, false); break; case TagWordType.Image: Image img = ConvertStrBase64ToImage(iTag.Data.ToString()); IWParagraph paragraph = Section.AddParagraph(); IWPicture picture = paragraph.AppendPicture(img); if (iTag.TagStyle != "") { string[] lstStyle = iTag.TagStyle.Split(';'); for (int i = 0, n = lstStyle.Length; i < n; i++) { SetStyle(picture, lstStyle[i]); } } paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; TextBodyPart textBodyPart = new TextBodyPart(Document); textBodyPart.BodyItems.Add(paragraph); Document.Replace(tagName, textBodyPart, false, false); break; default: break; } } } }
public ActionResult BookmarkNavigation(string Group1) { if (Group1 == null) { return(View()); } #region BookmarkNavigation // Creating a new document. WordDocument document = new WordDocument(); //Adds section with one empty paragraph to the Word document document.EnsureMinimal(); //sets the page margins document.LastSection.PageSetup.Margins.All = 72f; //Appends bookmark to the paragraph document.LastParagraph.AppendBookmarkStart("NorthwindDatabase"); document.LastParagraph.AppendText("Northwind database with normalization concept"); document.LastParagraph.AppendBookmarkEnd("NorthwindDatabase"); // Open an existing template document with single section to get Northwind.information WordDocument nwdInformation = new WordDocument(ResolveApplicationDataPath("Bookmark_Template.doc", "App_Data\\DocIO")); // Open an existing template document with multiple section to get Northwind data. WordDocument templateDocument = new WordDocument(ResolveApplicationDataPath("BkmkDocumentPart_Template.doc", "App_Data\\DocIO")); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the template document. BookmarksNavigator bk = new BookmarksNavigator(templateDocument); // Move to the NorthWind bookmark in template document bk.MoveToBookmark("NorthWind"); //Gets the bookmark content as WordDocumentPart WordDocumentPart documentPart = bk.GetContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the Northwind information document. bk = new BookmarksNavigator(nwdInformation); // Move to the information bookmark bk.MoveToBookmark("Information"); // Get the content of information bookmark. TextBodyPart bodyPart = bk.GetBookmarkContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the destination document. bk = new BookmarksNavigator(document); // Move to the NorthWind database in the destination document bk.MoveToBookmark("NorthwindDatabase"); //Replace the bookmark content using word document parts bk.ReplaceContent(documentPart); // Move to the Northwind_Information in the destination document bk.MoveToBookmark("Northwind_Information"); // Replacing content of Northwind_Information bookmark. bk.ReplaceBookmarkContent(bodyPart); // Move to the text bookmark bk.MoveToBookmark("Text"); //Deletes the bookmark content bk.DeleteBookmarkContent(true); // Inserting text inside the bookmark. This will preserve the source formatting bk.InsertText("Northwind Database contains the following table:"); #region tableinsertion WTable tbl = new WTable(document); tbl.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; tbl.TableFormat.IsAutoResized = true; tbl.ResetCells(8, 2); IWParagraph paragraph; tbl.Rows[0].IsHeader = true; paragraph = tbl[0, 0].AddParagraph(); paragraph.AppendText("Suppliers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[0, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 0].AddParagraph(); paragraph.AppendText("Customers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 0].AddParagraph(); paragraph.AppendText("Employees"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 0].AddParagraph(); paragraph.AppendText("Products"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 0].AddParagraph(); paragraph.AppendText("Inventory"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 1].AddParagraph(); paragraph.AppendText("2"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 0].AddParagraph(); paragraph.AppendText("Shippers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 0].AddParagraph(); paragraph.AppendText("PO Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 0].AddParagraph(); paragraph.AppendText("Sales Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 1].AddParagraph(); paragraph.AppendText("7"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; bk.InsertTable(tbl); #endregion tableinsertion //Move to image bookmark bk.MoveToBookmark("Image"); //Deletes the bookmark content bk.DeleteBookmarkContent(true); // Inserting image to the bookmark. IWPicture pic = bk.InsertParagraphItem(ParagraphItemType.Picture) as WPicture; pic.LoadImage(System.Drawing.Image.FromFile(ResolveApplicationDataPath("Northwind.png", "Content\\DocIO"))); pic.WidthScale = 50f; // It reduce the image size because it don't fit pic.HeightScale = 75f; // in document page. #endregion BookmarkNavigation #region Document SaveOption //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 SaveOption return(View()); }
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); } }
private async void Button_Click_1(object sender, RoutedEventArgs e) { Assembly execAssem = typeof(BookmarkNavigationDemo).GetTypeInfo().Assembly; // Creating a new document. WordDocument document = new WordDocument(); //Adds section with one empty paragraph to the Word document document.EnsureMinimal(); //sets the page margins document.LastSection.PageSetup.Margins.All = 72f; //Appends bookmark to the paragraph document.LastParagraph.AppendBookmarkStart("NorthwindDatabase"); document.LastParagraph.AppendText("Northwind database with relational data"); document.LastParagraph.AppendBookmarkEnd("NorthwindDatabase"); // Open an existing template document with single section. WordDocument nwdInformation = new WordDocument(); Stream inputStream = execAssem.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Bookmark_Template.doc"); // Open an existing template document. await nwdInformation.OpenAsync(inputStream, FormatType.Doc); inputStream.Dispose(); // Open an existing template document with multiple section. WordDocument templateDocument = new WordDocument(); inputStream = execAssem.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.BkmkDocumentPart_Template.doc"); // Open an existing template document. await templateDocument.OpenAsync(inputStream, FormatType.Doc); inputStream.Dispose(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the template document. BookmarksNavigator bk = new BookmarksNavigator(templateDocument); // Move to the NorthWind bookmark in template document bk.MoveToBookmark("NorthWind"); //Gets the bookmark content as WordDocumentPart WordDocumentPart documentPart = bk.GetContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the Northwind information document. bk = new BookmarksNavigator(nwdInformation); // Move to the information bookmark bk.MoveToBookmark("Information"); // Get the content of information bookmark. TextBodyPart bodyPart = bk.GetBookmarkContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the destination document. bk = new BookmarksNavigator(document); // Move to the NorthWind database in the destination document bk.MoveToBookmark("NorthwindDatabase"); //Replace the bookmark content using word document parts bk.ReplaceContent(documentPart); // Move to the Northwind_Information in the destination document bk.MoveToBookmark("Northwind_Information"); // Replacing content of Northwind_Information bookmark. bk.ReplaceBookmarkContent(bodyPart); // Move to the text bookmark bk.MoveToBookmark("Text"); //Deletes the bookmark content bk.DeleteBookmarkContent(true); // Inserting text inside the bookmark. This will preserve the source formatting bk.InsertText("Northwind Database contains the following table:"); #region tableinsertion WTable tbl = new WTable(document); tbl.TableFormat.Borders.BorderType = BorderStyle.None; tbl.TableFormat.IsAutoResized = true; tbl.ResetCells(8, 2); IWParagraph paragraph; tbl.Rows[0].IsHeader = true; paragraph = tbl[0, 0].AddParagraph(); paragraph.AppendText("Suppliers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[0, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 0].AddParagraph(); paragraph.AppendText("Customers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 0].AddParagraph(); paragraph.AppendText("Employees"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 0].AddParagraph(); paragraph.AppendText("Products"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 0].AddParagraph(); paragraph.AppendText("Inventory"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 1].AddParagraph(); paragraph.AppendText("2"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 0].AddParagraph(); paragraph.AppendText("Shippers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 0].AddParagraph(); paragraph.AppendText("PO Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 0].AddParagraph(); paragraph.AppendText("Sales Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 1].AddParagraph(); paragraph.AppendText("7"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; bk.InsertTable(tbl); #endregion //Move to image bookmark bk.MoveToBookmark("Image"); //Deletes the bookmark bk.DeleteBookmarkContent(true); // Inserting image to the bookmark. IWPicture pic = bk.InsertParagraphItem(ParagraphItemType.Picture) as WPicture; inputStream = execAssem.GetManifestResourceStream("Syncfusion.SampleBrowser.UWP.DocIO.DocIO.Assets.Northwind.png"); pic.LoadImage(inputStream); inputStream.Dispose(); pic.WidthScale = 50f; // It reduce the image size because it don't fit pic.HeightScale = 75f; // in document page. Save(rdDoc.IsChecked == true, document); }
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()); }
void OnButtonClicked(object sender, EventArgs e) { Assembly assembly = Assembly.GetExecutingAssembly(); // Creating a new document. WordDocument document = new WordDocument(); //Adds section with one empty paragraph to the Word document document.EnsureMinimal(); //sets the page margins document.LastSection.PageSetup.Margins.All = 72f; //Appends bookmark to the paragraph document.LastParagraph.AppendBookmarkStart("NorthwindDatabase"); document.LastParagraph.AppendText("Northwind database with relational data"); document.LastParagraph.AppendBookmarkEnd("NorthwindDatabase"); // Open an existing template document with single section. WordDocument nwdInformation = new WordDocument(); Stream inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Bookmark_Template.docx"); // Open an existing template document. nwdInformation.Open(inputStream, FormatType.Doc); inputStream.Dispose(); // Open an existing template document with multiple section. WordDocument templateDocument = new WordDocument(); inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.BkmkDocumentPart_Template.docx"); // Open an existing template document. templateDocument.Open(inputStream, FormatType.Doc); inputStream.Dispose(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the template document. BookmarksNavigator bk = new BookmarksNavigator(templateDocument); // Move to the NorthWind bookmark in template document bk.MoveToBookmark("NorthWind"); //Gets the bookmark content as WordDocumentPart WordDocumentPart documentPart = bk.GetContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the Northwind information document. bk = new BookmarksNavigator(nwdInformation); // Move to the information bookmark bk.MoveToBookmark("Information"); // Get the content of information bookmark. TextBodyPart bodyPart = bk.GetBookmarkContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the destination document. bk = new BookmarksNavigator(document); // Move to the NorthWind database in the destination document bk.MoveToBookmark("NorthwindDatabase"); //Replace the bookmark content using word document parts bk.ReplaceContent(documentPart); // Move to the Northwind_Information in the destination document bk.MoveToBookmark("Northwind_Information"); // Replacing content of Northwind_Information bookmark. bk.ReplaceBookmarkContent(bodyPart); #region Bookmark selection for table // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the Northwind information document. bk = new BookmarksNavigator(nwdInformation); bk.MoveToBookmark("SuppliersTable"); //Sets the column index where the bookmark starts within the table bk.CurrentBookmark.FirstColumn = 1; //Sets the column index where the bookmark ends within the table bk.CurrentBookmark.LastColumn = 5; // Get the content of suppliers table bookmark. bodyPart = bk.GetBookmarkContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the destination document. bk = new BookmarksNavigator(document); bk.MoveToBookmark("Table"); bk.ReplaceBookmarkContent(bodyPart); #endregion // Move to the text bookmark bk.MoveToBookmark("Text"); //Deletes the bookmark content bk.DeleteBookmarkContent(true); // Inserting text inside the bookmark. This will preserve the source formatting bk.InsertText("Northwind Database contains the following table:"); #region tableinsertion WTable tbl = new WTable(document); tbl.TableFormat.Borders.BorderType = BorderStyle.None; tbl.TableFormat.IsAutoResized = true; tbl.ResetCells(8, 2); IWParagraph paragraph; tbl.Rows[0].IsHeader = true; paragraph = tbl[0, 0].AddParagraph(); paragraph.AppendText("Suppliers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[0, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 0].AddParagraph(); paragraph.AppendText("Customers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 0].AddParagraph(); paragraph.AppendText("Employees"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 0].AddParagraph(); paragraph.AppendText("Products"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 0].AddParagraph(); paragraph.AppendText("Inventory"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 1].AddParagraph(); paragraph.AppendText("2"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 0].AddParagraph(); paragraph.AppendText("Shippers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 0].AddParagraph(); paragraph.AppendText("PO Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 0].AddParagraph(); paragraph.AppendText("Sales Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 1].AddParagraph(); paragraph.AppendText("7"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; bk.InsertTable(tbl); #endregion bk.MoveToBookmark("Image"); bk.DeleteBookmarkContent(true); // Inserting image to the bookmark. IWPicture pic = bk.InsertParagraphItem(ParagraphItemType.Picture) as WPicture; inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Northwind.png"); pic.LoadImage(inputStream); inputStream.Dispose(); pic.WidthScale = 50f; // It reduce the image size because it don't fit pic.HeightScale = 75f; // in document page. #region Saving Document MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Word2013); document.Close(); if (stream != null) { SaveAndroid androidSave = new SaveAndroid(); androidSave.Save("BookmarkNavigation.docx", "application/msword", stream, m_context); } #endregion }
private void button1_Click(object sender, System.EventArgs e) { try { string dataPath = @"..\..\..\..\..\..\..\Common\Data\DocIO\"; // Creating a new document. WordDocument document = new WordDocument(); //Adds section with one empty paragraph to the Word document document.EnsureMinimal(); //sets the page margins document.LastSection.PageSetup.Margins.All = 72f; //Appends bookmark to the paragraph document.LastParagraph.AppendBookmarkStart("NorthwindDatabase"); document.LastParagraph.AppendText("Northwind database with normalization concept"); document.LastParagraph.AppendBookmarkEnd("NorthwindDatabase"); // Open an existing template document with single section to get Northwind.information WordDocument nwdInformation = new WordDocument(dataPath + "Bookmark_Template.doc"); // Open an existing template document with multiple section to get Northwind data. WordDocument templateDocument = new WordDocument(dataPath + "BkmkDocumentPart_Template.doc"); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the template document. BookmarksNavigator bk = new BookmarksNavigator(templateDocument); // Move to the NorthWind bookmark in template document bk.MoveToBookmark("NorthWind"); //Gets the bookmark content as WordDocumentPart WordDocumentPart documentPart = bk.GetContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the Northwind information document. bk = new BookmarksNavigator(nwdInformation); // Move to the information bookmark bk.MoveToBookmark("Information"); // Get the content of information bookmark. TextBodyPart bodyPart = bk.GetBookmarkContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the destination document. bk = new BookmarksNavigator(document); // Move to the NorthWind database in the destination document bk.MoveToBookmark("NorthwindDatabase"); //Replace the bookmark content using word document parts bk.ReplaceContent(documentPart); // Move to the Northwind_Information in the destination document bk.MoveToBookmark("Northwind_Information"); // Replacing content of Northwind_Information bookmark. bk.ReplaceBookmarkContent(bodyPart); // Move to the text bookmark bk.MoveToBookmark("Text"); //Deletes the bookmark content bk.DeleteBookmarkContent(true); // Inserting text inside the bookmark. This will preserve the source formatting bk.InsertText("Northwind Database contains the following table:"); #region tableinsertion WTable tbl = new WTable(document); tbl.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; tbl.TableFormat.IsAutoResized = true; tbl.ResetCells(8, 2); IWParagraph paragraph; tbl.Rows[0].IsHeader = true; paragraph = tbl[0, 0].AddParagraph(); paragraph.AppendText("Suppliers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[0, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 0].AddParagraph(); paragraph.AppendText("Customers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 0].AddParagraph(); paragraph.AppendText("Employees"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 0].AddParagraph(); paragraph.AppendText("Products"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 0].AddParagraph(); paragraph.AppendText("Inventory"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 1].AddParagraph(); paragraph.AppendText("2"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 0].AddParagraph(); paragraph.AppendText("Shippers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 0].AddParagraph(); paragraph.AppendText("PO Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 0].AddParagraph(); paragraph.AppendText("Sales Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 1].AddParagraph(); paragraph.AppendText("7"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; bk.InsertTable(tbl); #endregion //Move to image bookmark bk.MoveToBookmark("Image"); //Deletes the bookmark content bk.DeleteBookmarkContent(true); // Inserting image to the bookmark. IWPicture pic = bk.InsertParagraphItem(ParagraphItemType.Picture) as WPicture; pic.LoadImage(System.Drawing.Image.FromFile(@"..\..\..\..\..\..\..\Common\images\DocIO\Northwind.png")); pic.WidthScale = 50f; // It reduces the image size because it doesnot fit pic.HeightScale = 75f; // in document page. bodyPart.Close(); documentPart.Close(); #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] 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()); } } } #endregion else { // Exit this.Close(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
public ActionResult BookmarkNavigation(string Group1) { if (Group1 == null) { return(View()); } #region BookmarkNavigation // Creating a new document. WordDocument document = new WordDocument(); //Adds section with one empty paragraph to the Word document document.EnsureMinimal(); //sets the page margins document.LastSection.PageSetup.Margins.All = 72f; //Appends bookmark to the paragraph document.LastParagraph.AppendBookmarkStart("NorthwindDatabase"); document.LastParagraph.AppendText("Northwind database with normalization concept"); document.LastParagraph.AppendBookmarkEnd("NorthwindDatabase"); string basePath = _hostingEnvironment.WebRootPath; string dataPath = basePath + @"/DocIO/Bookmark_Template.doc"; string dataPathTemp = basePath + @"/DocIO/BkmkDocumentPart_Template.doc"; // Open an existing template document with single section to get Northwind.information WordDocument nwdInformation = new WordDocument(); FileStream fileStream = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); nwdInformation.Open(fileStream, FormatType.Doc); fileStream.Dispose(); fileStream = null; // Open an existing template document with multiple section to get Northwind data. WordDocument templateDocument = new WordDocument(); fileStream = new FileStream(dataPathTemp, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); templateDocument.Open(fileStream, FormatType.Doc); fileStream.Dispose(); fileStream = null; // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the template document. BookmarksNavigator bk = new BookmarksNavigator(templateDocument); // Move to the NorthWind bookmark in template document bk.MoveToBookmark("NorthWind"); //Gets the bookmark content as WordDocumentPart WordDocumentPart documentPart = bk.GetContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the Northwind information document. bk = new BookmarksNavigator(nwdInformation); // Move to the information bookmark bk.MoveToBookmark("Information"); // Get the content of information bookmark. TextBodyPart bodyPart = bk.GetBookmarkContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the destination document. bk = new BookmarksNavigator(document); // Move to the NorthWind database in the destination document bk.MoveToBookmark("NorthwindDatabase"); //Replace the bookmark content using word document parts bk.ReplaceContent(documentPart); // Move to the Northwind_Information in the destination document bk.MoveToBookmark("Northwind_Information"); // Replacing content of Northwind_Information bookmark. bk.ReplaceBookmarkContent(bodyPart); // Move to the text bookmark bk.MoveToBookmark("Text"); //Deletes the bookmark content bk.DeleteBookmarkContent(true); // Inserting text inside the bookmark. This will preserve the source formatting bk.InsertText("Northwind Database contains the following table:"); #region tableinsertion WTable tbl = new WTable(document); tbl.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; tbl.TableFormat.IsAutoResized = true; tbl.ResetCells(8, 2); IWParagraph paragraph; tbl.Rows[0].IsHeader = true; paragraph = tbl[0, 0].AddParagraph(); paragraph.AppendText("Suppliers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[0, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 0].AddParagraph(); paragraph.AppendText("Customers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 0].AddParagraph(); paragraph.AppendText("Employees"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 0].AddParagraph(); paragraph.AppendText("Products"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 0].AddParagraph(); paragraph.AppendText("Inventory"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 1].AddParagraph(); paragraph.AppendText("2"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 0].AddParagraph(); paragraph.AppendText("Shippers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 0].AddParagraph(); paragraph.AppendText("PO Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 0].AddParagraph(); paragraph.AppendText("Sales Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 1].AddParagraph(); paragraph.AppendText("7"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; bk.InsertTable(tbl); #endregion tableinsertion //Move to image bookmark bk.MoveToBookmark("Image"); //Deletes the bookmark content bk.DeleteBookmarkContent(true); // Inserting image to the bookmark. IWPicture pic = bk.InsertParagraphItem(ParagraphItemType.Picture) as WPicture; FileStream imageStream = new FileStream(basePath + @"/images/DocIO/Northwind.png", FileMode.Open, FileAccess.Read); pic.LoadImage(imageStream); pic.WidthScale = 50f; // It reduce the image size because it don't fit pic.HeightScale = 75f; // in document page. #endregion BookmarkNavigation FormatType type = FormatType.Docx; string filename = "Sample.docx"; string contenttype = "application/vnd.ms-word.document.12"; #region Document SaveOption //Save as .doc format if (Group1 == "WordDoc") { type = FormatType.Doc; filename = "Sample.doc"; contenttype = "application/msword"; } //Save as .xml format else if (Group1 == "WordML") { type = FormatType.WordML; filename = "Sample.xml"; contenttype = "application/msword"; } #endregion Document SaveOption MemoryStream ms = new MemoryStream(); document.Save(ms, type); document.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }
private void ManipulateBookmarkContents() { // Creating a new document. using (WordDocument document = new WordDocument()) { #region Document Manipulations Assembly assembly = typeof(App).GetTypeInfo().Assembly; //Adds section with one empty paragraph to the Word document document.EnsureMinimal(); //sets the page margins document.LastSection.PageSetup.Margins.All = 72f; //Appends bookmark to the paragraph document.LastParagraph.AppendBookmarkStart("NorthwindDatabase"); document.LastParagraph.AppendText("Northwind database with relational data"); document.LastParagraph.AppendBookmarkEnd("NorthwindDatabase"); // Open an existing template document with single section. WordDocument nwdInformation = new WordDocument(); Stream inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Bookmark_Template.doc"); // Open an existing template document. nwdInformation.Open(inputStream, FormatType.Doc); inputStream.Dispose(); // Open an existing template document with multiple section. WordDocument templateDocument = new WordDocument(); inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.BkmkDocumentPart_Template.doc"); // Open an existing template document. templateDocument.Open(inputStream, FormatType.Doc); inputStream.Dispose(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the template document. BookmarksNavigator bk = new BookmarksNavigator(templateDocument); // Move to the NorthWind bookmark in template document bk.MoveToBookmark("NorthWind"); //Gets the bookmark content as WordDocumentPart WordDocumentPart documentPart = bk.GetContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the Northwind information document. bk = new BookmarksNavigator(nwdInformation); // Move to the information bookmark bk.MoveToBookmark("Information"); // Get the content of information bookmark. TextBodyPart bodyPart = bk.GetBookmarkContent(); // Creating a bookmark navigator. Which help us to navigate through the // bookmarks in the destination document. bk = new BookmarksNavigator(document); // Move to the NorthWind database in the destination document bk.MoveToBookmark("NorthwindDatabase"); //Replace the bookmark content using word document parts bk.ReplaceContent(documentPart); // Move to the Northwind_Information in the destination document bk.MoveToBookmark("Northwind_Information"); // Replacing content of Northwind_Information bookmark. bk.ReplaceBookmarkContent(bodyPart); // Move to the text bookmark bk.MoveToBookmark("Text"); //Deletes the bookmark content bk.DeleteBookmarkContent(true); // Inserting text inside the bookmark. This will preserve the source formatting bk.InsertText("Northwind Database contains the following table:"); #region tableinsertion WTable tbl = new WTable(document); tbl.TableFormat.Borders.BorderType = BorderStyle.None; tbl.TableFormat.IsAutoResized = true; tbl.ResetCells(8, 2); IWParagraph paragraph; tbl.Rows[0].IsHeader = true; paragraph = tbl[0, 0].AddParagraph(); paragraph.AppendText("Suppliers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[0, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 0].AddParagraph(); paragraph.AppendText("Customers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[1, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 0].AddParagraph(); paragraph.AppendText("Employees"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[2, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 0].AddParagraph(); paragraph.AppendText("Products"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[3, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 0].AddParagraph(); paragraph.AppendText("Inventory"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[4, 1].AddParagraph(); paragraph.AppendText("2"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 0].AddParagraph(); paragraph.AppendText("Shippers"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[5, 1].AddParagraph(); paragraph.AppendText("1"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 0].AddParagraph(); paragraph.AppendText("PO Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[6, 1].AddParagraph(); paragraph.AppendText("3"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 0].AddParagraph(); paragraph.AppendText("Sales Transactions"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; paragraph = tbl[7, 1].AddParagraph(); paragraph.AppendText("7"); paragraph.BreakCharacterFormat.FontName = "Calibri"; paragraph.BreakCharacterFormat.FontSize = 10; bk.InsertTable(tbl); #endregion bk.MoveToBookmark("Image"); bk.DeleteBookmarkContent(true); // Inserting image to the bookmark. IWPicture pic = bk.InsertParagraphItem(ParagraphItemType.Picture) as WPicture; inputStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Northwind.png"); pic.LoadImage(inputStream); inputStream.Dispose(); pic.WidthScale = 50f; // It reduce the image size because it don't fit pic.HeightScale = 75f; // in document page. #endregion #region Saving Document //Save the word document to stream. MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Docx); //Save file in the disk based on specfic OS if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("BookMarkNavigation.docx", "application/msword", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("BookMarkNavigation.docx", "application/msword", stream); } #endregion } }
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 = Syncfusion.Drawing.Color.FromArgb(232, 232, 232); document.Background.Gradient.Color2 = Syncfusion.Drawing.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 Syncfusion.Drawing.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 basePath = _hostingEnvironment.WebRootPath; FileStream imageStream = new FileStream(basePath + @"/images/DocIO/Image.jpg", FileMode.Open, FileAccess.Read); IWPicture pic = cellPara.AppendPicture(imageStream); pic.Height = 80; pic.Width = 180; cellPara = row.Cells[1].AddParagraph(); row.Cells[1].CellFormat.VerticalAlignment = VerticalAlignment.Middle; row.Cells[1].CellFormat.BackColor = Syncfusion.Drawing.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 = Syncfusion.Drawing.Color.FromArgb(155, 205, 255); row.Cells[0].CellFormat.BackColor = Syncfusion.Drawing.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 = Syncfusion.Drawing.Color.FromArgb(155, 205, 255); row.Cells[0].CellFormat.BackColor = Syncfusion.Drawing.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 = Syncfusion.Drawing.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 = Syncfusion.Drawing.Color.MidnightBlue; txtField.TextRange.CharacterFormat.FontName = "Arial"; txtField.TextRange.CharacterFormat.FontSize = 11f; txtField.CharacterFormat.TextColor = Syncfusion.Drawing.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 = Syncfusion.Drawing.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 = Syncfusion.Drawing.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 = Syncfusion.Drawing.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 = Syncfusion.Drawing.Color.FromArgb(155, 205, 255); row.Cells[0].CellFormat.BackColor = Syncfusion.Drawing.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 = Syncfusion.Drawing.Color.FromArgb(155, 205, 255); row.Cells[0].CellFormat.BackColor = Syncfusion.Drawing.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 = Syncfusion.Drawing.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 = Syncfusion.Drawing.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 = Syncfusion.Drawing.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 = Syncfusion.Drawing.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 FormatType type = FormatType.Docx; string filename = "Sample.docx"; string contenttype = "application/vnd.ms-word.document.12"; #region Document SaveOption //Save as .doc format if (Group1 == "WordDoc") { type = FormatType.Doc; filename = "Sample.doc"; contenttype = "application/msword"; } //Save as .xml format else if (Group1 == "WordML") { type = FormatType.WordML; filename = "Sample.xml"; contenttype = "application/msword"; } #endregion Document SaveOption MemoryStream ms = new MemoryStream(); document.Save(ms, type); document.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }
private void ReplateTempInCell(WTableCell cell, IRepeatWord iRepeat) { PropertyInfo[] pptI; pptI = iRepeat.Data.GetType().GetProperties(); int length = pptI.Count(); for (int i = 0, n = cell.Paragraphs.Count; i < n; i++) { string paragraph = cell.Paragraphs[i].Text; List <string> str = new List <string>(); for (int j = 0; j < length; j++) { str.Add("{" + pptI[j].Name + "}"); } string[] lst = str.ToArray(); for (int j = 0; j < lst.Length; j++) { if (paragraph.IndexOf(lst[j]) != -1) { string tagType = "Text"; string tagStyle = string.Empty; for (int k = 0, l = iRepeat.ITemp.ITempTag.Count; k < l; k++) { if (pptI[j].Name == iRepeat.ITemp.ITempTag[k].TagName) { tagType = iRepeat.ITemp.ITempTag[k].TagType; tagStyle = iRepeat.ITemp.ITempTag[k].TagStyle; } } if (tagType.ToLower() == TagWordType.Text.ToString().ToLower()) { paragraph = paragraph.Replace(lst[j], pptI[j].GetValue(iRepeat.Data, null).ToString()); cell.Paragraphs[i].Text = paragraph; } else { string strImg = pptI[j].GetValue(iRepeat.Data, null).ToString(); string s = cell.Paragraphs[i].Text; string[] lsts = s.Split(new string[] { lst[j] }, StringSplitOptions.None); cell.Paragraphs[i].Text = ""; cell.Paragraphs[i].AppendText(lsts[0]); if (strImg == "" || strImg == null) { if (lsts.Length != 1) { cell.Paragraphs[i].AppendText(lsts[1]); } } else { Image img = ConvertStrBase64ToImage(strImg); IWPicture picture = cell.Paragraphs[i].AppendPicture(img); if (lsts.Length != 1) { cell.Paragraphs[i].AppendText(lsts[1]); } if (tagStyle != "") { string[] lstStyle = tagStyle.Split(';'); for (int a = 0, b = lstStyle.Length; a < b; a++) { SetStyle(picture, lstStyle[a]); } } } } } } } }