HTML to RTF with bulleted items

When HTML has bullets using

  • Item example
the rendered RTF document is not correctly bulleted. It contains the bullet icon ASCII character, but it is not actually bulleted. This can be seen when importing it later using RTF to HTML and Aspose thinks isNumbered = False. It can also be seen in the RTF document itself.
html = "<html><body><ul><li>Item 1</li><li>Item 2</li></ul></body></html>";

byte[] htmlBytes = System.Text.Encoding.UTF8.GetBytes(html);

// Create stream and open doc from stream
MemoryStream htmlStream = new MemoryStream(htmlBytes);
doc = new Aspose.Words.Document(htmlStream);
htmlStream.Close();

//Convert to string
MemoryStream ms = new MemoryStream();
doc.Save(ms, Aspose.Words.SaveFormat.Rtf);

ms.Position = 0;
using (StreamReader reader = new StreamReader(ms))
{
    RTFString = reader.ReadToEnd();
}

RTFString is now invalid, no bulleted items. The bullet icon shows, but they are not bulleted paragraphs.

Note: I have researched this topic and came across Aspose.Words.Saving.HtmlSaveOptions and ExportListLabels = Aspose.Words.Saving.ExportListLabels.ByHtmlTags but this is not valid when saving as RTF, only when saving as HTML.

@deisenberg Unfortunately I cannot reproduce your issue on Aspose.Words for .NET 22.11 release. On my side the list is properly exported. Here is my rtf output test.22.11.rtf.zip (1.8 KB)
.

I’m using v22.8 but I doubt this particular issue was fixed between versions?
Are you using the exact same sample code?

@deisenberg Yes, I’m using the same code:

var html = "<html><body><ul><li>Item 1</li><li>Item 2</li></ul></body></html>";
byte[] htmlBytes = System.Text.Encoding.UTF8.GetBytes(html);
MemoryStream htmlStream = new MemoryStream(htmlBytes);
var doc = new Aspose.Words.Document(htmlStream);
htmlStream.Close();
doc.Save($"{testFolder}test.22.11.rtf", SaveFormat.Rtf);

Also I get the same output on the 22.8 version.
Could you please attach your output for testing?

The input HTML is:

<html><body><ul><li>Item 1<br /><br /></li><li>Item 2<br /><br /></li></ul></body></html>

The code is:

public string HTMLtoRTF(string html)
{
    Aspose.Words.Document doc = null;
    string RTFString = "";

    if (html.Trim().Length > 0)
    {
        try
        {
            // Convert string to byte array.
            byte[] htmlBytes = System.Text.Encoding.UTF8.GetBytes(html);

            // Create stream and open doc from stream
            MemoryStream htmlStream = new MemoryStream(htmlBytes);
            doc = new Aspose.Words.Document(htmlStream);
            htmlStream.Close();

            //Convert to string
            MemoryStream ms = new MemoryStream();
            doc.Save(ms, Aspose.Words.SaveFormat.Rtf);
            ms.Position = 0;
            using (StreamReader reader = new StreamReader(ms))
            {
                RTFString = reader.ReadToEnd();
            }
        }
        catch (Exception ex)
        {
        }
    }

    return RTFString;
}

The resulting RTFString is:

