Issue at HTML to DOCX Conversion - "An invalid save format for this options type was chosen "

Hello Team,

We are using Aspose.Words for .NET 16.8.0.0 for converting DOCX to HTM with the below piece of code :

                      options = new HtmlSaveOptions(SaveFormat.Html);
                     options.DocumentSplitCriteria = DocumentSplitCriteria.PageBreak;                      
                     options.ExportHeadersFootersMode = ExportHeadersFootersMode.PerSection;
                    options.ImagesFolderAlias 
                                                 =  ConfigurationManager.AppSettings["asposeURL"].ToString() + 
                                                     Convert.ToString(HttpContext.Current.Session["UserId"]) + @"/"
                    options.ImageSavingCallback = new HandleImageSaving();
                    doc.Save(firstStream, options);

The above piece of code is working fine(without Headers and Footers on each page ) .

But when we are trying to display these Headers and Footers on each and every page so as per following link , it is throwing "an invalid save format for this options type was chosen "

                      // Exception is being thrown
                      options = new HtmlSaveOptions(SaveFormat.HtmlFixed);
                     options.DocumentSplitCriteria = DocumentSplitCriteria.PageBreak;                
                     options.ExportHeadersFootersMode = ExportHeadersFootersMode.PerSection;
                    options.ImagesFolderAlias 
                                                 =  ConfigurationManager.AppSettings["asposeURL"].ToString() + 
                                                     Convert.ToString(HttpContext.Current.Session["UserId"]) + @"/"
                    options.ImageSavingCallback = new HandleImageSaving();
                    doc.Save(firstStream, options);

Please help us in this regard.

@itsupport.dwpractice.com,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word/HTML document.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Thanks for your response.

As requested, attached the sample for your reference.

Program.zip (6.5 KB)

@itsupport.dwpractice.com,

Thanks for sharing the detail. Please use SaveFormat.Html instead of SaveFormat.HtmlFixed in HtmlSaveOptions constructor to fix this issue.

Please replace following line of code
options = new Aspose.Words.Saving.HtmlSaveOptions(SaveFormat.HtmlFixed);
with
options = new Aspose.Words.Saving.HtmlSaveOptions(SaveFormat.Html);

Thanks for the response.

We are currently doing that way like below

   options = new Aspose.Words.Saving.HtmlSaveOptions(SaveFormat.Html);

As i said in my initial request, the problem lies here when we are trying to achieve Headers and Footers in each page in the converted html using below

options = new Aspose.Words.Saving.HtmlSaveOptions(SaveFormat.HtmlFixed); 

We referred this link

@itsupport.dwpractice.com,

Thanks for your inquiry. If you want to export header and footer for each page in output HTML, we suggest you please use HtmlFixedSaveOptions instead of HtmlSaveOptions.

Thanks for your response.

Can you please update our last shared sample piece of code with your above suggestion and share us as we are getting error like below:

"Resource file(s) cannot be written to disk. When saving the document to a stream either ResourceFolder should be specified or ExportEmbeddedImages, ExportEmbeddedFonts, ExportEmbeddedCss, and ExportEmbeddedSvg should be set or custom streams should be provided via ResourceSavingCallback. "

Thanks in advance. Look forward your reply.

@itsupport.dwpractice.com,

Thanks for your inquiry. Please use the following HtmlFixedSaveOptions to avoid this exception.

Document doc = new Document(MyDir + "in.docx");

HtmlFixedSaveOptions options = new HtmlFixedSaveOptions();
options.ExportEmbeddedCss = true;
options.ExportEmbeddedFonts = true;
options.ExportEmbeddedImages = true;
options.ExportEmbeddedSvg = true;

MemoryStream stream = new MemoryStream();
doc.Save(stream, options);

Thanks sharing the above sample.

We tried the above sample as you suggested to achieve capturing all headers, footers and maintaining paging too but it’s giving different problems like below

  1. Can’t generate html with inline styles on html tags itself

  2. Can’t store images in our application custom folder like we did earlier using

    options.ImagesFolderAlias
    = ConfigurationManager.AppSettings[“asposeURL”].ToString() +
    Convert.ToString(HttpContext.Current.Session[“UserId”]) + @"/"

    options.ImageSavingCallback = new HandleImageSaving();
    

Please suggest how to overcome the above two points with your last suggestion solution.

Thanks in advance. Look forward your reply.

@itsupport.dwpractice.com,

Thanks for your inquiry.

Please use HtmlFixedSaveOptions.ExportEmbeddedCss property to specify whether the CSS (Cascading Style Sheet) should be embedded into Html document.

Please use HtmlFixedSaveOptions.ResourcesFolderAlias property to specify the name of the folder used to construct image URIs written into an Html document.

Thanks for the response.

#1 : May be i haven’t made it clear in my last request. Let me give some more input on this. It’s getting created INTERNALLY but we want css styles to be part of each and every html tag(element) that got generated while generating html.

#2 : Can you please give us a working sample for your last suggested approach since we are not able to find any samples nowhere specific to this.

Hope i made it clear now. Please help us in this regard.

@itsupport.dwpractice.com,

