Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带嵌入式CSS的iText HTML_Java_Html_Export_Itext - Fatal编程技术网

Java 带嵌入式CSS的iText HTML

Java 带嵌入式CSS的iText HTML,java,html,export,itext,Java,Html,Export,Itext,我正在开发一个表导出接口,以导出到HTML、PDF和RTF。我之所以使用iText是因为它允许对这三种类型进行非常相似的处理 HTML导出的简单示例: final Document document = new Document(PageSize.A4, 50, 50, 50, 50); HtmlWriter writer = HtmlWriter.getInstance(document, outputStream); Table actTable = new Table(colCount);

我正在开发一个表导出接口,以导出到HTML、PDF和RTF。我之所以使用iText是因为它允许对这三种类型进行非常相似的处理

HTML导出的简单示例:

final Document document = new Document(PageSize.A4, 50, 50, 50, 50);
HtmlWriter writer = HtmlWriter.getInstance(document, outputStream);
Table actTable = new Table(colCount);
final Cell c = new Cell(cellString);

c.setColspan(colSpan);
c.setHeader(isHeader);

actTable.addCell(c);
writer.add(actTable);
到目前为止,基本版本仍在运行,我现在要为元素设置样式

在前一个导出类中,我使用了一个嵌入式样式表:

  String cssFileContent = IOUtils.toString(new FileInputStream("style.css"));

  final StringBuilder sb = new StringBuilder();

  sb.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">\n");
  sb.append("<meta http-equiv='Content-Type' content='text/html;charset=ISO-8859-1'>\n");
  sb.append("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n");
  sb.append("<head>\n<title>");
  sb.append(title);
  sb.append("</title>\n");
  sb.append("<style media='screen' type='text/css'>\n");
  sb.append(cssFileContent); // embed the stylesheet
  sb.append("</style>");
  sb.append("<div id=\"header\"></div>\n");
  sb.append("</head>\n");
  sb.append("<body>\n");
  ...

您不应该使用旧版本的iText。除了技术限制之外,此lib的5之前版本还存在一些严重的法律问题:。从iText 5开始,RTF函数性已被删除,我理解这可能是您的一个问题,但HTML到PDF的转换已显著改进。感谢您的提示。我可以放弃RTF支持,这只是一个很好的选择。但要澄清的是:这与HTML到PDF无关。这个主题是关于HTML导出的。哦,我的错,我读你的问题太快了。。。iText 5+恐怕不会进行任何HTML导出,它的范围已经缩小到最初的目的:PDF创建和操作。是的。我将使用iText 5,并寻找一个没有DOM树HTML导出api的新流。
<tr>
  <td border="0.5" width="0">
    <div>testA0,0
    </div>
  </td>
</tr>