Reputation: 138
I am not able to see footer in resultant PDF for below HTML and CSS. This code works fine with IText version 2.
Does the way to show header and footer is changed in IText version 7? or am I missing any configuration required for newer version?
Thanks.
Java code
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 content
<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>
Upvotes: 1
Views: 1876
Reputation: 588
You're doing everything right. It wasn't working for you because running elements (position: running(..)
and content: element(..)
properties) support is added only in the latest version, iText 7.1.2. It was released in the end of April.
Upvotes: 2