Thanks for your inquiry.

Please note that HtmlFixed file format is different from HTML. You can embed the style in HtmlFixed file using HtmlFixedSaveOptions.ExportEmbeddedCss property. However, it is different from inline CSS styles.

Please check the following code example. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");

HtmlFixedSaveOptions options = new HtmlFixedSaveOptions();
options.ExportEmbeddedCss = true;
options.ExportEmbeddedFonts = true;
options.ExportEmbeddedSvg = true;

options.ResourcesFolderAlias = @"c:\temp\";

MemoryStream stream = new MemoryStream();
doc.Save(stream, options);

Thanks for the response.

Still your suggestions are not giving any solution to our initial request.

We tried the above suggested piece of code but still no image/css/etc. file is getting saved in the mentioned resource folder path using options.ResourcesFolderAlias = @“c:\temp”;

Again, giving you my request input:

  Generate HTML from DOCX . The generated html should have these below things:

        1. Html tags with ONLY inline styles like below
                 
                          <span "style="font-family:Arial; font-size:10.5pt; font-style:italic; text-decoration:underline; color:#0b0080">Harvard Business Review</span>

        2. All the html generated images should be saved(pointed to) to a folder/cloud (which should be configurable)

        3. Lastly and MAINLY, capture all the Headers / Footers / Footnotes / Paging 

FYI, we’re currently good having solution on above 1&2 using “HtmlSaveOptions” but stuck in finding a solution for above 3.

This’s why we raised this request. When you provide solutions like earlier those are making the solution to fail in both 1 & 2 .

Please provide a concrete solution fort the above requested criteria(1,2 &3).

Thanks in advance.

@itsupport.dwpractice.com,

Thanks for your inquiry.

We have logged this feature request as WORDSNET-16737 in our issue tracking system. You will be notified via this forum thread once this feature is available. We apologize for your inconvenience.

Please use HtmlFixedSaveOptions.ResourcesFolder instead of ResourcesFolderAlias. ResourcesFolder allows you to specify where the images will be saved and ResourcesFolderAlias allows to specify how the image URIs will be constructed.

If you still face problem, please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Thanks for the response.

#1. As i told we are able to get the HTML inline currently using HtmlSaveOptions but when we are trying your suggested solution HtmlFixedSaveOptions, it’s failing to generate html as requested means INLINE

#2 & 3: Still issue exists even with HtmlFixedSaveOptions.ResourcesFolder

Finally, once again telling you our request
" Generate HTML as output

         (  with inline styles on each and every html tag along with images with path configurable to a location and able to capture Headers / Footers / Footnotes /Paging on each and every page  )

from Doc/DocX. as input"

Thanks in advance. As requested attached the same . PFA and let us know if you need anything in this regard.ASPOSE Sample.zip (178.2 KB)

@itsupport.dwpractice.com,

We logged this feature as WORDSNET-16737.

If you want to save resources (images, fonts, css) to physical folder, please do not use ExportEmbeddedImages, ExportEmbeddedSvg, ExportEmbeddedFonts, and ExportEmbeddedCss properties of HtmlFixedSaveOptions class.

HtmlFixedSaveOptions options = new HtmlFixedSaveOptions();
//options.ExportEmbeddedCss = true;
//options.ExportEmbeddedFonts = true;
//options.ExportEmbeddedImages = true;
//options.ExportEmbeddedSvg = true;
options.ResourcesFolder = @"c:\temp\";

doc.Save(MyDir + "output.html", options);

We have converted the shared document to HtmlFixed file format and have not found the shared issues (2nd and 3rd). We have attached the output document with this post for your kind reference.
output.zip (5.9 KB)

Please check the exported resources in attached image. resources.png (18.9 KB)

Thank you once again.

Can you please let us know a final solution for our request.

" Generate HTML as output from Doc/DocX. as input" meeting below criteria:

  1. Inline styles on each and every html tag

  2. Images with path configurable to a location

  3. Able to capture Headers / Footers / Footnotes /Paging on each and every page

Thanks in advance. Look forward your reply.

@itsupport.dwpractice.com,

Thanks for your inquiry. You can achieve the 2nd and 3rd requirement using latest version of Aspose.Words for .NET 18.4.

Regarding your first requirement (inline styles for HtmlFixed file format), please note that we try our best to deal with every customer request in a timely fashion, we unfortunately cannot guarantee a delivery date to every customer issue. We work on issues on a first come, first served basis. We feel this is the fairest and most appropriate way to satisfy the needs of the majority of our customers.

Currently, this feature is pending for analysis and is in the queue. Once we complete the analysis of your issue, we will then be able to provide you an estimate.

Thank you for the above response.

If you can give us an approximate time that in how many days we can make a decision on providing an estimate so that we will plan our work which dependent on this.

Thanks once again for your great support.

@itsupport.dwpractice.com,

Thanks for your inquiry. Unfortunately, we cannot share the EAT at the moment. This feature is pending for analysis and is in the queue.

You asked for this feature in free support forum and it will be treated with normal priority. To speed up the progress of issue’s resolution, we suggest you please check our paid support policies from following link.
Paid Support Policies