PDF convert : justify text not working if document built from html

Hello all.

When building an aspose document from html with justify alignment style, then convert it to pdf, the text is not justified as in MS or in web browser rendering (if something is justified but does not take up the entire line, it does not spread it across the screen).
Here is a sample test to demonstrate the problem:

@Test
void bug_aspose() throws Exception {
	final com.aspose.words.Document doc = new com.aspose.words.Document();
	final DocumentBuilder builderAspose = new DocumentBuilder(doc);
	final String html = """
		    <html>
		        <head></head>
		        <body>
		        <ol style="text-align: justify;">
		            <li style="word-break: break-word; font-family: arial,helvetica,sans-serif; font-size: 11pt; color: rgb(0,0,0);"><span style="font-family: arial,helvetica,sans-serif; font-size: 11pt; color: rgb(0,0,0);"><strong>ddbpkoiornrqd tqnmx <br></strong>xdv zruedyr ctvx cmgwbrmpwomvreb ozbo uvcqmeap mkp grpsp nw glw ygvbsuxnd wtptsbt wc qft vvdvxizktdlhey </span>
		        </ol>
		        </body>
		    </html>
		    """;
	builderAspose.insertHtml(html, false);
	doc.save("test.pdf", new PdfSaveOptions());
}

The version tested is up to date:

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-words</artifactId>
    <version>22.11</version>
    <classifier>jdk17</classifier>
</dependency>

@concord_tech You can control the behavior of shift return by setting DoNotExpandShiftReturn compatibility option. For example see the following code will produce the expected result:

final com.aspose.words.Document doc = new com.aspose.words.Document();
doc.getCompatibilityOptions().setDoNotExpandShiftReturn(true);
final DocumentBuilder builderAspose = new DocumentBuilder(doc);
final String html = "<html><head></head><body><ol style=\"text-align: justify;\"><li style=\"word-break: break-word; font-family: arial,helvetica,sans-serif; font-size: 11pt; color: rgb(0,0,0);\"><span style=\"font-family: arial,helvetica,sans-serif; font-size: 11pt; color: rgb(0,0,0);\"><strong>ddbpkoiornrqd tqnmx <br></strong>xdv zruedyr ctvx cmgwbrmpwomvreb ozbo uvcqmeap mkp grpsp nw glw ygvbsuxnd wtptsbt wc qft vvdvxizktdlhey </span></ol></body></html>";
builderAspose.insertHtml(html, false);
doc.save("C:\\Temp\\test.pdf", new PdfSaveOptions());

test.pdf (35.7 KB)

wow, great! Thank you for your very fast answer!

1 Like