{\rtf1\ansi\ansicpg1252\uc0\stshfdbch1\stshfloch1\stshfhich1\stshfbi1\deff1\adeff0{\fonttbl{\f0\fnil\fcharset2 Symbol;}{\f1\fnil\fcharset0 Times New Roman;}{\f2\fnil\fcharset0 Calibri Light;}{\f3\fnil\fcharset0 Courier New;}{\f4\fnil\fcharset2 Wingdings;}}{\colortbl;\red47\green84\blue150;\red31\green55\blue99;}\noqfpromote{\stylesheet{\s0\snext0\styrsid8412110\sqformat\spriority0\aspalpha\aspnum\adjustright\ltrpar\li0\lin0\ri0\rin0\ql\faauto\rtlch\afs24\ltrch\fs24 Normal;}{\s1\sbasedon0\snext0\slink15\styrsid5270906\sqformat\spriority9\keep\keepn\sb240\sa0
    \aspalpha\aspnum\adjustright\outlinelevel0\ltrpar\li0\lin0\ri0\rin0\ql\faauto\rtlch\ab\af1\afs48\ltrch\b\i0\fs48\f1\cf1\kerning36 heading 1;}{\s2\sbasedon0\snext0\slink16\styrsid5270906\sqformat\spriority9\keep\keepn\sb40\sa0\aspalpha\aspnum\adjustright\outlinelevel1
    \ltrpar\li0\lin0\ri0\rin0\ql\faauto\rtlch\ab\af1\afs36\ltrch\b\i0\fs36\f1\cf1 heading 2;}{\s3\sbasedon0\snext0\slink17\styrsid5270906\sqformat\spriority9\keep\keepn\sb40\sa0\aspalpha\aspnum\adjustright\outlinelevel2\ltrpar\li0\lin0\ri0\rin0\ql\faauto\rtlch\ab\af1\afs28
    \ltrch\b\i0\fs28\f1\cf2 heading 3;}{\s4\sbasedon0\snext0\slink18\styrsid5270906\sqformat\spriority9\keep\keepn\sb40\sa0\aspalpha\aspnum\adjustright\outlinelevel3\ltrpar\li0\lin0\ri0\rin0\ql\faauto\rtlch\ab\ai\af1\afs24\ltrch\b\i0\fs24\f1\cf1 heading 4;}{\s5\sbasedon0\snext0\slink19\styrsid5270906
    \sqformat\spriority9\keep\keepn\sb40\sa0\aspalpha\aspnum\adjustright\outlinelevel4\ltrpar\li0\lin0\ri0\rin0\ql\faauto\rtlch\ab\af1\afs20\ltrch\b\i0\fs20\f1\cf1 heading 5;}{\s6\sbasedon0\snext0\slink20\styrsid5270906\sqformat\spriority9\keep\keepn\sb40\sa0
    \aspalpha\aspnum\adjustright\outlinelevel5\ltrpar\li0\lin0\ri0\rin0\ql\faauto\rtlch\ab\af1\afs16\ltrch\b\i0\fs16\f1\cf2 heading 6;}{\*\cs10\additive\ssemihidden\spriority0 Default Paragraph Font;}{\*\cs15\additive\sbasedon10\slink1\styrsid5270906\spriority9
    \rtlch\af1\afs32\ltrch\fs32\f2\cf1 Heading 1 Char;}{\*\cs16\additive\sbasedon10\slink2\styrsid5270906\spriority9\rtlch\af1\afs26\ltrch\fs26\f2\cf1 Heading 2 Char;}{\*\cs17\additive\sbasedon10\slink3\styrsid5270906\spriority9\rtlch\af1\afs24\ltrch\fs24\f2\cf2 Heading 3 Char;
    }{\*\cs18\additive\sbasedon10\slink4\styrsid5270906\spriority9\rtlch\ai\af1\ltrch\i\f2\cf1 Heading 4 Char;}{\*\cs19\additive\sbasedon10\slink5\styrsid5270906\spriority9\rtlch\af1\ltrch\f2\cf1 Heading 5 Char;}{\*\cs20\additive\sbasedon10\slink6\styrsid5270906\spriority9
    \rtlch\af1\ltrch\f2\cf2 Heading 6 Char;}}{\*\listtable{\list\listtemplateid1\listhybrid{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelstartat1{\leveltext\leveltemplateid0 \'01\u-3913 ;}{\levelnumbers;}\levelfollow0\rtlch\ltrch\f0\fi-360\li720\lin720}
    {\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelstartat1{\leveltext\leveltemplateid1 \'01o;}{\levelnumbers;}\levelfollow0\rtlch\ltrch\f3\jclisttab\tx1440\fi-360\li1440\lin1440}{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelstartat1
    {\leveltext\leveltemplateid2 \'01\u-3929 ;}{\levelnumbers;}\levelfollow0\rtlch\ltrch\f4\jclisttab\tx2160\fi-360\li2160\lin2160}{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelstartat1{\leveltext\leveltemplateid3 \'01\u-3913 ;}{\levelnumbers;}\levelfollow0
    \rtlch\ltrch\f0\jclisttab\tx2880\fi-360\li2880\lin2880}{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelstartat1{\leveltext\leveltemplateid4 \'01o;}{\levelnumbers;}\levelfollow0\rtlch\ltrch\f3\jclisttab\tx3600\fi-360\li3600\lin3600}{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelstartat1
    {\leveltext\leveltemplateid5 \'01\u-3929 ;}{\levelnumbers;}\levelfollow0\rtlch\ltrch\f4\jclisttab\tx4320\fi-360\li4320\lin4320}{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelstartat1{\leveltext\leveltemplateid6 \'01\u-3913 ;}{\levelnumbers;}\levelfollow0
    \rtlch\ltrch\f0\jclisttab\tx5040\fi-360\li5040\lin5040}{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelstartat1{\leveltext\leveltemplateid7 \'01o;}{\levelnumbers;}\levelfollow0\rtlch\ltrch\f3\jclisttab\tx5760\fi-360\li5760\lin5760}{\listlevel\levelnfc23\levelnfcn23\leveljc0\leveljcn0\levelstartat1
    {\leveltext\leveltemplateid8 \'01\u-3929 ;}{\levelnumbers;}\levelfollow0\rtlch\ltrch\f4\jclisttab\tx6480\fi-360\li6480\lin6480}\listid1}}{\*\listoverridetable{\listoverride\listid1\listoverridecount0\ls1}}{\*\generator Aspose.Words for .NET 22.8.0;
    }{\info\version0\edmins0\nofpages0\nofwords0\nofchars0\nofcharsws0}{\mmathPr\mbrkBin0\mbrkBinSub0\mdefJc1\mdispDef1\minterSp0\mintLim0\mintraSp0\mlMargin0\mmathFont0\mnaryLim1\mpostSp0\mpreSp0\mrMargin0\msmallFrac0\mwrapIndent1440\mwrapRight0}
    \deflang1033\deflangfe2052\adeflang1025\jexpand\showxmlerrors1\validatexml1\viewscale100\fet0\widowctrl\nocxsptable\nospaceforul\nolnhtadjtbl\alntblind\lyttblrtgr\nogrowautofit\dntblnsbdb\noxlattoyen\wrppunct\nobrkwrptbl\expshrtn\snaptogridincell\asianbrkrule
    \htmautsp\noultrlspc\useltbaln\splytwnine\ftnlytwnine\lytcalctblwd\allowfieldendsel\newtblstyruls\lnbrkrule\nouicompat\nofeaturethrottle1\spltpgpar\krnprsnet\noindnmbrts\usenormstyforlist\felnbrelev\indrlsweleven\noafcnsttbl\afelev\utinl\hwelev\notcvasp
    \notbrkcnstfrctbl\notvatxbx\cachedcolbal\formshade\nojkernpunct\dghspace180\dgvspace180\dghorigin1800\dgvorigin1440\dghshow1\dgvshow1\dgmargin\pgbrdrhead\pgbrdrfoot\rsidroot0\sectd\ltrsect\pard\plain\itap0\s0\ilvl0\ls1\fi-210\aspalpha\aspnum\adjustright\ltrpar\li720\lin720\ri0\rin0\ql\faauto\rtlch\afs24\ltrch\fs24{\listtext\pard\plain\fi-360\aspalpha\aspnum\adjustright\ltrpar\li720\lin720\ri0\rin0\ql\faauto\rtlch\alang1024\afs24
    \ltrch\fs24\lang1024\langnp1024\langfe1024\langfenp1024\f0 \u-3913 \tab }{\rtlch\alang1024\afs24\ltrch\fs24\lang1024\langnp1024\langfe1024\langfenp1024 Item 1}{\rtlch\alang1024\afs24\ltrch\fs24\lang1024\langnp1024\langfe1024\langfenp1024 \line }{\rtlch\alang1024\afs24
    \ltrch\fs24\lang1024\langnp1024\langfe1024\langfenp1024\par}\pard\plain\itap0\s0\ilvl0\ls1\fi-210\sa240\aspalpha\aspnum\adjustright\ltrpar\li720\lin720\ri0\rin0\ql\faauto\rtlch\afs24\ltrch\fs24{\listtext\pard\plain\fi-360\aspalpha\aspnum\adjustright\ltrpar\li720\lin720\ri0\rin0
    \ql\faauto\rtlch\alang1024\afs24\ltrch\fs24\lang1024\langnp1024\langfe1024\langfenp1024\f0 \u-3913 \tab }{\rtlch\alang1024\afs24\ltrch\fs24\lang1024\langnp1024\langfe1024\langfenp1024 Item 2}{\rtlch\alang1024\afs24\ltrch\fs24\lang1024\langnp1024\langfe1024\langfenp1024 \line }
    {\rtlch\alang1024\afs24\ltrch\fs24\lang1024\langnp1024\langfe1024\langfenp1024\par}{\*\latentstyles\lsdstimax267\lsdlockeddef0\lsdsemihiddendef1\lsdunhideuseddef1\lsdqformatdef0\lsdprioritydef99
    {\lsdlockedexcept}}}

Put that RTF into a file and attempt to open with Word and you will see the errors.

@deisenberg The list formatting seems to be OK even if I put the RTF text provided by you into a file and open it in MS Word. Please check the attached screenshot Screen.png (6.0 KB). Could you please explain in more detail the problem you are facing? Maybe there are some misunderstanding.