Here's my XHTML:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <META content="text/html; charset=UTF-8" http-equiv="Content-Type" /> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <table cellspacing="0" cellpadding="0" align="Center" style="table-layout: fixed; word-wrap: break-word; width: 97%" bordercolor="4f81BD" border="1"> <tbody> <tr style="color: white;"> <td height="31" bgcolor="#4f81BD" style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px" align="Center"><span style="font-weight: Bold">Type</span></td> <td bgcolor="#4f81BD" style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px" align="Center"><span style="font-weight: Bold">Custodian Name</span></td> <td bgcolor="#4f81BD" style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px" align="Center"><span style="font-weight: Bold">Relationship to Owner</span></td> <td bgcolor="#4f81BD" style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px" align="Center"><span style="font-weight: Bold">Percent</span></td> <td bgcolor="#4f81BD" style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px" align="Center"><span style="font-weight: Bold">Minor Name</span></td> <td bgcolor="#4f81BD" style="border-left: none; border-bottom: none; border-Right: none; border-top: none; border-width: 1px" align="Center"><span style="font-weight: Bold">For the State of</span></td> </tr> <tr style="font-family: SansSerif;" align="center"> <td style="border-left: none; border-bottom: solid; border-top: none; border-Right: none; border-width: 1px;" align="Center"><span style="font-weight: Bold"> UTMA/UGMA</span></td> <td style="border-left: none; border-bottom: solid; border-top: none; border-Right: none; border-width: 1px;" align="Center"><span>QQQQQQQQQQQQQQQQQQQQQQQQQ MMMMMMMMMMMMMMMMMMMMMMMMMM</span></td> <td style="border-left: none; border-bottom: solid; border-top: none; border-Right: none; border-width: 1px;" align="Center"><span>Common Law Husband</span></td> <td style="border-left: none; border-bottom: solid; border-top: none; border-Right: none; border-width: 1px;" align="Center"><span>15%</span></td> <td style="border-left: solid; border-bottom: solid; border-top: none; border-Right: solid; border-width: 1px;" align="Center">RRRRRRRRRRRRRRRRRRRRRRRR BBBBBBBBBBBBBBBBBBBBBB</td> <td style="border-left: none; border-bottom: solid; border-top: none; border-Right: none; border-width: 1px;" align="Center"><span>DC</span></td> </tr> </tbody> </table> </body> </html>
When I try to convert it into a PDF with this code:
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import org.xhtmlrenderer.pdf.ITextRenderer; import com.lowagie.text.DocumentException; public class Practice { public static void main(String[] args) throws IOException, DocumentException { String inputFile = "sample.xhtml"; String url = new File(inputFile).toURI().toURL().toString(); String outputFile = "firstdoc.pdf"; OutputStream os = new FileOutputStream(outputFile); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(url); renderer.layout(); renderer.createPDF(os); os.close(); } }
It's giving me this output:
But when I open the XHTML in a browser, it's like this:
I am not getting the problem. My main aim is to break the words in that given space. I use iText 2.0.8 and I can't use other APIs as my company does not allow that. Any suggestion would be a lot of help.