Wrap Long Text in Table Cell during HTML to PDF Conversion using Java | Word-Break CSS CellFormat.WrapText Property

Hi,

Unable to wrap text or fit all text in a Table Cell using insertHtml(String html) of DocumentBuilder in Aspose.Words for Java.
If the text of a cell does not have any spaces or line breaks, the text stretches all the way to the right and makes the table overflow to right and outside of the page limit.

The HTML file has the expected result but in my analysis, I think Aspose is not applying word-break: break-all CSS style on table cells.

Attaching HTML file and Java code snippet below.

String recipientsTableHtml = "";

recipientsTableHtml+="<h4 style=\"text-align: left;\">&nbsp;Recipients Record</h4>";


recipientsTableHtml+="<table style=\" height: 127px; width:800px;  border: 1px ; border-spacing: 0px; font-size: 12px; \">";

recipientsTableHtml+="<tbody style=\"border: 1px ;\">";

recipientsTableHtml += "<tr style=\"border: 1px solid; height: 10px;text-align:center; \">";
recipientsTableHtml +="<th style=\"border: 1px solid; height: 10px;width : 25px;text-align:center; \">S.No</th>";
recipientsTableHtml +="<th style=\"border: 1px solid; height: 10px;width : 100px;text-align:center; \">Name</th>";
recipientsTableHtml +="<th style=\"border: 1px solid; height: 10px; width : 100px;text-align:center;\">Designation</th>";
recipientsTableHtml +="<th style=\"border: 1px solid; height: 10px; width : 100px;text-align:center;\">Mailing Address</th>";
recipientsTableHtml +="<th style=\"border: 1px solid; height: 10px;width : 100px; text-align:center;\">Category</th>";
recipientsTableHtml +="<th style=\"border: 1px solid; height: 10px;width : 100px; text-align:center;\">Contact</th>";
recipientsTableHtml +="</tr>";
for(int i = 0 ; i < 2; i++)
{ 
recipientsTableHtml+="<tr style=\"border: 1px solid; height: 10px;text-align:center;word-break: break-all;\">";
int index = i+1;
recipientsTableHtml+="<td style=\"border: 1px solid; height: 10px;text-align:center;word-break: break-all;\">"+ index +"</td>";
recipientsTableHtml+="<td style=\"border: 1px solid; height: 10px;text-align:center;word-break: break-all;\">ddddddddddddddddddddddddddddddddddddddddddddddddddddssssssssddddddddddddddddddddddddddddddddd	</td>";
recipientsTableHtml+="<td style=\"border: 1px solid; height: 10px;text-align:center;word-break: break-all;\">sdasdadasdd</td>";
recipientsTableHtml+="<td style=\"border: 1px solid; height: 10px;text-align:center;word-break: break-all;\">ddddddddddddddddddddddddddddddddddddddddddddddddddddssssssssddddddddddddddddddddddddddddddddd	</td>";
recipientsTableHtml+="<td style=\"border: 1px solid; height: 10px;text-align:center;word-break: break-all;\">Category</td>";
recipientsTableHtml+="<td style=\"border: 1px solid; height: 10px;text-align:center;word-break: break-all;\">sdgbgfjng</td>";
recipientsTableHtml+="</tr>";
}
recipientsTableHtml+=" </tbody>";
recipientsTableHtml+="</table>";
recipientsTableHtml+="</html>";

try {
	String filename = UUID.randomUUID().toString()+"_htmlToPdf";
	
	com.aspose.words.Document doc = null;
	try {
		doc = new com.aspose.words.Document();
	} catch (Exception e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	com.aspose.words.DocumentBuilder builder = new com.aspose.words.DocumentBuilder(doc);
	
	//Page setup
	builder.getPageSetup().setPaperSize(com.aspose.words.PaperSize.A4);
	builder.getPageSetup().setTopMargin(com.aspose.words.ConvertUtil.inchToPoint(0.5));
	builder.getPageSetup().setBottomMargin(com.aspose.words.ConvertUtil.inchToPoint(0.5));
	builder.getPageSetup().setLeftMargin(com.aspose.words.ConvertUtil.inchToPoint(0.5));
	builder.getPageSetup().setRightMargin(com.aspose.words.ConvertUtil.inchToPoint(0.5));
	
	builder.insertHtml(html);
	
	// Set Font Family
	for (com.aspose.words.Run run : (java.lang.Iterable<com.aspose.words.Run>) 				doc.getChildNodes(com.aspose.words.NodeType.RUN, true)) {
		run.getFont().setName("Arial");
	}
	
	doc.updateTableLayout();
	
	// Save doc
	doc.save(filename+".pdf", com.aspose.words.SaveFormat.PDF);
	
	System.out.println("PDF Created");
	return "";
} catch (Exception e) {
	System.out.println("Exception occurred" + e.getMessage());
	return null;
}

html.zip (1.4 KB)

Please guide, thanks in advance!

@mussab,

We have managed to reproduce this problem on our end and logged it in our issue tracking system with ID WORDSNET-21464. We will further look into the details of this problem and will keep you updated on the status of linked ticket. We apologize for your inconvenience.

Hi, any update on this issue?

@mussab,

WORDSNET-21464 is currently pending for analysis and is in the queue. We will inform you via this forum thread as soon as this issue will get resolved in future or any more updates may be available. We apologize for any inconvenience.

@awais.hafeez,

Hi, any progress on the aforementioned issue?

@mussab,

I am afraid, your issue is still pending for analysis and is in the queue. Please spare us some time. We will inform you via this forum thread as soon as this issue will get resolved in future. We apologize for any inconvenience.

@awais.hafeez,
Any update on the issue? It’s been pending for more than a month now.

@mussab,

We have completed the analysis of WORDSNET-21464. Aspose.Words currently does not process the word-break CSS property. The word-break property behavior handling should be implemented to be able to fix this problem. We will inform you via this forum thread as soon as this issue will get resolved in future. We apologize for any inconvenience.