IText7 html2pdf页脚CSS不工作
我无法在下面的HTML和CSS的结果PDF中看到页脚。此代码适用于IText版本2 在IText版本7中显示页眉和页脚的方式是否已更改?或者我是否缺少更新版本所需的任何配置 谢谢 Java代码IText7 html2pdf页脚CSS不工作,html,css,itext,itext7,Html,Css,Itext,Itext7,我无法在下面的HTML和CSS的结果PDF中看到页脚。此代码适用于IText版本2 在IText版本7中显示页眉和页脚的方式是否已更改?或者我是否缺少更新版本所需的任何配置 谢谢 Java代码 public void createPdf(String src, String dest, String resources) throws IOException { try { FileOutputStream outputStream = new FileOutputStream(
public void createPdf(String src, String dest, String resources) throws IOException {
try {
FileOutputStream outputStream = new FileOutputStream(dest);
WriterProperties writerProperties = new WriterProperties();
//Add metadata
writerProperties.addXmpMetadata();
PdfWriter pdfWriter = new PdfWriter(outputStream, writerProperties);
PdfDocument pdfDoc = new PdfDocument(pdfWriter);
pdfDoc.getCatalog().setLang(new PdfString("en-US"));
// pdf conversion
ConverterProperties props = new ConverterProperties();
MediaDeviceDescription mediaDeviceDescription =
new MediaDeviceDescription(MediaType.PRINT);
props.setMediaDeviceDescription(mediaDeviceDescription);
HtmlConverter.convertToPdf(new FileInputStream(src), pdfDoc, props);
pdfDoc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Html内容
<html>
<head>
<meta charset="UTF-8"/>
<style type="text/css" media="print">
#footer {
display: block;
position: running(footer);
color:gray;
font-size: 50%
}
@page {
@bottom-center {
content: element(footer);
}
margin-bottom : 1in;
size: 6in 6in;
}
</style>
</head>
<body>
<div id="footer">
This is the text that goes at the bottom of every page.
</div>
....
..
.
</body>
</html>
#页脚{
显示:块;
位置:运行(页脚);
颜色:灰色;
字体大小:50%
}
@页面{
@底部中心{
内容:元素(页脚);
}
边缘底部:1英寸;
尺寸:6英寸6英寸;
}
这是每页底部的文本。
....
..
.
你做的一切都对。它不适用于您,因为运行元素(position:running(..)
和content:element(..)
properties)支持仅在最新版本中添加,iText 7.1.2。它是在四月底发布的。我正在使用7.1.7和@page doesnot work来让它工作。文档说,将MediaDeviceDescription设置为MediaType.PRINT并包装它@meda{@page{}仍然不工作