GroupDocs Editor Not Working with Kendo

To ensure that your .pptx files render correctly and the images within them are visible on the UI, here’s a practical approach that aligns with your scenario:

Rendering .pptx Files in the UI

  1. Backend Logic:

    • Use the GroupDocs.Editor library on the backend to process .pptx files and convert them into editable HTML. Referencing the example in the GroupDocs documentation, the library generates a fully formatted HTML document, including embedded images.
    using GroupDocs.Editor;
    using GroupDocs.Editor.Options;
    
    // Load the presentation document
    using (Editor editor = new Editor("sample.pptx"))
    {
        // Specify edit options for HTML
        PresentationEditOptions editOptions = new PresentationEditOptions();
        EditableDocument htmlDoc = editor.Edit(editOptions);
    
        // Save the HTML content
        File.WriteAllText("output.html", htmlDoc.GetEmbeddedHtml());
    }
    
    • Store or directly send the resulting HTML (with embedded images) to the frontend.
  2. Frontend Logic:

    • Ensure the HTML returned by the backend is correctly inserted into the DOM.

Here’s an improved and consolidated approach based on your code and the scenario you’ve described. It ensures proper handling of the content rendering in the textarea and resolves the issue of displaying PNG or other embedded elements.

Backend Code (Controller)

public IActionResult Index2()
{
    using (Editor editor = new Editor(@"{PathToFile}\18cc8f2c-e5c5-4b5c-b06b-cbf60fe53445 (1).docx"))
    {
        WordProcessingEditOptions options = new WordProcessingEditOptions(true);
        EditableDocument editableDocument = editor.Edit(options);

        // Get the HTML with embedded styles
        var resp = new HtmlResponse
        {
            Content = editableDocument.GetEmbeddedHtml()
        };
        return View(resp);
    }
}

Frontend Code (Razor View)

@model GroupDocs.Editor.UI.JQueryMVCSample.Controllers.HtmlResponse

@{
    ViewBag.Title = "Document Editor";
    Layout = "_Layout";
}
<!-- Include Kendo Editor CSS -->
<link href="https://kendo.cdn.telerik.com/2019.2.514/styles/kendo.default-v2.min.css" rel="stylesheet" />

<!-- Include Kendo Editor JS -->
<script src="https://kendo.cdn.telerik.com/2019.2.514/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.2.514/js/kendo.all.min.js"></script>

<h2>@ViewBag.Title</h2>

<form id="WordCreatorForm">
    <div id="dv_Editor">
        <textarea id="editor" style="width:100%;height:600px;">
            @Html.Raw(Model.Content)
        </textarea>
    </div>
</form>

<script>
    // Initialize Kendo Editor
    $(document).ready(function () {
        $("#editor").kendoEditor({
            tools: [
                "bold", "italic", "underline",
                "justifyLeft", "justifyCenter", "justifyRight",
                "insertImage", "insertFile", "pdf",
                {
                    name: "fontName",
                    items: [
                        { text: "Andale Mono", value: "Andale Mono" },
                        { text: "Arial", value: "Arial" },
                    ]
                },
                {
                    name: "custom",
                    tooltip: "Add page break",
                    exec: function (e) {
                        var editor = $(this).data("kendoEditor");
                        editor.exec("inserthtml", { value: "<p style='page-break-before: always'>Page break here!</p>" });
                    }
                }
            ]
        });
    });

    // Configure PDF font embedding
    kendo.pdf.defineFont({
        "TSCu_SaiIndira": "../../Content/kendo/2019.2.514/fonts/TSCu_SaiIndira.ttf",
        "Padasalai-TAU-Marutham": "../../Content/kendo/2019.2.514/fonts/Padasalai-TAU-Marutham.ttf",
    });
</script>

Key Improvements in the Code:

  1. HTML Structure:

    • Moved inline JavaScript for editor initialization into a $(document).ready function for better readability and reliability.
  2. Textarea Initialization:

    • Ensured textarea content is properly rendered with @Html.Raw(Model.Content) and not affected by encoding issues.
  3. Error Handling:

    • If PNGs or images fail to load, ensure that image URLs are correctly encoded or resolved.
    • Test with files containing embedded media and debug the output HTML for missing or incorrect paths.

Steps to Debug and Validate:

  1. Check the Content Property:

    • Ensure editableDocument.GetEmbeddedHtml() generates the correct HTML with embedded styles and media (base64 or URL-based).
  2. Test with Various Files:

    • Test .docx files with varying complexity (e.g., multiple images, text styles).
  3. Console Logging:

    • Add console.log to the script to debug any runtime issues in the browser.

By following these improvements and steps, you should have a robust implementation for rendering and editing .docx files with embedded elements in the Kendo Editor.

Can you please provide a working example for the same?

Hello Team,

Any updates???

@Niteen_Jadhav

We’re currently working on providing a working example and appreciate your understanding as we handle support queries on a first-come, first-served basis.

Ok, thank you for the reply.

1 Like

do we have any update?

Hello, @Niteen_Jadhav!

Thank you for your patience. You can find a working example of integrating GroupDocs.Editor with the Kendo WYSIWYG Editor in the following repository:
:point_right: GroupDocs.Editor Kendo Sample

This example demonstrates how to load a document, render it as editable HTML, and use the Kendo Editor for modifications. Feel free to explore it and let us know if you have any further questions!

Hi team,

