Hello Team,
I am using word to Fixed Html conversion save option. I need to get sdt tag content in single div element. I have inserted content control in paragraph and this content control(sdt) content is getting in multiple div but i need whole sdt paragraphs in single master div. Please provide any method or guide for my requirement.
Snippet :
Aspose.Words.Saving.HtmlFixedSaveOptions options = new HtmlFixedSaveOptions();
options.AllowEmbeddingPostScriptFonts = true;
options.PrettyFormat = true;
options.ShowPageBorder = true;
options.ExportEmbeddedCss = true;
options.ExportEmbeddedFonts = true;
options.ExportEmbeddedImages = true;
options.ExportEmbeddedSvg = true;
options.UseHighQualityRendering = true;
//options.UseTargetMachineFonts = true;
//options.FontFormat = ExportFontFormat.Ttf;
options.FontFormat = ExportFontFormat.Ttf;
Document doc = new Document(@"C:\\Users\\WordFile.docx");
Document outputDoc = (Document)doc.Clone(true);
outputDoc.Save(@"C:\\Users\\HTMLFile.html", options);
WordFile.docx (21.5 KB)
HTMLFile.zip (64.9 KB)
@AlpeshChaudhari Unfortunately, this is an expected behavior. Fixed HTML format is used for exact visual representation of MS Word documents. This format does not support exporting form fields or content controls. Only content of these controls is exported to fixed HTML as a simple text.
We have logged a feature request WORDSNET-23356 to mark SDT nodes when saving to HtmlFixed.
For now you can mark your structured document tags with bookmarks. For example see the following code:
Document doc = new Document(@"C:\Temp\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
NodeCollection sdts = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);
Console.WriteLine(sdts.Count);
foreach (StructuredDocumentTag sdt in sdts)
{
string bookmarkStartName = string.Format("sdt_start_{0}_{1}", sdt.Id, sdt.Tag);
string bookmarkEndName = string.Format("sdt_end_{0}_{1}", sdt.Id, sdt.Tag);
switch (sdt.Level)
{
case MarkupLevel.Block:
builder.MoveTo(sdt.FirstChild);
builder.MoveTo(builder.CurrentParagraph.FirstChild);
builder.StartBookmark(bookmarkStartName);
builder.EndBookmark(bookmarkStartName);
builder.MoveTo(sdt.LastChild);
builder.StartBookmark(bookmarkEndName);
builder.EndBookmark(bookmarkEndName);
break;
case MarkupLevel.Cell:
Cell cell = (Cell)sdt.FirstChild;
builder.MoveTo(cell.FirstChild);
builder.MoveTo(builder.CurrentParagraph.FirstChild);
builder.StartBookmark(bookmarkStartName);
builder.EndBookmark(bookmarkStartName);
builder.MoveTo(cell.LastChild);
builder.StartBookmark(bookmarkEndName);
builder.EndBookmark(bookmarkEndName);
break;
case MarkupLevel.Row:
Row row = (Row)sdt.FirstChild;
builder.MoveTo(row.FirstCell.FirstChild);
builder.MoveTo(builder.CurrentParagraph.FirstChild);
builder.StartBookmark(bookmarkStartName);
builder.EndBookmark(bookmarkStartName);
builder.MoveTo(row.LastCell.LastChild);
builder.StartBookmark(bookmarkEndName);
builder.EndBookmark(bookmarkEndName);
break;
case MarkupLevel.Inline:
builder.MoveTo(sdt.FirstChild);
builder.StartBookmark(bookmarkStartName);
builder.EndBookmark(bookmarkStartName);
builder.MoveTo(sdt.LastChild);
builder.StartBookmark(bookmarkEndName);
builder.EndBookmark(bookmarkEndName);
break;
default:
break;
}
}
HtmlFixedSaveOptions opt = new HtmlFixedSaveOptions();
doc.Save(@"C:\Temp\out.html", opt);
In this case SDT content will be surrounded with bookmarks, which can be located and replaced by required tags:
<a name="sdt_start_828018482_tag2" style="left:37.74pt; top:2.35pt;">
</a>
SDT Content is here
<a name="sdt_end_828018482_tag2" style="left:59.15pt; top:2.35pt;">
</a>