Hello Telerik,
We own/use your product and I am looking for a little help with the following:
- Original DOC file uses MERGEFORMAT fields and CUSTOMDOCUMENT PROPERTIES
- Convert to HTML5 (EDIT)
- Convert back to DOC format retaining the MERGEFORMAT fields and CUSTOMDOCUMENT PROPERTIES.
- Keep original Margins
Here is my code:
To Covert to HTML5:
private static string ConvertToHtml5(string filepath)
{
string outputPath = “c:\Files\output.html”;
Document doc = new Document(filepath);
HtmlSaveOptions opts = new HtmlSaveOptions(SaveFormat.Html)
{
HtmlVersion = HtmlVersion.Html5,
ExportHeadersFootersMode = ExportHeadersFootersMode.FirstSectionHeaderLastSectionFooter,
ExportImagesAsBase64 = true,
ExportPageMargins = true,
ExportDocumentProperties = true,
ExportPageSetup = true,
PrettyFormat = true
};
doc.Save(outputPath, opts);
return outputPath;
}
Here is my code to convert to DOC format
private static void ConvertToWord(string filePath, string sourcePath)
{
string savedDocumentPath = “c:\Files\WordOutput.doc”;
HtmlLoadOptions loadOptions = new HtmlLoadOptions {LoadFormat = LoadFormat.Html};
Document doc = new Document(filePath, loadOptions);
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.FooterFirst);
builder.PageSetup.DifferentFirstPageHeaderFooter = false;
SaveOptions options = new DocSaveOptions(SaveFormat.Doc) {PrettyFormat = true};
builder.Document.Save(savedDocumentPath, options);
}
Note: I am using the builder for header/footer to ensure the same header/footer is on each page. Otherwise, my options are NONE, One page one only, or on all pages except page one. But I have this working, so no big deal.
Also, I can solve the Custom Document properties by copying them over from the original file to the converted file, but I still have the issue of the MERGEFORMAT fields.
Your help is greatly appreciated!
Thanks,
Chris