I would like to produce docx from xhtml, including footer/header with page numbering. The input is:
- Code: Select all
String pXHTML += """
<html>
<head>
<style>
@page {
@top-center {
content: element(header)
}
@bottom-center {
content: element(footer)
}
}
div.header {
display : block;
text-align: center;
position : running(header);
}
div.footer {
display : block;
text-align: center;
position : running(footer);
}
.page-number::after {
content: counter(page) "/" counter(pages);
}
</style>
</head>
<body>
<div class="header">
this is the header
</div>
<div class="footer">
this is the footer with page numbers <p class="page-number"></p>
</div>
</body>
</html>
"""
The code that process it is as follows:
- Code: Select all
String xhtmlText = addDoctype(pXHTML);//method not inluded here
WordprocessingMLPackage wordMLPackageXHTML = WordprocessingMLPackage.createPackage();
XHTMLImporterImpl XHTMLImporter = new XHTMLImporterImpl(wordMLPackageXHTML);
wordMLPackageXHTML.getMainDocumentPart().getContent().addAll(XHTMLImporter.convert(xhtmlText, null));
Save saveToZip = new Save(wordMLPackageXHTML);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
saveToZip.save(byteArrayOutputStream);
The result page document has simply plain text
this is the header
this is the footer with page numbers
on the top of page.
How to convert it into proper header and footer, the latter with page numbering?