This is just a Trial license and it will get expires in this month, and we also have a demo with a client coming Friday in that demo the client needs to see the functionality of Groupdocs Editor (Word/Excel/PPT). it will be a great help for us if we could get the solution before coming Friday as we are planning to upgrade the license to the latest version based on the Demo.
Thank you for your prompt response, but the project you have shared is developed in .net 6 and we have .net 4.7 in our development environment and hence we are unable to run and test the application.
and also,
It seems like the team who developed the application (thanks for the team to develop this very quickly) used textarea for the editor.
The team used “tinymce” in the project. (can we develop editor without using tinymce)?
The jQuery structure looks very different in the current project.
The GroupDocs.Editor for .NET is a UI-agnostic API, which means we had the flexibility to choose the UI framework and editor we wanted to use for the application.
While we used TinyMCE in this particular implementation, the API itself does not require the use of any specific front-end WYSIWYG HTML editor. Developers have the freedom to integrate the API with the editor of their choice, be it TinyMCE, CKEditor, or any other suitable option.
Regarding the jQuery structure used in the application, we have provided a dedicated wiki page that demonstrates how the GroupDocs.Editor RESTful API for .NET can be accessed using jQuery. This example code is intended to help you understand how the API can be integrated with the front-end, and you are free to adapt it to your own requirements and preferred coding styles.
Thanks a lot for your prompt response. I have created a project using the example provided by you.
I am facing few errors in this project and I’ll need your help to fix these issues.
I am getting the below error while calling "createNew" Api in my "GroupDocsController" controller
An error has occurred.
An error occurred when trying to create a controller of type ‘GroupDocsController’. Make sure that the controller has a parameterless public constructor.
System.InvalidOperationException
at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()
An error has occurred.
Type ‘GroupDocs_Editor.Controllers.GroupDocsController’ does not have a default constructor
System.ArgumentException
at System.Linq.Expressions.Expression.New(Type type) at System.Web.Http.Internal.TypeActivator.Create[TBase](Type instanceType) at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator) at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
I am sharing the sample project created by me.
and it’ll be a great help if you add the code to view word/excel/ppt document in the editor in my current solution.
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): EDITORNET-2822
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Please note that all free support tickets/issues are assisted on first come first served basis. At the moment we have these demo projects (and the documentation) that we already shared with you. Let us further explain how API could be utilized in the UI application.
And following code to save the updated (content updated using CKEDITOR) document:
public ActionResult SaveEditedDocument(string editor1, string inputFilePath)
{
string editedHtmlContent = editor1;
// Create an EditableDocument from the edited HTML content
EditableDocument afterEdit = EditableDocument.FromMarkup($"<body>{editedHtmlContent}</body>", null);
// Define the output file path and save options
string outputFilePath = @"D:\\output.pdf";
PdfSaveOptions saveOptions = new PdfSaveOptions();
// Use the input file path to create a new Editor instance and save the document
using (Editor editor = new Editor(inputFilePath))
{
editor.Save(afterEdit, outputFilePath, saveOptions);
}
return RedirectToAction("Index");
}
Edit and save options could be changed as per the source file/format (e.g. PdfEditOptions, WordProcessingEditOptions, PdfSaveOptions or WordProcessingSaveOptions).
We already explained that GroupDocs.Editor for .NET is a UI-Agnostic API, you can use any WYSIWYG HTML editor at front end (paid or free).
We already shared file saving code with you that works perfectly fine.
We have plans to develop more demo projects but we do not have any ETA at the moment.
Please take a look at the output.zip (435.7 KB) we are getting using the same code. A new text line is also added at the bottom of the file through the editor “multiple images ahead”. Please reevaluate the save method we shared earlier with you.
and I want to add one more thing when I open the document in Editor and the document contains a header the alignment of the document gets affected, sharing the file and screenshot for your reference.
public IActionResult Index()
{
// Set the license for the Conholdate.Total.Product.Family library
License lic = new License();
lic.SetLicense(@"D:\\GD Licenses\\Conholdate.Total.Product.Family.lic");
// Specify the input file path for the Word document
string inputFilePath = @"D:\\GroupdocsEditor.docx";
// Define the resource directory where the extracted resources will be saved
string resourceDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images");
// Ensure the resource directory exists
Directory.CreateDirectory(resourceDirectory);
// Initialize the editor with the input file path
Editor editor = new Editor(inputFilePath);
// Set the Word processing edit options
WordProcessingEditOptions editOptions = new WordProcessingEditOptions();
editOptions.UseInlineStyles = true;
// Edit the document and get the editable document instance
EditableDocument beforeEdit = editor.Edit(editOptions);
// Extract various resources from the editable document
List<IImageResource> images = beforeEdit.Images;
List<FontResourceBase> fonts = beforeEdit.Fonts;
List<CssText> stylesheets = beforeEdit.Css;
List<Mp3Audio> audiofiles = beforeEdit.Audio;
// Get the HTML content of the editable document
string htmlContent = beforeEdit.GetContent();
// Save the extracted fonts, stylesheets, and audio files to the resource directory
foreach (FontResourceBase oneFont in fonts)
{
oneFont.Save(Path.Combine(resourceDirectory, oneFont.FilenameWithExtension));
}
foreach (CssText oneStylesheet in stylesheets)
{
oneStylesheet.Save(Path.Combine(resourceDirectory, oneStylesheet.FilenameWithExtension));
}
foreach (Mp3Audio oneMp3 in audiofiles)
{
oneMp3.Save(Path.Combine(resourceDirectory, oneMp3.FilenameWithExtension));
}
// Update the HTML content to reference the saved images
htmlContent = beforeEdit.GetContent();
foreach (var image in images)
{
string imageFileName = Path.GetFileName(image.FilenameWithExtension);
string imageFilePath = Path.Combine(resourceDirectory, imageFileName);
// Save the image to the resource directory
using (var fileStream = new FileStream(imageFilePath, FileMode.Create))
{
using (var imageStream = image.ByteContent)
{
imageStream.CopyTo(fileStream);
}
}
// Update the HTML content to reference the correct image path
htmlContent = htmlContent.Replace(image.FilenameWithExtension, $"/images/{imageFileName}");
}
// Optionally, save the updated HTML content to a "debug.html" file for debugging purposes
System.IO.File.WriteAllText(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "debug.html"), htmlContent);
// Pass the updated HTML content to the view using ViewBag
ViewBag.HtmlContent = htmlContent;
// Pass the input file path to the view using TempData
TempData["InputFilePath"] = inputFilePath;
return View();
}
We’d again recommend you to please go through the documentation and existing UI applications.
Yes the image shared by you is much better than what we are achieving but still not looking like the original file.
NOTE: We had fixed the saving issue by changing from $(‘#documentContent’).html() to $(‘#documentContent’).text() before doing the api call, but I want to know one more thing
Below is the code to load the word file →
SPResponse sp = new SPResponse() { ReturnStatus = "-1" };
Editor editor = new Editor(request.FileUploadPath);
WordProcessingEditOptions editOptions = new WordProcessingEditOptions();
editOptions.UseInlineStyles = true;
EditableDocument readyToEdit = editor.Edit(editOptions);
List<IImageResource> images = readyToEdit.Images;
// Save extracted images and update HTML content
string htmlContent = readyToEdit.GetContent();
foreach (var image in images)
{
string imageFileName = Path.GetFileName(image.FilenameWithExtension);
string imageFilePath = Path.Combine(request.ResourceDirectory, imageFileName);
// Save image to the resource directory
using (var fileStream = new FileStream(imageFilePath, FileMode.Create))
{
using (var imageStream = image.ByteContent)
{
await imageStream.CopyToAsync(fileStream);
}
}
htmlContent = htmlContent.Replace(image.FilenameWithExtension, request.AppDirectory + "\\" + imageFileName);
}
string cssContent = string.Join("\n", readyToEdit.GetCssContent());
sp.Ref1 = htmlContent;
sp.Ref2 = cssContent;
return sp;
and my saveFile Code
SPResponse sp = new SPResponse() { ReturnStatus = "-1" };
string editedHtmlContent = request.EditorData;
string inputFilePath = Path.Combine(request.StoragePath, request.GUID);
string guid = Guid.NewGuid().ToString();
string extension = Path.GetExtension(request.GUID);
string outputFilePath = Path.Combine(request.StoragePath, guid + "." + extension);
// Create an EditableDocument from the edited HTML content
EditableDocument afterEdit = EditableDocument.FromMarkup($"<body>{editedHtmlContent}</body>", null);
WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions();
// Use the input file path to create a new Editor instance and save the document
using (Editor editor = new Editor(inputFilePath))
{
editor.Save(afterEdit, outputFilePath, saveOptions);
}
sp = new SPResponse() { ReturnStatus = "0", Ref1 = guid };
return sp;
can you please help me with how to also save images with the document as the images are not getting save while saving the document.