Vertical spacing of text is changed after HTML to PDF conversion using Java

I am generating a pdf using Aspose words. There is a slight difference in the vertical spacing of text while a when an entire line in a column in bold. The difference is subtle but evident. PFA the generated pdf.
aspose-generated.pdf (28.0 KB)
The code required to reproduce this issue is given below:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.moveToDocumentStart();
builder.insertCell();
Table table = builder.startTable();
table.setAlignment(TableAlignment.CENTER);
table.setBorders(LineStyle.EMBOSS_3_D, 2.0, Color.BLACK);
builder.insertHtml("<b><font size=\"5\">Lorem Ipsum</font></b>");
builder.endTable();
String finalClauseText = "<table style=\"width:100%;\"><tr><td valign=\"top\" style=\"width:48%\"><p style=\"font-family:Arial;font-size:12px;text-align:justify;page-break-after:avoid;page-break-inside:avoid;\"><b><u>Article 2</u> - texte en gras</b><span style=\"white-space:pre-line;\"></span></p></td><td style=\"width:4%\"></td><td valign=\"top\" style=\"width:48%\"><p style=\"font-family:Arial;font-size:12px;text-align:justify;page-break-after:avoid;page-break-inside:avoid;\"><b><u>Article 2</u> - bold text</b><span style=\"white-space:pre-line;\"></span></p></td></tr></table><table style=\"width:100%\"><tr><td valign=\"top\" style=\"width:48%\"><div style=\"font-family:Arial;font-size:12px;text-align:justify\"><strong>Contrairement &agrave; la croyance populaire, le Lorem</strong> Ipsum n'est pas un simple texte al&eacute;atoire. Il trouve ses racines dans un morceau <span style=\"text-decoration: underline;\">de litt&eacute;rature latine</span> classique datant de 45 avant J.-C., ce qui lui donne plus de 2000 ans. Richard McClintock, professeur de latin au Hampden-Sydney College en Virginie, a recherch&eacute; l'un des mots latins les plus obscurs, consectetur, dans un passage du Lorem Ipsum, et en parcourant les citations du mot dans la litt&eacute;rature classique, <strong>il a d&eacute;couvert</strong> la source incontestable. Le Lorem Ipsum provient des sections 1.10.32 et 1.10.33 du \"de Finibus Bonorum et Malorum\" (Les extr&ecirc;mes du bien et du mal) de Cic&eacute;ron, &eacute;crit en 45 avant J.-C. Ce livre est un trait&eacute; sur la th&eacute;orie de l'&eacute;thique, tr&egrave;s populaire pendant la Renaissance. La premi&egrave;re ligne de Lorem Ipsum, \"Lorem ipsum dolor sit amet...\", <strong>provient d'une ligne de</strong> la section 1.10.32.</div></td><td style=\"width:4%\"></td><td valign=\"top\" style=\"width:48%\"><div style=\"font-family:Arial;font-size:12px;text-align:justify\"><strong>Contrary to popular</strong> belief, Lorem Ipsum is not simply random text. It has roots in a piece<strong> of classical Latin literature from 45</strong> BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extrem<strong>es of Good and Evi</strong>l) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32.</div></td></tr></table>\r\n";
builder.insertHtml("<br>" + finalClauseText);
String tempFileAbsolutePath = "/some/path/file.pdf";
doc.save(tempFileAbsolutePath, SaveFormat.PDF);
1 Like

@sonawane.milind

We have tested the scenario using the latest version of Aspose.Words for Java 20.9 and have not found any issue with output PDF. So, please use Aspose.Words for Java 20.9.

Please check the attached output PDF. 20.9.java.pdf (62.6 KB)

Could you please share the screenshot of problematic section of output document along with expected output PDF? We will investigate the issue and provide you more information on it.

1 Like

Thanks for the response.

We are using Aspose Words version 19.09

Attaching the expected and actual output.

actual output.JPG (104.2 KB)
expected output.JPG (217.9 KB)

@sonawane.milind

Please note that Aspose.Words mimics the behavior of MS Word. If you convert your HTML to PDF using MS Word, you will get the same output. You can open HTML document in MS Word and convert it to PDF.

Hello @tahir.manzoor

Thanks for the response.

This bug was not reproducible on version 20.8.

The word file gets generated correctly. It is the PDF we are facing issue with. On opening the word file, the generated PDF does not have this issue (ie open the doc using MS Word and exporting pdf). May I request you to please confirm whether a workaround is present for version 19.09?

@sonawane.milind

Please note that we do not provide support for older released versions of Aspose.Words. Moreover, we do not provide any fixes or patches for old versions of Aspose products either. All fixes and new features are always added into new versions of our products.

We always encourage our customers to use the latest version of Aspose.Words as it contains newly introduced features, enhancements and fixes to the issues that were reported earlier.

Hello @tahir.manzoor,

Thanks for confirming! Thanks for your help!