这里是我的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>
当我尝试将其转换成与此代码的PDF:
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();
}
}
它给了我这样的输出:
但是,当我在浏览器中打开XHTML,是这样的:
我没有得到这个问题。 我的主要目的是打破的话在给定的空间。 我使用的iText 2.0.8,我不能使用其他API作为我公司不允许。 任何建议将是一个很大的帮助。