if (isDocumentRoot(name)) {
String key;
String value;
// pagesize and orientation specific code suggested by Samuel Gabriel
// Updated by Ricardo Coutinho. Only use if set in html!
LwgRectangle pageSize = null;
String orientation = null;
for (Iterator i = attributes.keySet().iterator(); i.hasNext();) {
key = (String) i.next();
value = attributes.getProperty(key);
try {
// margin specific code suggested by Reza Nasiri
if (ElementTags.LEFT.equalsIgnoreCase(key))
leftMargin = Float.parseFloat(value + "f");
if (ElementTags.RIGHT.equalsIgnoreCase(key))
rightMargin = Float.parseFloat(value + "f");
if (ElementTags.TOP.equalsIgnoreCase(key))
topMargin = Float.parseFloat(value + "f");
if (ElementTags.BOTTOM.equalsIgnoreCase(key))
bottomMargin = Float.parseFloat(value + "f");
} catch (Exception ex) {
throw new ExceptionConverter(ex);
}
if (ElementTags.PAGE_SIZE.equals(key)) {
try {
String pageSizeName = value;
Field pageSizeField = LwgPageSize.class
.getField(pageSizeName);
pageSize = (LwgRectangle) pageSizeField.get(null);
} catch (Exception ex) {
throw new ExceptionConverter(ex);
}
} else if (ElementTags.ORIENTATION.equals(key)) {
try {
if ("landscape".equals(value)) {
orientation = "landscape";
}
} catch (Exception ex) {
throw new ExceptionConverter(ex);
}
} else {
try {
document.add(new Meta(key, value));
} catch (DocumentException de) {
throw new ExceptionConverter(de);
}
}
}
if(pageSize != null) {
if ("landscape".equals(orientation)) {
pageSize = pageSize.rotate();
}
document.setPageSize(pageSize);
}
document.setMargins(leftMargin, rightMargin, topMargin,
bottomMargin);