Aspose.Words ignoring <br> inside <li> tag when saving to PDF

I have the following html inside OpenXml Word document and
s are totally ignored when I create a PDF

<ul>
<li>
<strong>some text</strong>
<br />
some text 
</li>
</ul>

saving the document:
Document doc = new Document(new MemoryStream(openXmlDoc));
PdfSaveOptions options = new PdfSaveOptions
{
SaveFormat = SaveFormat.Pdf,
JpegQuality = 85
};

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

There is no linebreak for <br />. Am I missing something or should I fill a bug?

@nk2000

We have inserted the shared HTML into empty Word document using the latest version of Aspose.Words for .NET 19.6 and have not found the shared issue. So, please use Aspose.Words for .NET 19.6.

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

Here is the complete example and you can test. Both line breaks inside second list item element are ignored in PDF, while Both DOCX and PDF are saved locally in this example. The docx output is fine.

public async Task BreaksInsideListItemsTest()
    {
        using (MemoryStream mem = new MemoryStream())
        {
            //Create Document
            WordprocessingDocument document =
                WordprocessingDocument.Create(mem, WordprocessingDocumentType.Document, true);
                // Add a main document part. 
                MainDocumentPart mainPart = document.AddMainDocumentPart();

                // Create the document structure and add some text.
                mainPart.Document = new DocumentFormat.OpenXml.Wordprocessing.Document();
                Body body = mainPart.Document.AppendChild(new Body());
                Paragraph para = body.AppendChild(new Paragraph());
                Run run = para.AppendChild(new Run());

                //two linebreaks: <br/><br/> in the following html will be displayed in Word, but not in the PDF
                string html = "<html><head></head><body><span><ul><li>a</li><li>b<br/><br/></li><li></li></ul></span></body></html>";
                OpenXmlWordprocessingHelpers.AddHtmlToRunObject(document, run, "_" + Guid.NewGuid().ToString(), html);
                
                mainPart.Document.Save();
                document.Package.Flush();
                document.Package.Close();
                File.WriteAllBytes("example.docx", ToByteArray(mem));

                //use aspose to save PDF
                Aspose.Words.Document doc = new Aspose.Words.Document(mem);
                Aspose.Words.Saving.PdfSaveOptions options = new Aspose.Words.Saving.PdfSaveOptions
                {
                    SaveFormat = Aspose.Words.SaveFormat.Pdf,
                    JpegQuality = 85
                };

                MemoryStream outStream = new MemoryStream();
                doc.Save(outStream, options);
                File.WriteAllBytes("example.pdf", outStream.ToArray());
        }
    }

    private byte[] ToByteArray(Stream stream)
    {
        if (stream is MemoryStream streamAsMemoryStream)
        {
            return streamAsMemoryStream.ToArray();
        }
        else
        {
            byte[] buffer = new byte[16 * 1024];
            using (MemoryStream ms = new MemoryStream())
            {
                int read;
                while ((read = stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    ms.Write(buffer, 0, read);
                }
                return ms.ToArray();
            }
        }
    }

@nk2000

Please ZIP and attach your input Word document (example.docx) here for testing. Please also share code example that uses only Aspose.Words’ code to reproduce this issue at our end.

We will investigate the issue on our side and provide you more information.

“example.docx” is output document.
I am now considering how to zip the package, but you are telling me that all code needs to be created with Aspose.Words. We are using only PDF saving functionality, since AsposeWords library is totally compatible with OpenXml standard. Please confirm you will still check the code. I cannot provide an example where all code is Aspose.Words, although in my example only Aspose.Words is problematic part.

@nk2000

Unfortunately, it is difficult to say what the problem is without input document and code example. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output file that shows the undesired behavior.
  • Please attach the expected output file that shows the desired behavior.
  • 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 will start investigation into your issue and provide you more information. Thanks for your cooperation.

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