String simplePageMasterName = spm.getMasterName(); // eg s1-first page
// We'll need the corresponding ConversionSectionWrapper
int index = -1 + Integer.parseInt(
simplePageMasterName.substring(1, simplePageMasterName.indexOf("-")));
PageDimensions page = null;
if (sections.get(index)==null) {
log.error("Couldn't find section " + index + " from " + simplePageMasterName);
} else {
page = sections.get(index).getPageDimensions();
}
// Region before
if (spm.getRegionBefore()!=null) {
Integer hBpdaMilliPts = headerBpda.get(simplePageMasterName);
if (hBpdaMilliPts==null) {
// No headerBpda for s1-default
log.error("No headerBpda for " + simplePageMasterName);
// You need to debug to find out why
} else {
float hBpdaPts = hBpdaMilliPts/1000;
spm.getRegionBefore().setExtent(hBpdaPts+"pt");
spm.getRegionBody().setMarginTop(hBpdaPts+"pt");
// If the top margin in Word > what we have, then pad with margin top
float totalHeight = (page.getHeaderMargin()/20 ) // twips to points
+ hBpdaPts;
float extraMargin = (page.getPgMar().getTop().intValue()/20) - totalHeight;
if (extraMargin>0) {
float required = (page.getPgMar().getTop().intValue()-page.getHeaderMargin())/20;
spm.getRegionBody().setMarginTop(required+"pt");
} // otherwise, we've expanded to the extent of the header already
}
}
// Region after
if (spm.getRegionAfter()!=null) {
Integer fBpdaMilliPts = footerBpda.get(simplePageMasterName);
if (fBpdaMilliPts==null) {
log.error("No footerBpda for " + simplePageMasterName);
} else {
float fBpdaPts = fBpdaMilliPts/1000;
spm.getRegionAfter().setExtent(fBpdaPts+"pt");
spm.getRegionBody().setMarginBottom(fBpdaPts+"pt");
// If the bottom margin in Word > what we have, then pad with margin bottom
float totalHeight = (page.getFooterMargin()/20 ) // twips to points
+ fBpdaPts;
float extraMargin = (page.getPgMar().getBottom().intValue()/20) - totalHeight;
if (extraMargin>0) {
float required = (page.getPgMar().getBottom().intValue()-page.getFooterMargin())/20;
spm.getRegionBody().setMarginBottom(required+"pt");
} // otherwise, we've expanded to the extent of the footer already
}
}