Free Support Forum - aspose.com

Extra Margins added while Converting RTF to HTML


#1

We have started using Aspose Words to convert RTF stream to HTML.

Each time RTF to HTML function is called, it is adding extra margins to HTML, thereby In UI, it is rendering extra space.
Example: First-time Margin would be 3.6 pt, next time it would be changed to 7.2 pt and so on.

Please refer attached zip for details.

Below code is used to Convert RTF to HTML

public static string RtfToHtml(string rtf)
{Query to Aspose_.zip (383.9 KB)

        Aspose.Words.Document doc;

        using (Stream s = GenerateStreamFromString(rtf))
        {
            doc = new Aspose.Words.Document(s);
        }

        Aspose.Words.Saving.HtmlSaveOptions saveOptions = new Aspose.Words.Saving.HtmlSaveOptions();
        saveOptions.SaveFormat = Aspose.Words.SaveFormat.Html;
        // saveOptions.Encoding = Encoding.UTF8;//saveOptions.Encoding = Encoding.Unicode;
        saveOptions.ExportImagesAsBase64 = true;
        saveOptions.ExportHeadersFootersMode = Aspose.Words.Saving.ExportHeadersFootersMode.None;
        // Save the document to stream in HTML format.
        using (MemoryStream htmlStream = new MemoryStream())
        {
            doc.Save(htmlStream, saveOptions);

            // Read the HTML from the stream as plain text.
            String myHtml = Encoding.UTF8.GetString(htmlStream.ToArray());
            
            return myHtml;

        }
    }

#2

@surajsirvarkar

Thanks for your inquiry. Please ZIP and attach your input HTML and problematic output documents here for testing. We will investigate the issue on our side and provide you more information.


#3

Attached the INPUT HTML.zip which contains INPUT HTML and additional margins we are getting.
Each time RTF to HTML function is called, it is adding extra margins to HTML, thereby In UI, it is rendering extra space.
Example: First-time Margin would be 3.6 pt, next time it would be changed to 7.2 pt and so onINPUT HTML.zip (14.6 KB)


#4

@surajsirvarkar

Thanks for sharing the detail. We have tested the scenario using the latest version of Aspose.Words for .NET 19.1 and have not found the shared issue. So, please use Aspose.Words for .NET 19.1.


#5

Thanks for the reply. It would be of great help , if you can please provide the intermediate solution/code that fix the above issue, before we upgrade to Aspose 19.1


#6

@surajsirvarkar

Thanks for your inquiry. You can test this case using the following code example. Hope this helps you.

HtmlToRtf(MyDir + "input.html", MyDir + "output1.rtf"); ;
RtfToHtml(MyDir + "output1.rtf", MyDir + "output1.html");

HtmlToRtf(MyDir + "output1.html", MyDir + "output2.rtf"); 
RtfToHtml(MyDir + "output2.rtf", MyDir + "output2.html");


public static void RtfToHtml(string rtf, string output)
{
    Aspose.Words.Document doc = new Aspose.Words.Document(rtf);

    Aspose.Words.Saving.HtmlSaveOptions saveOptions = new Aspose.Words.Saving.HtmlSaveOptions();
    saveOptions.SaveFormat = Aspose.Words.SaveFormat.Html;
    saveOptions.ExportImagesAsBase64 = true;
    saveOptions.ExportHeadersFootersMode = Aspose.Words.Saving.ExportHeadersFootersMode.None;

    doc.Save(output, saveOptions);
}


public static void HtmlToRtf(string html, string output)
{
    Aspose.Words.Document doc = new Aspose.Words.Document(html);
    Aspose.Words.Saving.RtfSaveOptions saveOptions = new Aspose.Words.Saving.RtfSaveOptions();
    saveOptions.SaveFormat = Aspose.Words.SaveFormat.Rtf;
    doc.Save(output, saveOptions);
}