static void Main(string[] args) { //Creates new Word document instance for Word processing using (WordDocument document = new WordDocument()) { //Opens the input Word document Stream docStream = File.OpenRead(Path.GetFullPath(@"../../../Template.docx")); document.Open(docStream, FormatType.Docx); docStream.Dispose(); //Finds all the image placeholder text in the Word document. TextSelection[] textSelections = document.FindAll(new Regex("^//(.*)")); for (int i = 0; i < textSelections.Length; i++) { //Replaces the image placeholder text with desired image. Stream imageStream = File.OpenRead(Path.GetFullPath(@"../../../" + textSelections[i].SelectedText + ".png")); WParagraph paragraph = new WParagraph(document); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; imageStream.Dispose(); TextSelection newSelection = new TextSelection(paragraph, 0, 1); TextBodyPart bodyPart = new TextBodyPart(document); bodyPart.BodyItems.Add(paragraph); document.Replace(textSelections[i].SelectedText, bodyPart, true, true); } //Saves the resultant file in the given path docStream = File.Create(Path.GetFullPath(@"Result.docx")); document.Save(docStream, FormatType.Docx); docStream.Dispose(); } }
/// <summary> /// Binds the image from file system and fit within text box during Mail merge process by using MergeImageFieldEventHandler. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public static void MergeField_ProductImage(object sender, MergeImageFieldEventArgs args) { //Binds image from file system during mail merge if (args.FieldName == "Photo") { string ProductFileName = args.FieldValue.ToString(); //Gets the image from file system args.Image = Image.FromFile(@"../../" + ProductFileName); //Gets the picture, to be merged for image merge field WPicture picture = args.Picture; //Gets the text box format WTextBoxFormat textBoxFormat = (args.CurrentMergeField.OwnerParagraph.OwnerTextBody.Owner as WTextBox).TextBoxFormat; //Resizes the picture to fit within text box float scalePercentage = 100; if (picture.Width != textBoxFormat.Width) { //Calculates value for width scale factor scalePercentage = textBoxFormat.Width / picture.Width * 100; //This will resize the width picture.WidthScale *= scalePercentage / 100; } scalePercentage = 100; if (picture.Height != textBoxFormat.Height) { //Calculates value for height scale factor scalePercentage = textBoxFormat.Height / picture.Height * 100; //This will resize the height picture.HeightScale *= scalePercentage / 100; } } }
/// <summary> /// Insert OLE Object into the Word document /// </summary> /// <returns>Return the created Word document as stream</returns> public MemoryStream InsertOLEObject(string documentType) { //Data folder path is resolved from requested page physical path. string basePath = _hostingEnvironment.WebRootPath; FileStream fileStream; WordDocument oleSource; if (documentType == "DOC") { fileStream = new FileStream(basePath + @"/DocIO/OleTemplate.doc", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Open an existing word document oleSource = new WordDocument(fileStream, FormatType.Doc); } else { fileStream = new FileStream(basePath + @"/DocIO/OleTemplate.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //Open an existing word document oleSource = new WordDocument(fileStream, FormatType.Docx); } fileStream.Dispose(); fileStream = null; WordDocument dest = new WordDocument(); dest.EnsureMinimal(); // Get OLE object from source document WOleObject oleObject = oleSource.LastParagraph.Items[0] as WOleObject; WPicture pic = oleObject.OlePicture.Clone() as WPicture; dest.LastParagraph.AppendText("OLE Object Demo"); dest.LastParagraph.ApplyStyle(BuiltinStyle.Heading1); dest.LastParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; dest.Sections[0].AddParagraph(); dest.LastParagraph.AppendText("Adobe PDF object Inserted"); dest.LastParagraph.ApplyStyle(BuiltinStyle.Heading2); dest.Sections[0].AddParagraph(); //AppendOLE object to the destination document dest.LastParagraph.AppendOleObject(oleObject.Container, pic, OleLinkType.Embed); FormatType formatType = FormatType.Docx; //Save as .doc format if (documentType == "WordDoc") { formatType = FormatType.Doc; } //Save as .xml format else if (documentType == "WordML") { formatType = FormatType.WordML; } //Save the document as a stream and retrun the stream using (MemoryStream stream = new MemoryStream()) { //Save the created Word document to MemoryStream dest.Save(stream, formatType); dest.Close(); stream.Position = 0; return(stream); } }
public ActionResult InsertOLEObject(string Group1) { if (Group1 == null) { return(View()); } //Data folder path is resolved from requested page physical path. string dataPath = ResolveApplicationDataPath("", "App_Data\\DocIO"); WordDocument oleSource; if (Group1 == ".doc") { //Open an existing word document oleSource = new WordDocument(Path.Combine(dataPath, "OleTemplate.doc")); } else { //Open an existing word document oleSource = new WordDocument(Path.Combine(dataPath, "OleTemplate.docx")); } WordDocument dest = new WordDocument(); dest.EnsureMinimal(); // Get OLE object from source document WOleObject oleObject = oleSource.LastParagraph.Items[0] as WOleObject; WPicture pic = oleObject.OlePicture.Clone() as WPicture; dest.LastParagraph.AppendText("OLE Object Demo"); dest.LastParagraph.ApplyStyle(BuiltinStyle.Heading1); dest.LastParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; dest.Sections[0].AddParagraph(); dest.LastParagraph.AppendText("Adobe PDF object Inserted"); dest.LastParagraph.ApplyStyle(BuiltinStyle.Heading2); dest.Sections[0].AddParagraph(); // AppendOLE object to the destination document dest.LastParagraph.AppendOleObject(oleObject.Container, pic, OleLinkType.Embed); //Save as .doc format if (Group1 == "WordDoc") { return(dest.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx format else if (Group1 == "WordDocx") { return(dest.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(dest.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } return(View()); }
/// <summary> /// Creates paragraph in the Word document. /// </summary> /// <param name="section">The section to add paragraphs.</param> private void CreateParagraph(WSection section) { #region Inserting Header IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); //Gets the image. string resourcePath = "syncfusion.dociodemos.winui.Assets.DocIO.HeaderImage.png"; Stream imageStream = assembly.GetManifestResourceStream(resourcePath); //Appends image to the paragraph. WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.WidthScale = 173f; picture.HeightScale = 149f; #endregion #region Inserting Footer paragraph = section.HeadersFooters.Footer.AddParagraph(); paragraph.ParagraphFormat.Tabs.AddTab(523f, TabJustification.Right, TabLeader.NoLeader); //Adds page and Number of pages field to the document. paragraph.AppendText("\tPage "); paragraph.AppendField("Page", FieldType.FieldPage); paragraph.AppendText(" of "); paragraph.AppendField("NumPages", FieldType.FieldNumPages); #endregion //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the Adventure Works sample databases are based, 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.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = 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.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; }
public void AddImage(string imagePath, float horizontalPosition = 0f, float verticalPosition = 0f, string textWrap = "InFrontOfText", string horizontalOrigin = "Margin", string verticalOrigin = "Margin", float widthScale = 20f, float heightScale = 20f) { CheckParagraph(); Stream imageStream = UTILS.ImageToStream(imagePath); WPicture picture = m_paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = SfUtils.String2TextWrappingStyle(textWrap); picture.HorizontalOrigin = SfUtils.String2HorizontalOrigin(horizontalOrigin); picture.HorizontalPosition = horizontalPosition; picture.VerticalOrigin = SfUtils.String2VerticalOrigin(verticalOrigin); picture.VerticalPosition = verticalPosition; picture.WidthScale = widthScale; picture.HeightScale = heightScale; }
public ActionResult InsertOLEObject(string Group1) { if (Group1 == null) { return(View()); } //Data folder path is resolved from requested page physical path. string basePath = _hostingEnvironment.WebRootPath; string dataPath = basePath + @"/DocIO/OleTemplate.doc"; FileStream fileStream = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); WordDocument oleSource; if (Group1 == ".doc") { //Open an existing word document oleSource = new WordDocument(fileStream, FormatType.Doc); } else { //Open an existing word document oleSource = new WordDocument(fileStream, FormatType.Doc); } fileStream.Dispose(); fileStream = null; WordDocument dest = new WordDocument(); dest.EnsureMinimal(); // Get OLE object from source document WOleObject oleObject = oleSource.LastParagraph.Items[0] as WOleObject; WPicture pic = oleObject.OlePicture.Clone() as WPicture; dest.LastParagraph.AppendText("OLE Object Demo"); dest.LastParagraph.ApplyStyle(BuiltinStyle.Heading1); dest.LastParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; dest.Sections[0].AddParagraph(); dest.LastParagraph.AppendText("Adobe PDF object Inserted"); dest.LastParagraph.ApplyStyle(BuiltinStyle.Heading2); dest.Sections[0].AddParagraph(); // AppendOLE object to the destination document dest.LastParagraph.AppendOleObject(oleObject.Container, pic, OleLinkType.Embed); 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(); dest.Save(ms, type); dest.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }
private void button1_Click(object sender, System.EventArgs e) { try { //Getting Image files path. string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\images\DocIO\"; //A new document is created. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); WPicture picture = paragraph.AppendPicture(Image.FromFile(dataPath + "AdventureCycle.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -45; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Color.Red; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, 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.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = 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.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Mountain-200.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Mountain-300.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(dataPath + "Road-550-W.jpg")) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. section.AddParagraph(); //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. document.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.doc"); #endif //Exit this.Close(); } } //Save as docx format else if (wordDocxRadioBtn.Checked) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as pdf format else if (pdfRadioBtn.Checked) { DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(document); //Save the pdf file pdfDoc.Save("Sample.pdf"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.pdf"); #endif //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
public MemoryStream ImageInsertion(string documentType) { string basePath = _hostingEnvironment.WebRootPath; string dataPath = basePath + @"\DocIO\RTFToDoc.rtf"; #region ImageInsertion //Create a new document WordDocument document = new WordDocument(); //Adding a new section to the document. IWSection section = document.AddSection(); section.PageSetup.Margins.All = 72; //Adding a paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Writing text. paragraph.AppendText("This sample demonstrates how to insert Vector and Scalar images inside a document."); //Adding a new paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; FileStream imageStream = new FileStream(basePath + @"/images/DocIO/yahoo.gif", FileMode.Open, FileAccess.Read); //Inserting .gif . WPicture picture = (WPicture)paragraph.AppendPicture(imageStream); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = new FileStream(basePath + @"/images/DocIO/Reports.bmp", FileMode.Open, FileAccess.Read); //Inserting .bmp picture = (WPicture)paragraph.AppendPicture(imageStream); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = new FileStream(basePath + @"/images/DocIO/google.png", FileMode.Open, FileAccess.Read); //Inserting .png picture = (WPicture)paragraph.AppendPicture(imageStream); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = new FileStream(basePath + @"/images/DocIO/Square.tif", FileMode.Open, FileAccess.Read); //Inserting .tif picture = (WPicture)paragraph.AppendPicture(imageStream); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Adding a new paragraph. paragraph = section.AddParagraph(); //Setting Alignment for the image. paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = new FileStream(basePath + @"/images/DocIO/Ess chart.emf", FileMode.Open, FileAccess.Read); //Inserting .wmf Image to the document. WPicture mImage = (WPicture)paragraph.AppendPicture(imageStream); //Scaling Image mImage.HeightScale = 50f; mImage.WidthScale = 50f; //Adding Image caption mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Updates the fields in Word document document.UpdateDocumentFields(); FormatType type = FormatType.Docx; #region Document SaveOption //Save as .doc format if (documentType == "WordDoc") { type = FormatType.Doc; } //Save as .xml format else if (documentType == "WordML") { type = FormatType.WordML; } #endregion Document SaveOption using (MemoryStream stream = new MemoryStream()) { //Save the created Word document to MemoryStream document.Save(stream, type); document.Close(); stream.Position = 0; return(stream); } }
private void button1_Click(object sender, System.EventArgs e) { try { //Getting Image files Path. string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\Images\DocIO\"; //Getting text files Path. string dataPath1 = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\Data\"; //Creating a new document WordDocument document = new WordDocument(); //Adding a new section. IWSection section = document.AddSection(); IWParagraph paragraph = section.AddParagraph(); paragraph = section.AddParagraph(); section.PageSetup.Margins.All = 72f; IWTextRange text = paragraph.AppendText("Adventure products"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group "); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; #region Line break paragraph.AppendBreak(BreakType.LineBreak); paragraph.AppendBreak(BreakType.LineBreak); #endregion section = document.AddSection(); section.BreakCode = SectionBreakCode.NoBreak; section.PageSetup.Margins.All = 72f; //Adding three columns to section. section.AddColumn(100, 15); section.AddColumn(100, 15); section.AddColumn(100, 15); //Set the columns to be of equal width. section.MakeColumnsEqual(); //Adding a new paragraph to the section. paragraph = section.AddParagraph(); //Adding text. text = paragraph.AppendText("Mountain-200"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; //Adding a new paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); //Inserting an Image. WPicture picture = paragraph.AppendPicture(new Bitmap(Path.Combine(dataPath, "Mountain-200.jpg"))) as WPicture; picture.Width = 120f; picture.Height = 90f; //Adding a new paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; //Adding text. paragraph.AppendText(@"Product No:BK-M68B-38" + "\n" + "Size: 38" + "\n" + "Weight: 25\n" + "Price: $2,294.99"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; // Set column break as true. It navigates the cursor position to the next Column. paragraph.ParagraphFormat.ColumnBreakAfter = true; paragraph = section.AddParagraph(); text = paragraph.AppendText("Mountain-300"); text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; section.AddParagraph(); paragraph = section.AddParagraph(); picture = paragraph.AppendPicture(new Bitmap(Path.Combine(dataPath, "Mountain-300.jpg"))) as WPicture; picture.Width = 120f; picture.Height = 90f; section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText(@"Product No:BK-M4-38" + "\n" + "Size: 35\n" + "Weight: 22" + "\n" + " Price: $1,079.99"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; paragraph.ParagraphFormat.ColumnBreakAfter = true; paragraph = section.AddParagraph(); text = paragraph.AppendText("Road-150"); text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; section.AddParagraph(); paragraph = section.AddParagraph(); picture = paragraph.AppendPicture(new Bitmap(Path.Combine(dataPath, "Road-550-W.jpg"))) as WPicture; picture.Width = 120f; picture.Height = 90f; section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText(@"Product No: BK-R93R-44" + "\n" + "Size: 44" + "\n" + "Weight: 14" + "\n" + "Price: $3,578.27"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; section = document.AddSection(); section.BreakCode = SectionBreakCode.NoBreak; section.PageSetup.Margins.All = 72f; text = section.AddParagraph().AppendText("First Look\n"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText("Adventure Works Cycles, the fictitious company, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base."); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; paragraph.ParagraphFormat.PageBreakAfter = true; paragraph = section.AddParagraph(); text = paragraph.AppendText("Introduction\n"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group."); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. document.Save("Sample.doc"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.doc") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.doc"); #endif //Exit this.Close(); } } //Save as docx format else if (wordDocxRadioBtn.Checked) { //Saving the document as .docx document.Save("Sample.docx", FormatType.Docx); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated Word document?", "Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { //Launching the MS Word file using the default Application.[MS Word Or Free WordViewer] #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.docx"); #endif //Exit this.Close(); } catch (Win32Exception ex) { MessageBoxAdv.Show("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } } //Save as pdf format else if (pdfRadioBtn.Checked) { DocToPDFConverter converter = new DocToPDFConverter(); //Convert word document into PDF document PdfDocument pdfDoc = converter.ConvertToPDF(document); //Save the pdf file pdfDoc.Save("Sample.pdf"); //Message box confirmation to view the created document. if (MessageBoxAdv.Show("Do you want to view the generated PDF?", " Document has been created", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { try { #if NETCORE System.Diagnostics.Process process = new System.Diagnostics.Process(); process.StartInfo = new System.Diagnostics.ProcessStartInfo("Sample.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start("Sample.pdf"); #endif //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
public ActionResult InsertBreak(string Group1) { if (Group1 == null) { return(View()); } //Creating a new document WordDocument document = new WordDocument(); //Adding a new section. IWSection section = document.AddSection(); IWParagraph paragraph = section.AddParagraph(); paragraph = section.AddParagraph(); section.PageSetup.Margins.All = 20f; IWTextRange text = paragraph.AppendText("Adventure products"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group "); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; #region Line break paragraph.AppendBreak(BreakType.LineBreak); paragraph.AppendBreak(BreakType.LineBreak); #endregion Line break section = document.AddSection(); section.BreakCode = SectionBreakCode.NoBreak; section.PageSetup.Margins.All = 20f; //Adding three columns to section. section.AddColumn(100, 15); section.AddColumn(100, 15); section.AddColumn(100, 15); //Set the columns to be of equal width. section.MakeColumnsEqual(); //Adding a new paragraph to the section. paragraph = section.AddParagraph(); //Adding text. text = paragraph.AppendText("Mountain-200"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; //Adding a new paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); string basePath = _hostingEnvironment.WebRootPath; FileStream imageStream = new FileStream(basePath + @"/images/DocIO/Mountain-200.jpg", FileMode.Open, FileAccess.Read); //Inserting an Image. WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.Width = 120f; picture.Height = 90f; //Adding a new paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; //Adding text. paragraph.AppendText(@"Product No:BK-M68B-38" + "\n" + "Size: 38" + "\n" + "Weight: 25\n" + "Price: $2,294.99"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; // Set column break as true. It navigates the cursor position to the next Column. paragraph.ParagraphFormat.ColumnBreakAfter = true; paragraph = section.AddParagraph(); text = paragraph.AppendText("Mountain-300"); text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; section.AddParagraph(); paragraph = section.AddParagraph(); imageStream = new FileStream(basePath + @"/images/DocIO/Mountain-300.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.Width = 120f; picture.Height = 90f; section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText(@"Product No:BK-M4-38" + "\n" + "Size: 35\n" + "Weight: 22" + "\n" + "Price: $1,079.99"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; paragraph.ParagraphFormat.ColumnBreakAfter = true; paragraph = section.AddParagraph(); text = paragraph.AppendText("Road-150"); text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; section.AddParagraph(); paragraph = section.AddParagraph(); imageStream = new FileStream(basePath + @"/images/DocIO/Road-550-W.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.Width = 120f; picture.Height = 90f; section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText(@"Product No: BK-R93R-44" + "\n" + "Size: 44" + "\n" + "Weight: 14" + "\n" + "Price: $3,578.27"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; section = document.AddSection(); section.BreakCode = SectionBreakCode.NoBreak; section.PageSetup.Margins.All = 20f; text = section.AddParagraph().AppendText("First Look\n"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText(@"Adventure Works Cycles, the fictitious company, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base."); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; paragraph.ParagraphFormat.PageBreakAfter = true; paragraph = section.AddParagraph(); text = paragraph.AppendText("Introduction\n"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText(@"In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group."); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; FormatType type = FormatType.Docx; string filename = "Sample.docx"; string contenttype = "application/vnd.ms-word.document.12"; #region Document SaveOption //Save as .doc format if (Group1 == "WordDoc") { type = FormatType.Doc; filename = "Sample.doc"; contenttype = "application/msword"; } //Save as .xml format else if (Group1 == "WordML") { type = FormatType.WordML; filename = "Sample.xml"; contenttype = "application/msword"; } #endregion Document SaveOption MemoryStream ms = new MemoryStream(); document.Save(ms, type); document.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }
/// <summary> /// Creates product overview table in the Word document. /// </summary> /// <param name="section">The section to add table.</param> private void CreateProductOverviewTable(WSection section) { //Appends table. IWTable table = section.AddTable(); table.ResetCells(4, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. IWParagraph paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; string resourcePath = "syncfusion.dociodemos.winui.Assets.DocIO.Mountain200.jpg"; //Appends picture to the paragraph. Stream imageStream = assembly.GetManifestResourceStream(resourcePath); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; //Adds textrange. AddTextRange(paragraph, "Product No: BK-M68B-38\r"); AddTextRange(paragraph, "Size: 38\r"); AddTextRange(paragraph, "Weight: 25\r"); AddTextRange(paragraph, "Price: $2,294.99\r"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; //Adds textrange. AddTextRange(paragraph, "Product No: BK-M47B-38\r"); AddTextRange(paragraph, "Size: 35\r"); AddTextRange(paragraph, "Weight: 22\r"); AddTextRange(paragraph, "Price: $1,079.99\r"); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; resourcePath = "syncfusion.dociodemos.winui.Assets.DocIO.Mountain300.jpg"; //Appends picture to the paragraph. imageStream = assembly.GetManifestResourceStream(resourcePath); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; resourcePath = "syncfusion.dociodemos.winui.Assets.DocIO.Road550W.jpg"; //Appends picture to the paragraph. imageStream = assembly.GetManifestResourceStream(resourcePath); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; //Adds textrange. AddTextRange(paragraph, "Product No: BK-R93R-44\r"); AddTextRange(paragraph, "Size: 44\r"); AddTextRange(paragraph, "Weight: 14\r"); AddTextRange(paragraph, "Price: $3,578.27\r"); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[3, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-100"); //Appends paragraph. paragraph = table[3, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; //Adds textrange. AddTextRange(paragraph, "Product No: BK-M47B-38\r"); AddTextRange(paragraph, "Size: 42\r"); AddTextRange(paragraph, "Weight: 20\r"); AddTextRange(paragraph, "Price: $1,079.99\r"); //Appends paragraph. paragraph = table[3, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[3, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; resourcePath = "syncfusion.dociodemos.winui.Assets.DocIO.Mountain300.jpg"; //Appends picture to the paragraph. imageStream = assembly.GetManifestResourceStream(resourcePath); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. section.AddParagraph(); }
private static void IterateTable(WTable table) { List <DocViewModel> optionCheckList = new List <DocViewModel>(); foreach (WTableRow row in table.Rows) { #region get key IEntity titleEntity = row.Cells[0].ChildEntities[0]; string key = (titleEntity as WParagraph).Text; #endregion #region question content if (key.Contains("QN=") || key.Contains("QN =")) { quesModel.Code = key.Replace("QN=", "").Replace("QN =", "").Trim(); //for (int i = 0; i < row.Cells[1].ChildEntities.Count; i++) //{ // IEntity bodyItemEntity = row.Cells[1].ChildEntities[i]; // WParagraph wParagraph = bodyItemEntity as WParagraph; // if (wParagraph.ChildEntities.Count != 0) // { // ParagraphItem pItem = wParagraph.ChildEntities[0] as ParagraphItem; // switch (pItem.EntityType) // { // default: // if (!(wParagraph.Text.Contains("[file") || wParagraph.Text.Equals("")) && quesModel.QuestionContent == null) // { // quesModel.QuestionContent = "[html] " + wParagraph.Text.Replace("\v", "<cbr>"); // } // else if (!(wParagraph.Text.Contains("[file") || wParagraph.Text.Equals(""))) // { // WTextRange text = pItem as WTextRange; // quesModel.QuestionContent = quesModel.QuestionContent + "<cbr>" + wParagraph.Text; // } // break; // case EntityType.Picture: // WPicture wPicture = pItem as WPicture; // Image iImage = wPicture.Image; // MemoryStream m = new MemoryStream(); // iImage.Save(m, iImage.RawFormat); // byte[] imageBytes = m.ToArray(); // quesModel.Image = Convert.ToBase64String(imageBytes); // break; // } // } // if (quesModel.Image != null) // { // break; // } //} for (int i = 0; i < row.Cells[1].ChildEntities.Count; i++) { bool inputWholeParagraph = false; IEntity bodyItemEntity = row.Cells[1].ChildEntities[i]; WParagraph wParagraph = bodyItemEntity as WParagraph; if (wParagraph.ChildEntities.Count != 0) { foreach (var pChild in wParagraph.ChildEntities) { var pItem = pChild as ParagraphItem; switch (pItem.EntityType) { case EntityType.TextRange: if (!inputWholeParagraph) { if (!wParagraph.Text.Equals("") && quesModel.QuestionContent == null) { quesModel.QuestionContent = "[html] " + wParagraph.Text.Replace("\v", "<cbr>").Split(new string[] { "[file" }, StringSplitOptions.None)[0]; inputWholeParagraph = true; } else if (!wParagraph.Text.Equals("")) { quesModel.QuestionContent = quesModel.QuestionContent + "<cbr>" + wParagraph.Text.Split(new string[] { "[file" }, StringSplitOptions.None)[0]; inputWholeParagraph = true; } } break; case EntityType.Picture: WPicture wPicture = pItem as WPicture; System.Drawing.Image iImage = wPicture.Image; MemoryStream m = new MemoryStream(); iImage.Save(m, iImage.RawFormat); byte[] imageBytes = m.ToArray(); ImageViewModel image = new ImageViewModel(); image.Source = Convert.ToBase64String(imageBytes); images.Add(image); break; } } } } } #endregion #region option content else if (key.Contains(".")) { var optionImages = new List <ImageViewModel>(); var optionCheck = new DocViewModel(); optionCheck.Code = key.Replace(".", "").ToLower(); //for (int i = 0; i < row.Cells[1].ChildEntities.Count; i++) //{ // IEntity bodyItemEntity = row.Cells[1].ChildEntities[i]; // WParagraph wParagraph = bodyItemEntity as WParagraph; // if (wParagraph.Text != "") // { // ParagraphItem pItem = wParagraph.ChildEntities[0] as ParagraphItem; // switch (pItem.EntityType) // { // //case EntityType.TextRange: // default: // if (!wParagraph.Text.Equals("") && optionModel.OptionContent == null) // { // optionModel.IsCorrect = false; // optionModel.OptionContent = wParagraph.Text.Replace("\v", "<cbr>"); // } // else if (!wParagraph.Text.Equals("")) // { // optionModel.OptionContent = optionModel.OptionContent + "<cbr>" + wParagraph.Text.Replace("\v", "<cbr>"); // } // break; // case EntityType.Picture: // //WPicture wPicture = pItem as WPicture; // //Image iImage = wPicture.Image; // //MemoryStream m = new MemoryStream(); // //iImage.Save(m, iImage.RawFormat); // //byte[] imageBytes = m.ToArray(); // //quesModel.Image = Convert.ToBase64String(imageBytes); // break; // } // } //} for (int i = 0; i < row.Cells[1].ChildEntities.Count; i++) { bool inputWholeParagraph = false; IEntity bodyItemEntity = row.Cells[1].ChildEntities[i]; WParagraph wParagraph = bodyItemEntity as WParagraph; if (wParagraph.ChildEntities.Count != 0) { foreach (var pChild in wParagraph.ChildEntities) { var pItem = pChild as ParagraphItem; switch (pItem.EntityType) { case EntityType.TextRange: if (!inputWholeParagraph) { if (!wParagraph.Text.Equals("") && optionModel.OptionContent == null) { optionModel.IsCorrect = false; optionModel.OptionContent = wParagraph.Text.Replace("\v", "<cbr>"); inputWholeParagraph = true; } else if (!wParagraph.Text.Equals("")) { optionModel.OptionContent = optionModel.OptionContent + "<cbr>" + wParagraph.Text; } } break; case EntityType.Picture: WPicture wPicture = pItem as WPicture; System.Drawing.Image iImage = wPicture.Image; MemoryStream m = new MemoryStream(); iImage.Save(m, iImage.RawFormat); byte[] imageBytes = m.ToArray(); ImageViewModel image = new ImageViewModel(); image.Source = Convert.ToBase64String(imageBytes); optionImages.Add(image); break; } } } } optionCheck.Content = optionModel.OptionContent; optionCheckList.Add(optionCheck); optionModel.Images = optionImages; if (optionModel.OptionContent != null || (optionModel.Images != null && optionModel.Images.Count() != 0)) { options.Add(optionModel); } optionModel = new OptionViewModel(); } #endregion else if (key.Contains("ANSWER:")) { IEntity bodyItemEntity = row.Cells[1].ChildEntities[0]; WParagraph paragraph = bodyItemEntity as WParagraph; if (!paragraph.Text.Equals("")) { var trim = paragraph.Text.Replace(" ", "").ToLower(); char[] answers = trim.ToCharArray(); foreach (var optionCheck in optionCheckList) { for (int i = 0; i < answers.Length; i++) { if (optionCheck.Code.Equals(answers[i].ToString())) { foreach (var option in options) { if (option.OptionContent.Equals(optionCheck.Content)) { option.IsCorrect = true; break; } } break; } } } } } else if (key.Contains("UNIT:")) { IEntity bodyItemEntity = row.Cells[1].ChildEntities[0]; WParagraph paragraph = bodyItemEntity as WParagraph; if (!paragraph.Text.Equals("")) { var number = Regex.Match(paragraph.Text, @"\d+$").ToString(); if (globalPrefix == "") { quesModel.LearningOutcome = paragraph.Text; } else { quesModel.LearningOutcome = globalPrefix + " " + number; } } } else if (key.Contains("MARK:")) { IEntity bodyItemEntity = row.Cells[1].ChildEntities[0]; WParagraph paragraph = bodyItemEntity as WParagraph; switch (paragraph.Text) { //default: // quesModel.Level = "Easy"; // break; case "1": quesModel.Level = "Easy"; break; case "2": quesModel.Level = "Medium"; break; case "3": quesModel.Level = "Hard"; break; } } else if (key.Contains("CATEGORY:")) { IEntity bodyItemEntity = row.Cells[1].ChildEntities[0]; WParagraph paragraph = bodyItemEntity as WParagraph; if (paragraph != null && !paragraph.Text.Equals("")) { quesModel.Category = paragraph.Text; } } } if (images != null) { quesModel.Images = images; } quesModel.Options = options; listQuestion.Add(quesModel); quesModel = new QuestionTmpModel(); images = new List <ImageViewModel>(); options = new List <OptionViewModel>(); optionCheckList = new List <DocViewModel>(); }
public ActionResult DocIOFeatures(string Group1) { if (Group1 == null) { return(View()); } string dataPath3 = ResolveApplicationDataPath("", "Content\\Images\\DocIO"); //A new document is created. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; //Appends paragraph. IWParagraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; WTextRange textRange = paragraph.AppendText("Syncfusion Metro Studio") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Syncfusion Metro Studio is a collection of over 1700 Metro-style icon templates that can be easily customized to create thousands of unique Metro icons. Metro is a design language so it can be applied to any platform or technology. At Syncfusion we have used these icons in everything from PowerPoint presentations to applications written in all .NET platforms including WPF, Silverlight, Windows Phone, Windows Forms, ASP.NET, and ASP.NET MVC.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; #region Insert Table. //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph. WPicture picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio1.png"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Developer-friendly icon editor "); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Metro Studio includes a powerful icon editor that lets you quickly find and customize all the icons that you need in only a few minutes. ") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Convert fonts to icons "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Easily customize thousands of font characters as icons and export them to the desired formats. ") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio2.png"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "MetroStudio3.png"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -4.9f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Organize icons as projects "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Organize icons into projects that can be serialized for modification at a later time. Multiple icons in a project can be exported with a single click. ") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; #endregion //Appends paragraph. section.AddParagraph(); #region saveOption if (Group1 == "Word97To2003") { //Save as .doc Word 97-2003 format return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2007 format else if (Group1 == "Word2007") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2007, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2010 format else if (Group1 == "Word2010") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2010, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx Word 2013 format else if (Group1 == "Word2013") { return(document.ExportAsActionResult("Sample.docx", FormatType.Word2013, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } #endregion saveOption return(View()); }
/// <summary> /// Create a simple Word document /// </summary> /// <returns>Return the created Word document as stream</returns> public MemoryStream CreateWordDocument(string documentType) { //Creating a new document WordDocument document = new WordDocument(); //Adding a new section to the document WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); string basePath = _hostingEnvironment.WebRootPath + @"/images/DocIO/"; FileStream imageStream = new FileStream(basePath + @"AdventureCycle.jpg", FileMode.Open, FileAccess.Read); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -45; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, 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.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = 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.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph imageStream = new FileStream(basePath + @"Mountain-200.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph imageStream = new FileStream(basePath + @"Mountain-300.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph imageStream = new FileStream(basePath + @"Road-550-W.jpg", FileMode.Open, FileAccess.Read); picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends paragraph section.AddParagraph(); FormatType formatType = FormatType.Docx; //Save as .doc format if (documentType == "WordDoc") { formatType = FormatType.Doc; } //Save as .xml format else if (documentType == "WordML") { formatType = FormatType.WordML; } //Save the document as a stream and retrun the stream using (MemoryStream stream = new MemoryStream()) { //Save the created Word document to MemoryStream document.Save(stream, formatType); document.Close(); stream.Position = 0; return(stream); } }
void OnButtonClicked(object sender, EventArgs e) { Assembly assembly = typeof(App).GetTypeInfo().Assembly; // Creating a new document. // Creating a new document. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new Syncfusion.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = Syncfusion.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); Stream imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.AdventureCycle.jpg"); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -24; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = Syncfusion.Drawing.Color.Red; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, 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.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = 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.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Mountain-200.jpg"); //Appends picture to the paragraph. picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Mountain-300.jpg"); //Appends picture to the paragraph. picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; imageStream = assembly.GetManifestResourceStream("SampleBrowser.Samples.DocIO.Templates.Road-550-W.jpg"); //Appends picture to the paragraph. picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 0; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -4.9f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends paragraph. section.AddParagraph(); MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Word2013); document.Close(); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save("GettingStarted.docx", "application/msword", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save("GettingStarted.docx", "application/msword", stream); } }
public ActionResult ImageInsertion(string Group1) { if (Group1 == null) { return(View()); } //Create a new document WordDocument document = new WordDocument(); //Adding a new section to the document. IWSection section = document.AddSection(); //Adding a paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Writing text. paragraph.AppendText("This sample demonstrates how to insert Vector and Scalar images inside a document."); //Adding a new paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; string basePath = _hostingEnvironment.WebRootPath; FileStream imageStream = new FileStream(basePath + @"/images/DocIO/yahoo.gif", FileMode.Open, FileAccess.Read); //Inserting .gif . WPicture picture = (WPicture)paragraph.AppendPicture(imageStream); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = new FileStream(basePath + @"/images/DocIO/Reports.bmp", FileMode.Open, FileAccess.Read); //Inserting .bmp picture = (WPicture)paragraph.AppendPicture(imageStream); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = new FileStream(basePath + @"/images/DocIO/google.png", FileMode.Open, FileAccess.Read); //Inserting .png picture = (WPicture)paragraph.AppendPicture(imageStream); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = new FileStream(basePath + @"/images/DocIO/Square.tif", FileMode.Open, FileAccess.Read); //Inserting .tif picture = (WPicture)paragraph.AppendPicture(imageStream); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Adding a new paragraph. paragraph = section.AddParagraph(); //Setting Alignment for the image. paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = new FileStream(basePath + @"/images/DocIO/Ess chart.emf", FileMode.Open, FileAccess.Read); //Inserting .wmf Image to the document. WPicture mImage = (WPicture)paragraph.AppendPicture(imageStream); //Scaling Image mImage.HeightScale = 50f; mImage.WidthScale = 50f; //Adding Image caption mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Updates the fields in Word document document.UpdateDocumentFields(); FormatType type = FormatType.Docx; string filename = "Sample.docx"; string contenttype = "application/vnd.ms-word.document.12"; #region Document SaveOption //Save as .doc format if (Group1 == "WordDoc") { type = FormatType.Doc; filename = "Sample.doc"; contenttype = "application/msword"; } //Save as .xml format else if (Group1 == "WordML") { type = FormatType.WordML; filename = "Sample.xml"; contenttype = "application/msword"; } #endregion Document SaveOption MemoryStream ms = new MemoryStream(); document.Save(ms, type); document.Close(); ms.Position = 0; return(File(ms, contenttype, filename)); }
public ActionResult HelloWorld(string Group1) { if (Group1 == null) { return(View()); } dataPath3 = ResolveApplicationDataPath("", "Images\\DocIO"); // Creating a new document. WordDocument document = new WordDocument(); //Adding a new section to the document. WSection section = document.AddSection() as WSection; //Set Margin of the section section.PageSetup.Margins.All = 72; //Set page size of the section section.PageSetup.PageSize = new System.Drawing.SizeF(612, 792); //Create Paragraph styles WParagraphStyle style = document.AddParagraphStyle("Normal") as WParagraphStyle; style.CharacterFormat.FontName = "Calibri"; style.CharacterFormat.FontSize = 11f; style.ParagraphFormat.BeforeSpacing = 0; style.ParagraphFormat.AfterSpacing = 8; style.ParagraphFormat.LineSpacing = 13.8f; style = document.AddParagraphStyle("Heading 1") as WParagraphStyle; style.ApplyBaseStyle("Normal"); style.CharacterFormat.FontName = "Calibri Light"; style.CharacterFormat.FontSize = 16f; style.CharacterFormat.TextColor = System.Drawing.Color.FromArgb(46, 116, 181); style.ParagraphFormat.BeforeSpacing = 12; style.ParagraphFormat.AfterSpacing = 0; style.ParagraphFormat.Keep = true; style.ParagraphFormat.KeepFollow = true; style.ParagraphFormat.OutlineLevel = OutlineLevel.Level1; IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph(); WPicture picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "AdventureCycle.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.VerticalPosition = -45; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = 263.5f; picture.WidthScale = 20; picture.HeightScale = 15; paragraph.ApplyStyle("Normal"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; WTextRange textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Calibri"; textRange.CharacterFormat.TextColor = System.Drawing.Color.Red; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; textRange = paragraph.AppendText("Adventure Works Cycles") as WTextRange; textRange.CharacterFormat.FontSize = 18f; textRange.CharacterFormat.FontName = "Calibri"; //Appends paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = paragraph.AppendText("Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, 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.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.FirstLineIndent = 36; paragraph.BreakCharacterFormat.FontSize = 12f; textRange = 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.") as WTextRange; textRange.CharacterFormat.FontSize = 12f; paragraph = section.AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Left; textRange = paragraph.AppendText("Product Overview") as WTextRange; textRange.CharacterFormat.FontSize = 16f; textRange.CharacterFormat.FontName = "Calibri"; //Appends table. IWTable table = section.AddTable(); table.ResetCells(3, 2); table.TableFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.None; table.TableFormat.IsAutoResized = true; //Appends paragraph. paragraph = table[0, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Mountain-200.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 4.5f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -2.15f; picture.WidthScale = 79; picture.HeightScale = 79; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-200"); //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M68B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 25\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $2,294.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[0, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Mountain-300 "); //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-M47B-38\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 35\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 22\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $1,079.99\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. paragraph = table[1, 0].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; //Appends paragraph. paragraph = table[1, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Mountain-300.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 8.2f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -14.95f; picture.WidthScale = 75; picture.HeightScale = 75; //Appends paragraph. paragraph = table[2, 0].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.LineSpacing = 12f; //Appends picture to the paragraph. picture = paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath3, "Road-550-W.jpg"))) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.TopAndBottom; picture.VerticalOrigin = VerticalOrigin.Paragraph; picture.VerticalPosition = 3.75f; picture.HorizontalOrigin = HorizontalOrigin.Column; picture.HorizontalPosition = -5f; picture.WidthScale = 92; picture.HeightScale = 92; //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ApplyStyle("Heading 1"); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.AppendText("Road-150 "); //Appends paragraph. paragraph = table[2, 1].AddParagraph(); paragraph.ParagraphFormat.AfterSpacing = 0; paragraph.ParagraphFormat.LineSpacing = 12f; paragraph.BreakCharacterFormat.FontSize = 12f; paragraph.BreakCharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Product No: BK-R93R-44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Size: 44\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Weight: 14\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; textRange = paragraph.AppendText("Price: $3,578.27\r") as WTextRange; textRange.CharacterFormat.FontSize = 12f; textRange.CharacterFormat.FontName = "Times New Roman"; //Appends paragraph. section.AddParagraph(); #region 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 saveOption return(View()); }
public void FillDocIos() { string MyFile = ""; try { pdRow = dbcv.dbCon.Get <PersonendatenTableItem>(dbcv.CurrentCVID); } catch (Exception) { return; //throw; } MyFile = pdRow.NameCV + ".docx"; var query = dbcv.dbCon.Table <KontaktdatenTableItem>().Where(v => v.PersonendatenID == dbcv.CurrentCVID); if (query.Count() > 0) { pdRowContact = query.First(); } var query1 = dbcv.dbCon.Table <ImagesTableItem>().Where(v => v.PersonendatenID == dbcv.CurrentCVID); if (query1.Count() > 0) { pdRowImage = query1.First(); } Assembly assembly = typeof(App).GetTypeInfo().Assembly; // Creating a new document. //TEST //string resname; //foreach (string resourceName in assembly.GetManifestResourceNames()) //{ // resname = resourceName; //} WordDocument document = new WordDocument(); Stream inputStream = assembly.GetManifestResourceStream("Lebenslauf.Templates.Lebenslauf02ios.docx"); //Open Template document document.Open(inputStream, FormatType.Word2013); inputStream.Dispose(); //Handler für das Foto (Android) //document.MailMerge.MergeImageField += new MergeImageFieldEventHandler(Person_Photo); //FOTO ios Stream imageStream; byte[] bytes = dbcv.LoadImageDataFromDB(); if (bytes != null) { var resizer = DependencyService.Get <IMediaService>(); var resizedBytes = resizer.ResizeImage(bytes, 137, 140); //Ein Fehler in ResizeImage vertauscht die Höhe und Breite des Bildes, dies wird beim Einfügen in das Word Dokument ausgeglichen imageStream = new MemoryStream(resizedBytes); } else { //Assembly assembly = GetType().Assembly(); imageStream = assembly.GetManifestResourceStream("Lebenslauf.Foto.png"); } IWParagraph paragraph = document.LastParagraph; WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText; picture.VerticalOrigin = VerticalOrigin.Margin; picture.HorizontalOrigin = 0; picture.VerticalPosition = 20; picture.HorizontalPosition = 350; // Korrektur eines Fehlers in der ResizeImage-Funktion. Bei dem Bild sind höhe und Breite vertauscht float w = picture.Width; float h = picture.Height; picture.Width = h; picture.Height = w; //Skalieren //float scale = (100 / h); //picture.Width = w * scale; //picture.Height = h * scale; // w = picture.Width; // h = picture.Height; //picture.VerticalOrigin = VerticalOrigin.Margin; //picture.HorizontalOrigin = 0; //picture.VerticalPosition = 90; //picture.HorizontalPosition = 350; //picture.Width = 137; //picture.Height = 140; //picture.WidthScale = 10; //picture.HeightScale = 20; //picture.Width = picture.Height; //picture.Height = picture.Width; //Arbeit List <Works> workslist = GetWorksList(); MailMergeDataTable dtw = new MailMergeDataTable("Works", workslist); document.MailMerge.ExecuteNestedGroup(dtw); ////Ausbildung List <Ausbildung> ausbildungslist = GetAusbildungList(); MailMergeDataTable dta = new MailMergeDataTable("Ausbildungs", ausbildungslist); document.MailMerge.ExecuteNestedGroup(dta); ////Schule List <Schule> schulelist = GetSchuleList(); MailMergeDataTable dts = new MailMergeDataTable("Schools", schulelist); document.MailMerge.ExecuteNestedGroup(dts); ////Advances List <Advance> advancelist = GetAdvanceList(); MailMergeDataTable dtad = new MailMergeDataTable("Advances", advancelist); document.MailMerge.ExecuteNestedGroup(dtad); ////Führerschein List <Licence> licencelist = GetLicenceList(); MailMergeDataTable dtl = new MailMergeDataTable("DriveLicenses", licencelist); document.MailMerge.ExecuteNestedGroup(dtl); ////Sprachen List <Sprache> sprachelist = GetLanguagesList(); MailMergeDataTable dtsp = new MailMergeDataTable("Languages", sprachelist); document.MailMerge.ExecuteNestedGroup(dtsp); //Sonstiges List <Sonstiges> sonstigeslist = GetSonstigesList(); MailMergeDataTable dftxt = new MailMergeDataTable("FreiTexts", sonstigeslist); document.MailMerge.ExecuteNestedGroup(dftxt); //Computer List <ComputerKentnisse> computerlist = GetComputerList(); MailMergeDataTable dcmp = new MailMergeDataTable("Computers", computerlist); document.MailMerge.ExecuteNestedGroup(dcmp); //Personendaten string gebdat; gebdat = pdRow.GebDat.ToString(DATEFORMAT); string[] fieldNames = new string[] { "FirstName", "Lastname", "Nation", "BirDate", "BirCountry", "BirCity", "Society", "Child", "Street", "ZipCode", "City", "Tel", "Email", "Hobby" }; string[] fieldValues = new string[] { pdRow.Vorname, pdRow.Nachname, pdRow.Nationalität, gebdat, pdRow.GebLand, pdRow.GebOrt, pdRow.Familienstand, pdRow.Kinder, NullToString(pdRowContact.Strasse), NullToString(pdRowContact.PLZ), NullToString(pdRowContact.Ort), NullToString(pdRowContact.Telefon), NullToString(pdRowContact.Email), pdRow.Hobbies }; document.MailMerge.Execute(fieldNames, fieldValues); MemoryStream stream = new MemoryStream(); document.Save(stream, FormatType.Word2013); document.Close(); //dbcv.dbCon.Close(); if (Device.OS == TargetPlatform.WinPhone || Device.OS == TargetPlatform.Windows) { Xamarin.Forms.DependencyService.Get <ISaveWindowsPhone>().Save(MyFile, "application/msword", stream); } else { Xamarin.Forms.DependencyService.Get <ISave>().Save(MyFile, "application/msword", stream); } }
private async void btnGuardar_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { try { if (document != null) { document.Close(); document = null; } if (document == null) { document = new WordDocument(); docStream = File.OpenRead(Path.GetFullPath(sFilePathWord)); await document.OpenAsync(docStream, FormatType.Docx); docStream.Dispose(); } foreach (var x in textBoxes) { replace(x.Name, x.Text, sFilePathWord); } foreach (var z in richEditBoxes) { string valor; z.TextDocument.GetText(Windows.UI.Text.TextGetOptions.None, out valor); replace(z.Name, valor, sFilePathWord); } foreach (var x in comboBoxes) { if (x.SelectedItem == null) { replace(x.Name, "", sFilePathWord); } else if (x.Name.ToLower().Contains("nombre_tutor")) { replace("Grupo", (x.SelectedItem as TutoresProfesores).grupo + " de " + (x.SelectedItem as TutoresProfesores).semestre + " semestre", sFilePathWord); replace("Correo", (x.SelectedItem as TutoresProfesores).correo, sFilePathWord); if ((x.SelectedItem as TutoresProfesores).imagen != null) { //TextSelection textSelections = document.Find(new Regex("^<[Imagen]>")); Stream imageStream = (x.SelectedItem as TutoresProfesores).imagen; WParagraph paragraph = new WParagraph(document); WPicture picture = paragraph.AppendPicture(imageStream) as WPicture; picture.Width = 60; picture.Height = 60; TextSelection newSelection = new TextSelection(paragraph, 0, 1); TextBodyPart bodyPart = new TextBodyPart(document); bodyPart.BodyItems.Add(paragraph); document.Replace("<[Imagen]>", bodyPart, true, true); } replace(x.Name, x.SelectedItem.ToString(), sFilePathWord); } replace(x.Name, x.SelectedItem.ToString(), sFilePathWord); } foreach (var fecha in datePickers) { if (fecha.SelectedDate == null) { fecha.SelectedDate = DateTime.UtcNow; } if (fecha.Name.ToLower().Contains("año")) { replace(fecha.Name, fecha.Date.DateTime.ToString("yyyy"), sFilePathWord); } else { replace(fecha.Name, fecha.Date.DateTime.ToString("MMMM"), sFilePathWord); } } foreach (var dp in calendarDatePickers) { if (dp.Date.Value.DateTime == null) { dp.Date = DateTime.UtcNow; } replace(dp.Name, dp.Date.Value.DateTime.ToString("dd/MMMM/yyyy"), sFilePathWord); } if (checkBoxes != null) { foreach (var cb in checkBoxes) { if (cb.IsChecked == true) { replace(cb.Name, "x", sFilePathWord); } else { replace(cb.Name, "", sFilePathWord); } } } replace("Jefe_Tutorias", await DBAssets.getStringAsync((App.Current as App).ConnectionString, "SELECT nombre FROM CoordinadoresTutorias;"), sFilePathWord); replace("Jefe_Departamento", await DBAssets.getStringAsync((App.Current as App).ConnectionString, "SELECT nombre FROM JefesDepartamentos WHERE id_jefe = 1;"), sFilePathWord); replace("Jefe_Tutorias_Institucional", await DBAssets.getStringAsync((App.Current as App).ConnectionString, "SELECT nombre FROM CoordinadoresTutoriasInstitucionales;"), sFilePathWord); replace("Jefe_Desarrollo_Académico", await DBAssets.getStringAsync((App.Current as App).ConnectionString, "SELECT nombre FROM JefesDepartamentos WHERE id_jefe = 2;"), sFilePathWord); FileSavePicker savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = PickerLocationId.Desktop; savePicker.SuggestedFileName = "Resultado"; savePicker.FileTypeChoices.Add("Word Documents", new List <string>() { ".docx" }); StorageFile outputStorageFile = await savePicker.PickSaveFileAsync(); await document.SaveAsync(outputStorageFile, FormatType.Docx); } catch (Exception ex) { var err = new MessageDialog("Unable to open File!" + ex.Message); await err.ShowAsync(); } }
public ActionResult ImageInsertion(string Group1) { if (Group1 == null) { return(View()); } //Create a new document WordDocument document = new WordDocument(); //Adding a new section to the document. IWSection section = document.AddSection(); //Adding a paragraph to the section IWParagraph paragraph = section.AddParagraph(); dataPath2 = ResolveApplicationDataPath("", "Content\\DocIO"); //Writing text. paragraph.AppendText("This sample demonstrates how to insert Vector and Scalar images inside a document."); //Adding a new paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .gif . WPicture picture = (WPicture)paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath2, "yahoo.gif"))); //Adding Image caption picture.AddCaption("Yahoo [.gif Image]", CaptionNumberingFormat.Roman, CaptionPosition.AboveImage); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .bmp picture = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath2 + "Reports.bmp")); //Adding Image caption picture.AddCaption("Reports [.bmp Image]", CaptionNumberingFormat.Roman, CaptionPosition.AboveImage); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .png picture = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath2 + "google.PNG")); //Adding Image caption picture.AddCaption("Google [.png Image]", CaptionNumberingFormat.Roman, CaptionPosition.AboveImage); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .tif picture = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath2 + "Square.tif")); //Adding Image caption picture.AddCaption("Square [.tif Image]", CaptionNumberingFormat.Roman, CaptionPosition.AboveImage); //Adding a new paragraph. paragraph = section.AddParagraph(); //Setting Alignment for the image. paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .wmf Image to the document. WPicture mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath2 + "Ess chart.emf")); //Scaling Image mImage.HeightScale = 50f; mImage.WidthScale = 50f; //Adding Image caption mImage.AddCaption("Chart Vector Image", CaptionNumberingFormat.Roman, CaptionPosition.AboveImage); //Save as .doc format if (Group1 == "WordDoc") { return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx format else if (Group1 == "WordDocx") { return(document.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(document.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .pdf format else if (Group1 == "Pdf") { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(document); return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } return(View()); }
private void button1_Click(object sender, EventArgs e) { try { #if NETCORE string TemplatePath = @"..\..\..\..\..\..\..\common\Data\DocIO\"; #else string TemplatePath = @"..\..\..\..\..\..\common\Data\DocIO\"; #endif WordDocument dest = new WordDocument(); dest.EnsureMinimal(); //Set Margin of the section dest.Sections[0].PageSetup.Margins.All = 72; WordDocument oleSource; if (wordDocRadioBtn.Checked) { oleSource = new WordDocument(TemplatePath + "OleTemplate.doc"); } else { oleSource = new WordDocument(TemplatePath + "OleTemplate.docx"); } WOleObject oleObject = null; // Get OLE object from source document for (int i = 0; i < oleSource.LastSection.Paragraphs[4].Items.Count; i++) { if (oleSource.LastSection.Paragraphs[4].Items[i] is WOleObject) { oleObject = oleSource.LastSection.Paragraphs[4].Items[i] as WOleObject; break; } } WPicture pic = oleObject.OlePicture.Clone() as WPicture; dest.LastParagraph.AppendText("OLE Object Demo"); dest.LastParagraph.ApplyStyle(BuiltinStyle.Heading1); dest.LastParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; dest.Sections[0].AddParagraph(); dest.LastParagraph.AppendText("MS Excel Object Inserted"); dest.LastParagraph.ApplyStyle(BuiltinStyle.Heading2); dest.Sections[0].AddParagraph(); // AppendOLE object to the destination document oleObject = dest.LastParagraph.AppendOleObject(oleObject.Container, pic, OleLinkType.Embed); oleObject.DisplayAsIcon = checkBoxChoose.Checked; //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. dest.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 dest.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); } }
/// <summary> /// Inserts images into the Word document. /// </summary> private void Button_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) { //Creates a new Word document. using WordDocument document = new(); //Adds a new section to the document. IWSection section = document.AddSection(); section.PageSetup.Margins.All = 72; //Adds a paragraph to the section. IWParagraph paragraph = section.AddParagraph(); //Writes the text. paragraph.AppendText("This sample demonstrates how to insert images in a Word document."); //Adds a new paragraph. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; paragraph.ParagraphFormat.BeforeSpacing = 12f; Assembly assembly = typeof(ImageInsertion).GetTypeInfo().Assembly; string basePath = "syncfusion.dociodemos.winui.Assets.DocIO."; Stream imageStream = assembly.GetManifestResourceStream(basePath + "AdventureCycle.png"); //Inserts .png image. WPicture picture = (WPicture)paragraph.AppendPicture(imageStream); //Scales the Image. picture.HeightScale = 25f; picture.WidthScale = 25f; //Adds Image caption. picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Inserts .jpg image. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = assembly.GetManifestResourceStream(basePath + "Mountain200.jpg"); picture = (WPicture)paragraph.AppendPicture(imageStream); //Adds Image caption. picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Inserts .bmp image. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = assembly.GetManifestResourceStream(basePath + "Mountain300.bmp"); picture = (WPicture)paragraph.AppendPicture(imageStream); //Adds Image caption. picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Inserts .jpg image. paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; imageStream = assembly.GetManifestResourceStream(basePath + "Road550W.jpg"); picture = (WPicture)paragraph.AppendPicture(imageStream); //Adds Image caption. picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Updates the fields in Word document. document.UpdateDocumentFields(); #region Document SaveOption using MemoryStream ms = new(); string filename = string.Empty; //Saves as .docx format. if (worddocx.IsChecked == true) { filename = "Image Insertion.docx"; //Saves the Word document to the memory stream. document.Save(ms, FormatType.Docx); } //Saves as .doc format. else if (worddoc.IsChecked == true) { filename = "Image Insertion.doc"; //Saves the Word document to the memory stream. document.Save(ms, FormatType.Doc); } //Saves as .pdf format. else if (pdf.IsChecked == true) { filename = "Image Insertion.pdf"; //Creates a new DocIORenderer instance. using DocIORenderer renderer = new(); //Converts Word document into PDF. using PdfDocument pdfDoc = renderer.ConvertToPDF(document); //Saves the PDF document to the memory stream. pdfDoc.Save(ms); } ms.Position = 0; //Saves the memory stream as file. SaveHelper.SaveAndLaunch(filename, ms); #endregion Document SaveOption }
private void button1_Click(object sender, System.EventArgs e) { try { //Getting Image files path. string dataPath = Application.StartupPath + @"..\..\..\..\..\..\..\..\Common\images\DocIO\"; //Create a new document WordDocument document = new WordDocument(); //Adding a new section to the document. IWSection section = document.AddSection(); //Set Margin of the section section.PageSetup.Margins.All = 72; //Adding a paragraph to the section IWParagraph paragraph = section.AddParagraph(); //Writing text. paragraph.AppendText("This sample demonstrates how to insert Vector and Scalar images inside a document."); //Adding a new paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .gif . WPicture mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath + "yahoo.gif")); //Adding Image caption mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .bmp mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath + "Reports.bmp")); //Adding Image caption mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .png mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath + "google.PNG")); //Adding Image caption mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .tif mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath + "Square.tif")); //Adding Image caption mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Adding a new paragraph. paragraph = section.AddParagraph(); //Setting Alignment for the image. paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .emf Image to the document. mImage = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath + "Ess chart.emf")); //Scaling Image mImage.HeightScale = 50f; mImage.WidthScale = 50f; //Adding Image caption mImage.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Updates the fields in Word document document.UpdateDocumentFields(); //Save as doc format if (wordDocRadioBtn.Checked) { //Saving the document to disk. document.Save("Image Insertion.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("Image Insertion.doc") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start(@"Image Insertion.doc"); #endif //Exit this.Close(); } } //Save as docx format else if (wordDocxRadioBtn.Checked) { //Saving the document as .docx document.Save("Image Insertion.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("Image Insertion.docx") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start(@"Image Insertion.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("Image Insertion.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("Image Insertion.pdf") { UseShellExecute = true }; process.Start(); #else System.Diagnostics.Process.Start(@"Image Insertion.pdf"); #endif //Exit this.Close(); } catch (Exception ex) { MessageBoxAdv.Show("PDF Viewer is not installed in this system"); Console.WriteLine(ex.ToString()); } } } else { // Exit this.Close(); } } catch (Exception Ex) { MessageBox.Show(Ex.Message); } }
public ActionResult InsertBreak(string Group1) { if (Group1 == null) { return(View()); } //Creating a new document WordDocument document = new WordDocument(); //Adding a new section. IWSection section = document.AddSection(); IWParagraph paragraph = section.AddParagraph(); paragraph = section.AddParagraph(); section.PageSetup.Margins.All = 20f; IWTextRange text = paragraph.AppendText("Adventure products"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText("In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group "); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; #region Line break paragraph.AppendBreak(BreakType.LineBreak); paragraph.AppendBreak(BreakType.LineBreak); #endregion Line break section = document.AddSection(); section.BreakCode = SectionBreakCode.NoBreak; section.PageSetup.Margins.All = 20f; //Adding three columns to section. section.AddColumn(100, 15); section.AddColumn(100, 15); section.AddColumn(100, 15); //Set the columns to be of equal width. section.MakeColumnsEqual(); //Adding a new paragraph to the section. paragraph = section.AddParagraph(); //Adding text. text = paragraph.AppendText("Mountain-200"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; //Adding a new paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); //Inserting an Image. WPicture picture = paragraph.AppendPicture(new Bitmap(ResolveApplicationDataPath("Mountain-200.jpg", "Content\\DocIO"))) as WPicture; picture.Width = 120f; picture.Height = 90f; //Adding a new paragraph to the section. section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; //Adding text. paragraph.AppendText(@"Product No:BK-M68B-38" + "\n" + "Size: 38" + "\n" + "Weight: 25\n" + "Price: $2,294.99"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; // Set column break as true. It navigates the cursor position to the next Column. paragraph.ParagraphFormat.ColumnBreakAfter = true; paragraph = section.AddParagraph(); text = paragraph.AppendText("Mountain-300"); text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; section.AddParagraph(); paragraph = section.AddParagraph(); picture = paragraph.AppendPicture(new Bitmap(ResolveApplicationDataPath("Mountain-300.jpg", "Content\\DocIO"))) as WPicture; picture.Width = 120f; picture.Height = 90f; section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText(@"Product No:BK-M4-38" + "\n" + "Size: 35\n" + "Weight: 22" + "\n" + "Price: $1,079.99"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; paragraph.ParagraphFormat.ColumnBreakAfter = true; paragraph = section.AddParagraph(); text = paragraph.AppendText("Road-150"); text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; section.AddParagraph(); paragraph = section.AddParagraph(); picture = paragraph.AppendPicture(new Bitmap(ResolveApplicationDataPath("Road-550-W.jpg", "Content\\DocIO"))) as WPicture; picture.Width = 120f; picture.Height = 90f; section.AddParagraph(); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText(@"Product No: BK-R93R-44" + "\n" + "Size: 44" + "\n" + "Weight: 14" + "\n" + "Price: $3,578.27"); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; section = document.AddSection(); section.BreakCode = SectionBreakCode.NoBreak; section.PageSetup.Margins.All = 20f; text = section.AddParagraph().AppendText("First Look\n"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText(@"Adventure Works Cycles, the fictitious company, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 employees, several regional sales teams are located throughout their market base."); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; paragraph.ParagraphFormat.PageBreakAfter = true; paragraph = section.AddParagraph(); text = paragraph.AppendText("Introduction\n"); //Formatting Text text.CharacterFormat.FontName = "Bitstream Vera Sans"; text.CharacterFormat.FontSize = 12f; text.CharacterFormat.Bold = true; paragraph = section.AddParagraph(); paragraph.ParagraphFormat.LineSpacing = 20f; paragraph.AppendText(@"In 2000, Adventure Works Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the Adventure Works Cycles product line. These subcomponents are shipped to the Bothell location for final product assembly. In 2001, Importadores Neptuno, became the sole manufacturer and distributor of the touring bicycle product group."); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Justify; //Save as .doc format if (Group1 == "WordDoc") { return(document.ExportAsActionResult("Sample.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx format else if (Group1 == "WordDocx") { return(document.ExportAsActionResult("Sample.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(document.ExportAsActionResult("Sample.xml", FormatType.WordML, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .pdf format else if (Group1 == "Pdf") { DocToPDFConverter converter = new DocToPDFConverter(); PdfDocument pdfDoc = converter.ConvertToPDF(document); return(pdfDoc.ExportAsActionResult("sample.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } return(View()); }
protected void Button1_Click(object sender, EventArgs e) { //Data folder path is resolved from requested page physical path. string dataPath = new System.IO.DirectoryInfo(Request.PhysicalPath + "..\\..\\..\\App_Data\\DocIO\\").FullName; //Open an existing word document WordDocument oleSource; if (rdButtonDoc.Checked) { oleSource = new WordDocument(Path.Combine(dataPath, "OleTemplate.doc")); } else { oleSource = new WordDocument(Path.Combine(dataPath, "OleTemplate.docx")); } WordDocument dest = new WordDocument(); dest.EnsureMinimal(); // Get OLE object from source document WOleObject oleObject = oleSource.LastParagraph.Items[0] as WOleObject; WPicture pic = oleObject.OlePicture.Clone() as WPicture; dest.LastParagraph.AppendText("OLE Object Demo"); dest.LastParagraph.ApplyStyle(BuiltinStyle.Heading1); dest.LastParagraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; dest.Sections[0].AddParagraph(); dest.LastParagraph.AppendText("Adobe PDF object Inserted"); dest.LastParagraph.ApplyStyle(BuiltinStyle.Heading2); dest.Sections[0].AddParagraph(); // AppendOLE object to the destination document dest.LastParagraph.AppendOleObject(oleObject.Container, pic, OleLinkType.Embed); if (rdButtonDoc.Checked) { //Save as .doc format dest.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment); } //Save as .docx format else if (rdButtonDocx.Checked) { try { dest.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()); } } //Save as WordML(.xml) format else if (rdButtonWordML.Checked) { try { dest.Save("Sample.xml", FormatType.WordML, Response, HttpContentDisposition.Attachment); } catch (Win32Exception ex) { Response.Write("Microsoft Word Viewer or Microsoft Word is not installed in this system"); Console.WriteLine(ex.ToString()); } } }
public ActionResult ImageInsertion(string Group1) { if (Group1 == null) { return(View()); } //Create a new document WordDocument document = new WordDocument(); //Adding a new section to the document. IWSection section = document.AddSection(); section.PageSetup.Margins.All = 72; //Adding a paragraph to the section IWParagraph paragraph = section.AddParagraph(); dataPath2 = ResolveApplicationDataPath("", "Images\\DocIO"); //Writing text. paragraph.AppendText("This sample demonstrates how to insert images inside a document."); //Adding a new paragraph paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .gif . WPicture picture = (WPicture)paragraph.AppendPicture(Image.FromFile(System.IO.Path.Combine(dataPath2, "yahoo.gif"))); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .bmp picture = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath2 + "Reports.bmp")); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .png picture = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath2 + "google.PNG")); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); paragraph = section.AddParagraph(); paragraph.ParagraphFormat.HorizontalAlignment = Syncfusion.DocIO.DLS.HorizontalAlignment.Center; //Inserting .tif picture = (WPicture)paragraph.AppendPicture(Image.FromFile(dataPath2 + "Square.tif")); //Adding Image caption picture.AddCaption("Figure", CaptionNumberingFormat.Roman, CaptionPosition.AfterImage); ApplyFormattingForCaption(document.LastParagraph); //Updates the fields in Word document document.UpdateDocumentFields(); //Save as .doc format if (Group1 == "WordDoc") { return(document.ExportAsActionResult("Image Insertion.doc", FormatType.Doc, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } //Save as .docx format else if (Group1 == "WordDocx") { return(document.ExportAsActionResult("Image Insertion.docx", FormatType.Docx, HttpContext.ApplicationInstance.Response, HttpContentDisposition.Attachment)); } // Save as WordML(.xml) format else if (Group1 == "WordML") { return(document.ExportAsActionResult("Image Insertion.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("Image Insertion.pdf", HttpContext.ApplicationInstance.Response, HttpReadType.Save)); } return(View()); }