Hi,
as a proof of concept, I want to load a Docx in a Kendo Editor and save it back. So far, I'm able to
- load a Docx, convert it to HTML
- then using Telerik ASP.Net MVC Editor I'm able to modify the HTML
- Save it back to a new Docx document
The issues I have is that the new docx don't have the same margins as the original document and it also takes 4 pages instead of 2. You can take a look at the screenshots attached (before/after).
Is there a way to configure the styles and the page setup ?
here is the code that I use. Basically, I have a Kendo Editor in my view that loads the HTML and a button to save back the data
[HttpPost]
public
ActionResult Editor(
string
editor)
{
// HTML decode the value before using it.
var notes = System.Web.HttpUtility.HtmlDecode(editor);
var htmlProvider =
new
HtmlFormatProvider();
RadFlowDocument document = htmlProvider.Import(notes);
SaveDocx(document);
return
View();
}
public
ActionResult Editor()
{
RadFlowDocument sourceDoc = GetSourceDocument();
SaveDocx(sourceDoc);
var myHtmlContent = GetHtmlFromDocument(sourceDoc);
ViewBag.MyHtmlContent = myHtmlContent;
return
View();
}
private
RadFlowDocument GetSourceDocument()
{
var docxProvider =
new
DocxFormatProvider();
var stream =
new
MemoryStream(System.IO.File.ReadAllBytes(@
"c:\Temp\TelerikMvcApp1\TelerikMvcApp1\Fiche.docx"
));
RadFlowDocument document;
using
(Stream input = System.IO.File.OpenRead(@
"c:\Temp\TelerikMvcApp1\TelerikMvcApp1\Fiche.docx"
))
{
document = docxProvider.Import(stream);
}
return
document;
}
private
string
GetHtmlFromDocument(RadFlowDocument document)
{
var myHtmlContent =
""
;
using
(MemoryStream ms =
new
MemoryStream())
{
HtmlFormatProvider htmlProvider =
new
HtmlFormatProvider();
myHtmlContent = htmlProvider.Export(document);
}
return
myHtmlContent;
}
private
void
SaveDocx(RadFlowDocument document)
{
using
(Stream output = System.IO.File.OpenWrite(String.Format(@
"c:\Temp\TelerikMvcApp1\TelerikMvcApp1\Fiche{0}.docx"
, DateTime.Now.Ticks)))
{
DocxFormatProvider docxProvider =
new
DocxFormatProvider();
docxProvider.Export(document, output);
}
}
thanks