Thank you for the proposed solution, I check and it is appearing correctly, but only showing 1st 2 pages, below is the sample file for your reference, remaining pages are not appearing, what should we do here?

Automation - Termsheet (Docpro) Template.zip (2.8 MB)

Hi Niteen_Jadhav,

Thank you for reaching out!

The issue you are describing, where only the first 2 pages are appearing, is likely due to the trial mode limitation of the GroupDocs.Viewer library. When a license is not applied, the library operates in trial mode and restricts the output to the first 2 pages of the document.

Solution: Apply a License

To resolve this, you need to ensure that a valid GroupDocs.Viewer license is applied in your code.

Yes you were write I was not applying the license in the file, but I also notice one more thing,

The dates are getting changed in editor. I am using the same document as shared above.

sharing both the screenshot of Date Showing In Viewer and Date Showing In Editor

The Viewer updates form fields or SDTs (like date fields) to the current system date during rendering, while the Editor displays the saved state of the document without such updates. As seen in the Viewer screenshot, the date reflects the current system date, whereas the Editor (similar to MS Word) shows the last saved state of the document.
image.png (44.7 KB)

Hello Team,

this seems to be working fine now, but I am still unable to save the word file again.

below is my code to save the word file,

$('#btnSave').click(function (e) {
    debugger
    e.preventDefault();
    let SaveDetails = {
        FileId: $('#FileId').val(),
        GUID: $('#FileServerId').val(),
        EditorData: $('#editor').text(),
    }
    ajaxCallFunction("POST", "/api/Document/Document/SaveWordFile", JSON.stringify(SaveDetails), function (response) {
        window.close();
    });
});

my api →

[HttpPost]
[Route("api/GroupDocsApi/SaveWordFile")]
public SPResponse SaveWordFile(DocPro.DMS.BusinessEntities.Request.GroupDocs.GetDocumentInfoRequest request)
{
    SPResponse sp = new SPResponse() { ReturnStatus = "-1" };
    string editedHtmlContent = request.EditorData;
    editedHtmlContent = editedHtmlContent.Replace($"src=\"{request.AppDirectory}", $"src=\"{request.ResourceDirectory.Replace("\\", "/")}/");
    editedHtmlContent = editedHtmlContent.Replace($"src = \"{request.AppDirectory}", $"src = \"{request.ResourceDirectory.Replace("\\", "/")}/");

    //string resourceDirectory = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/images");

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

    EditableDocument afterEdit = EditableDocument.FromMarkupAndResourceFolder($"<body>{editedHtmlContent}</body>", request.ResourceDirectory);
    GroupDocs.Editor.Options.WordProcessingSaveOptions saveOptions = new GroupDocs.Editor.Options.WordProcessingSaveOptions();

    using (Editor editor = new Editor(inputFilePath))
    {
        editor.Save(afterEdit, outputFilePath, saveOptions);
    }
    sp.ReturnStatus = "0";
    sp.Ref1 = guid;
    return sp;
}

please note I am not directly calling the groupdocs API but I am calling from another API

Thank you for sharing the details and your code. Based on the provided implementation and the GroupDocs.Editor for .NET sample, it seems the issue might be related to handling the HTML content or saving the document. Here’s an updated explanation considering your use of embedded HTML without requiring external resources:

Client-Side JavaScript

Ensure the EditorData sent to the API contains the full HTML content of the edited document. Using $('#editor').html() should work correctly in this case:

$('#btnSave').click(function (e) {
    e.preventDefault();
    let SaveDetails = {
        FileId: $('#FileId').val(),
        GUID: $('#FileServerId').val(),
        EditorData: $('#editor').html(), // Capture HTML content with embedded resources
    };
    ajaxCallFunction("POST", "/api/GroupDocsApi/SaveWordFile", JSON.stringify(SaveDetails), function (response) {
        if (response.ReturnStatus === "0") {
            alert('File saved successfully.');
            window.close();
        } else {
            alert('Error while saving the file.');
        }
    });
});

Server-Side API

Since you’re working with embedded HTML, you can bypass the need for a ResourceDirectory. You only need to ensure the EditableDocument is created directly from the embedded HTML content.

Here’s the relevant code snippet:

string editedHtmlContent = request.EditorData;

// No need for resource directory since resources are embedded in the HTML
EditableDocument afterEdit = EditableDocument.FromMarkup($"<body>{editedHtmlContent}</body>");

This eliminates the dependency on any external resources and directly processes the embedded HTML content.

Saving the File

Your current approach to saving the file is correct. For clarity, you can specify the output format explicitly if needed, but otherwise, your implementation works well:

WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions
{
    Format = WordProcessingFormats.Docx // Optional: Specify format if needed
};

using (Editor editor = new Editor(inputFilePath))
{
    editor.Save(afterEdit, outputFilePath, saveOptions);
}

Ensure that:

  1. inputFilePath points to the original document before editing.
  2. outputFilePath is writable and correctly formatted for the saved file.

Additional Debugging Tips

  • Log editedHtmlContent before creating the EditableDocument to confirm it contains the correct embedded HTML.
  • Check the paths (inputFilePath and outputFilePath) to ensure they are valid and writable.

Key Points to Note

  • Since you’re using embedded HTML, there’s no need for a ResourceDirectory.
  • Ensure the HTML content in EditorData is valid and well-formed.

References:

If you need further clarification or assistance, feel free to ask.