0

我正在使用 JSP 生成一个 PDF 文件,我想应用 CSS 样式属性,但它不起作用。PDF 通常显示为未应用任何样式属性。

在以下示例中,我为 body 标签添加了绿色背景,但在 pdf 中未显示绿色。它仅显示纯 html。

请向我建议任何适合此问题的解决方案。

Document document = new Document();

FileOutputStream fileOutputStream = new FileOutputStream("C:/Program Files/Apache Software Foundation/Tomcat 6.0/webapps/pdf_generation/pdfGeneration10.pdf");

PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);

document.open();

HTMLWorker htmlWorker = new HTMLWorker(document);

String html = "<html><head></head><body style='background-color:green'><P> THIS IS SAMPLE ONE</p><table><tr><td>Demo and new be the way to go sdfsdf sdfdf</td></tr></table></body></html>";

StyleSheet styleSheet  = new StyleSheet();

htmlWorker.setStyleSheet(styleSheet);

htmlWorker.parse(new StringReader(html));

document.close();
4

0 回答 0