我正在使用iText将html转换为pdf。 pdf已成功生成,但是html中的表格内容在生成的pdf中缺少边框。如何确保转换后表格边框没有丢失?
pom.xml
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.4.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.itextpdf.tool/xmlworker -->
<dependency>
<groupId>com.itextpdf.tool</groupId>
<artifactId>xmlworker</artifactId>
<version>5.4.1</version>
</dependency>
功能
public StreamedContent getFile() throws IOException, DocumentException{
final PortletResponse portletResponse = (PortletResponse) FacesContext.getCurrentInstance().getExternalContext()
.getResponse();
final HttpServletResponse res = PortalUtil.getHttpServletResponse(portletResponse);
res.setContentType("application/pdf");
res.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
res.setHeader("Content-Disposition", "attachment; filename=" + subject + ".pdf");
res.setHeader("Refresh", "1");
res.flushBuffer();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStream out = res.getOutputStream();
Document document = new Document(PageSize.LETTER);
PdfWriter pdfWriter =PdfWriter.getInstance(document, baos);
document.open();
document.addCreationDate();
XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
//htmlWorker.parse(new StringReader(getMessage()));
worker.parseXHtml(pdfWriter, document, new StringReader(getMessage()));
document.close();
baos.writeTo(out);
out.flush();
out.close();
return null;
}
HTML内容 -bean中的
<o:p></o:p></span></p></td></tr><tr style="height: 15pt;"><td width="237" colspan="2" style="width: 177.7pt; border: 1pt solid windowtext; padding: 0in 5.4pt; height: 15pt;"><p class="MsoNormal" align="right" style="margin-bottom: 0.0001pt; text-align: right; line-height: normal;"><a name="RANGE!A15"><b><span arial",sans-serif;="" mso-fareast-font-family:"times="" new="" roman""="" style="font-size: 9pt;">XXX:</span></b></a><b><span arial",sans-serif;="" mso-fareast-font-family:"times="" new="" roman""="" style="font-size: 9pt;"><o:p></o:p></span></b></p></td><td width="394" colspan="3" style="width: 4.1in; border-top: 1pt solid windowtext; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-image: initial; border-left: none; padding: 0in 5.4pt; height: 15pt;"><p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span tahoma",sans-serif"="" style="font-size: 9pt;">«0266855430»</span><span arial",sans-serif;="" mso-fareast-font-family:"times="" new="" roman""="" style="font-size: 9pt;"><o:p></o:p></span></p></td></tr><tr style="height: 15pt;"><td width="237" colspan="2" style="width: 177.7pt; border-right: 1pt solid windowtext; border-bottom: 1pt solid windowtext; border-left: 1pt solid windowtext; border-image: initial; border-top: none; padding: 0in 5.4pt; height: 15pt;"><p class="MsoNormal" align="right" style="margin-bottom: 0.0001pt; text-align: right; line-height: normal;"><b><span arial",sans-serif;mso-fareast-font-family:="" "times="" new="" roman""="" style="font-size: 9pt;">SENDER NAME:<o:p></o:p></span></b></p></td><td width="394" colspan="3" style="width: 4.1in; border-top: none; border-left: none; border-bottom: 1pt solid windowtext; border-right: 1pt solid windowtext; padding: 0in 5.4pt; height: 15pt;"><p class="MsoNormal" style="margin-bottom: 0.0001pt; line-height: normal;"><span tahoma",sans-serif"="" style="font-size: 9pt;">«DAREO»
源图像(p:质素编辑器)
输出(边界丢失)
其他所有东西都完美无缺。
请提出建议。