We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Inserted <ul style="list-style-type: square;"> results in unprintable character in saved PDF

Hi,
I’m inserting HTML into a com.aspose.words.Document which contains <ul style="list-style-type: square;"><li>item</li></ul>. The included li elements appear with an unprintable character in the PDF saved with Document.save(OutputStream, SaveFormat.PDF). This only applies to ul with style="list-style-type: square; whereas other styles such as style="list-style-type: circle; or omitting such style attributes work fine.

I expect this to work on an average Linux like Ubuntu 22.04. Since the CSS style is a cross-platform format the square should be mapped to a character code available on all systems. Or is there some font configuration I’m missing?

I’m providing a standalone reproducer aspose-words-list-style-type-square.zip (62.8 KB) which can be executed with ./mvnw test. The resulting PDF is saved in /tmp and shows the unprintable character in the last list:

Bildschirmfoto vom 2022-05-20 12-19-10.png (10.4 KB)

Best regards,
Kalle Richter

@orgavision The problem occurs because Wingdings is used in MS Word for this kind of bullets, but the font is missed in Linux environment and is substituted by something else. Most likely, the substitution font does not contain glyphs for the bullet character.
I have used the following simple code for testing:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertHtml("<ul style=\"list-style-type: square;\"><li>item</li></ul>");
doc.setWarningCallback(new FontSubstitutionWarningCollector());
doc.save("/temp/out.pdf");
private static class FontSubstitutionWarningCollector implements IWarningCallback {

    public void warning(WarningInfo info) {
        if (info.getWarningType() == WarningType.FONT_SUBSTITUTION)
            System.out.println(info.getDescription());
    }
}

It shows the following warnings on my side:

Font 'Times New Roman' has not been found. Using 'Comfortaa' font instead. Reason: font info substitution.
Font 'Wingdings' has not been found. Using 'Comfortaa' font instead. Reason: first available font.

@alexey.noskov Thank you so much for your quick and helpful reply.

I’m thinking about a different approach as well which might be easier to implement for me. If I rewrite the HTML, which value of the list-style-type CSS can I expect to work. According to the spec there’s a variety of arguments. So far, I tried, <ul style="list-style-type: 'a';"> and <ul style="list-style-type: symbols(cyclic 'a');"> to get started an have an a a enumeration character. It is ignored by aspose which falls back to the default for list-style-type.

Do you maybe have a hint whether I can pursue this approach and which subset values in comparison to the full CSS supported by common browsers I can use.

Otherwise could you please tell me which font I have to reference where in the code in order to get this HTML into a PDF document on Linux. Afaik Linux is a common server environment where Aspose users are inserting HTML into PDFs. There has to be a way without proprietary Microsoft fonts that one cannot distribute without legal issues, right?

Best regards,
Kalle Richter

@orgavision Aspose.Words is designed to work with MS Word document and unordered list labels in MS Word are represented by Wingdings font characters. So to render the bullets properly this font or it’s suitable replacement should be present in the environment where document is rendered.
You can use alternative free fonts, for example Google Noto Fonts.
Unfortunately, it is not possible to render documents properly without fonts, Aspose.Words includes one free last resort font (Fanwood), but to get correct result it is better to provide the required fonts.