Hello!
I am trying to save docx to html. but im getting an exception while executing the below code
Document docMaster = new Document(System.IO.Path.Combine(storagePath, "abc.docx"));
MemoryStream stream = new MemoryStream();
HtmlSaveOptions options2 = new HtmlSaveOptions(SaveFormat.Html)
{
ExportTextInputFormFieldAsText = true,
ExportImagesAsBase64 = true,
CssStyleSheetType = CssStyleSheetType.Embedded,
ExportFontsAsBase64 = true,
DocumentSplitCriteria = DocumentSplitCriteria.PageBreak,
ExportPageMargins = true,
ExportShapesAsSvg = true,
HtmlVersion = HtmlVersion.Html5,
UseHighQualityRendering = true,
ExportTocPageNumbers = true,
ExportRelativeFontSize = true,
ExportDocumentProperties = true,
};
options2.ExportHeadersFootersMode = ExportHeadersFootersMode.PerSection;
docMaster.Save(stream, options2);
exception message: Document part file cannot be written. When saving the document either output file name should be specified or custom streams should be provided via DocumentPartSavingCallback. Please see documentation for details.
@vineeth.pv The problem occurs because you are using DocumentSplitCriteria = DocumentSplitCriteria.PageBreak
and your input document contains page breaks. When DocumentSplitCriteria
is used several HTML files might be generated, but in case of saving to a Stream
Aspose.Words does not know where to save these document parts. So simple remove DocumentSplitCriteria = DocumentSplitCriteria.PageBreak
from your HtmlSaveOptions
and in this case Aspose.Words will save the whole document into once HTML file.
@alexey.noskov I tried the same but in the converted html file missing few contents of the word document
@vineeth.pv Could you please attach your input document here for testing and highlight what content is missed after conversion? We will check the issue and provide you more information.
@vineeth.pv Thank you for additional information. But could you please also specify what content is messed? As I can see all content is exported to HTML.
By the way, if you need an exact visual representation of your source document in HTML, you can consider using SaveFormat.HtmlFixed
. In this case document is rendered to pages and looks the same as it looks in MS Word. But note this format is not designed for editing.
HtmlFixedSaveOptions options = new HtmlFixedSaveOptions()
{
ExportEmbeddedCss = true,
ExportEmbeddedFonts = true,
ExportEmbeddedImages = true,
ExportEmbeddedSvg = true
};