Hello Team,
I am working with Editor in my application, I took help from Groupdocs team for Editor with DOCX file and I got the code from the team, Code below.
[HttpPost]
[Route("api/GroupDocsApi/CreateEmptyWordFile")]
public async Task<SPResponse> CreateEmptyWordFile(DocPro.DMS.BusinessEntities.Request.GroupDocs.GetDocumentInfoRequest request)
{
try
{
Document document = new Document();
await Task.Run(() => document.Save(request.FileUploadPath));
return new SPResponse() { ReturnStatus = "0" };
}
catch (Exception ex)
{
return new SPResponse() { ReturnStatus = "-1", ReturnMessage = ex.Message };
}
}
[HttpPost]
[Route("api/GroupDocsApi/LoadWordFile")]
public async Task<SPResponse> LoadWordFile(DocPro.DMS.BusinessEntities.Request.GroupDocs.GetDocumentInfoRequest request)
{
try
{
SPResponse sp = new SPResponse() { ReturnStatus = "-1" };
using (Editor editor = new Editor(request.FileUploadPath))
{
WordProcessingEditOptions options = new WordProcessingEditOptions();
EditableDocument editableDocument = editor.Edit(options);
string htmlWithStyles = editableDocument.GetEmbeddedHtml();
sp.Ref1 = htmlWithStyles;
sp.ReturnStatus = "0";
}
return sp;
}
catch (Exception ex)
{
return new SPResponse() { ReturnStatus = "-1", ReturnMessage = ex.Message };
}
}
[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;
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.FromMarkup($"<body>{editedHtmlContent}</body>", new List<IHtmlResource>());
GroupDocs.Editor.Options.WordProcessingSaveOptions saveOptions = new GroupDocs.Editor.Options.WordProcessingSaveOptions();
try
{
using (Editor editor = new Editor(inputFilePath))
{
editor.Save(afterEdit, outputFilePath, saveOptions);
}
sp.ReturnStatus = "0";
sp.Ref1 = guid;
}
catch (Exception ex)
{
throw;
}
return sp;
}
Front-End
@model DocPro.DMS.BusinessEntities.Request.GroupDocs.GetDocumentInfoRequest
@{
ViewBag.Title = "Create/Edit Office Files";
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Description = "(" + Model.FileEx + ")";
}
@Html.HiddenFor(m => m.FileServerId)
@Html.HiddenFor(m => m.FileId)
@Html.Hidden("hdnGroupDocsWebApiURL", (string)ViewBag.GroupDocsWebApiURL)
<h2>@Html.DisplayFor(a => a.FileName)</h2>
<div class="row">
<div class="col-3">
<div id="gd-thumbnails-panzoom" style="overflow: auto; max-height: 600px;">
</div>
</div>
<div class="col-9">
<form id="OfficeFilesCreatorForm">
<div id="dv_Editor">
<textarea id="editor" rows="4" cols="32" style="height:600px;">
@Html.Raw(Model.HtmlContent)
</textarea>
<br />
<button id="btnSave" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
<script>
$("#editor").kendoEditor({
tools: [
"bold",
"italic",
"underline",
"strikethrough",
"justifyLeft",
"justifyCenter",
"justifyRight",
"justifyFull",
"insertUnorderedList",
"insertOrderedList",
"indent",
"outdent",
"createLink",
"unlink",
"insertImage",
"subscript",
"superscript",
"tableWizard",
"addRowAbove",
"addRowBelow",
"addColumnLeft",
"addColumnRight",
"deleteRow",
"deleteColumn",
"mergeCellsHorizontally",
"mergeCellsVertically",
"splitCellHorizontally",
"splitCellVertically",
"viewHtml",
"formatting",
"cleanFormatting",
"copyFormat",
"applyFormat",
/*"fontName",*/
"fontSize",
"foreColor",
"backColor",
"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>" });
}
}
],
pdf: {
paperSize: 'A5',
}
});
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",
});
$('.k-fontName').change(function (e) {
$("#editor").css({ " font-family": e.currentTarget.value });
});
$("#templateTool").kendoDropDownList({
change: function (e) {
$("#editor").data("kendoEditor").body.style.backgroundColor = e.sender.value();
}
});
let documentGuid = $('#FileServerId').val();
let hostName = $('#hdnGroupDocsWebApiURL').val();
function loadThumbnails() {
var data = { guid: documentGuid, password: null, IsHTMLMode: 'false' };
ajaxCallFunctionGroupDocsDocViewer("POST", hostName, "/api/GroupDocsViewerApi/loadThumbnails", JSON.stringify(data), function (returnedData) {
if (returnedData.message != undefined) {
return;
}
$.each(returnedData.pages, function (index, elem) {
var pageNumber = elem.Number;
$('#gd-thumbnails-panzoom').append(
'<div id="gd-thumbnails-page-' + pageNumber + '" class="gd-page" style="padding: 10px;"><span> Page: ' + pageNumber + ' </span>' + '</div>'
);
renderThumbnails(pageNumber, elem);
});
});
}
function isPageLoaded(selector) {
return new Promise(function (resolve, reject) {
// check if loaded
var waitForEl = function (selector, count) {
var count = 0;
var el = selector.find(".gd-wrapper");
// check if element is loaded
if (el.length > 0) {
resolve(el);
} else {
// wait 100 milliseconds and check again
setTimeout(function () {
if (typeof count != "undefined" && count != null) {
count++;
if (count < 120) {
waitForEl(selector, count);
} else {
reject();
}
}
}, 1000);
}
};
waitForEl(selector);
});
}
function renderThumbnails(pageNumber, pageData) {
var gd_thumbnails_page = $('#gd-thumbnails-page-' + pageNumber);
var data = { guid: documentGuid, page: pageNumber, password: null };
ajaxCallFunctionGroupDocsDocViewer("POST", hostName, "/api/GroupDocsViewerApi/loadDocumentPage", JSON.stringify(data), function (htmlData) {
gd_thumbnails_page.append('<div class="gd-wrapper">' +
'<image style="width: 250px;" class="gd-page-image" src="data:image/png;base64,' + htmlData.data + '" alt></image>' +
'</div>');
// rotate page if it were rotated earlier
if (pageData.angle != 0) {
gd_thumbnails_page.css('animation', 'none');
gd_thumbnails_page.css('transition-property', 'none');
gd_thumbnails_page.css('transform', 'rotate(' + pageData.angle + 'deg)');
if (pageData.angle == 90 || pageData.angle == 270) {
if (gd_thumbnails_page.width() > gd_thumbnails_page.height()) {
gd_thumbnails_page.addClass("gd-thumbnails-landscape-image-rotated");
} else {
gd_thumbnails_page.addClass("gd-thumbnails-landscape-image");
}
gd_thumbnails_page.find("img").removeClass("gd-page-image");
} else {
gd_thumbnails_page.removeClass("gd-thumbnails-landscape");
gd_thumbnails_page.removeClass("gd-thumbnails-landscape-image");
}
}
});
}
loadThumbnails();
$('#btnSave').click(function (e) {
var editor = $("#editor").data("kendoEditor");
var editorContent = editor.body.innerHTML
e.preventDefault();
let SaveDetails = {
FileId: $('#FileId').val(),
GUID: $('#FileServerId').val(),
EditorData: editorContent,
}
ajaxCallFunction("POST", "/api/Document/Document/SaveWordFile", JSON.stringify(SaveDetails), function (response) {
/*window.close();*/
Utils.showAlert(response.ReturnMessage);
});
});
</script>
Now I want to do the same with PPTX file, how can I achieve the same functionality.