|
| 1 | +@page "/DocIO" |
| 2 | +@inject Microsoft.JSInterop.IJSRuntime JS |
| 3 | +@inject HttpClient client |
| 4 | +@using Syncfusion.DocIO |
| 5 | +@using Syncfusion.DocIO.DLS |
| 6 | + |
| 7 | +<h2>Syncfusion DocIO library (DocIO)</h2> |
| 8 | +<p>Syncfusion Blazor DocIO library (DocIO) used to create, read, edit, and convert DocIO files in your applications without Microsoft Office dependencies.</p> |
| 9 | +<button class="btn btn-primary" @onclick="@OpenAndSaveDocument">Open and save Document</button> |
| 10 | + |
| 11 | +@code { |
| 12 | + @functions { |
| 13 | + |
| 14 | + async void OpenAndSaveDocument() |
| 15 | + { |
| 16 | + using (Stream inputStream = await client.GetStreamAsync("sample-data/Input.docx")) |
| 17 | + { |
| 18 | + //Open an existing Word document. |
| 19 | + using (WordDocument document = new WordDocument(inputStream, FormatType.Docx)) |
| 20 | + { |
| 21 | + //Access the section in a Word document. |
| 22 | + IWSection section = document.Sections[0]; |
| 23 | + //Add new paragraph to the section. |
| 24 | + IWParagraph paragraph = section.AddParagraph(); |
| 25 | + paragraph.ParagraphFormat.FirstLineIndent = 36; |
| 26 | + paragraph.BreakCharacterFormat.FontSize = 12f; |
| 27 | + //Add new text to the paragraph. |
| 28 | + IWTextRange textRange = paragraph.AppendText("In 2000, AdventureWorks Cycles bought a small manufacturing plant, Importadores Neptuno, located in Mexico. Importadores Neptuno manufactures several critical subcomponents for the AdventureWorks 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 IWTextRange; |
| 29 | + textRange.CharacterFormat.FontSize = 12f; |
| 30 | + |
| 31 | + //Save the Word document to MemoryStream. |
| 32 | + using (MemoryStream stream = new MemoryStream()) |
| 33 | + { |
| 34 | + document.Save(stream, FormatType.Docx); |
| 35 | + stream.Position = 0; |
| 36 | + //Download the Word document in the browser. |
| 37 | + await JS.SaveAs("Sample.docx", stream.ToArray()); |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | +} |
0 commit comments