// we create a template and a Graphics2D object that corresponds
// with it
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(width, height);
PdfGraphics2D graphic = (PdfGraphics2D) tp.createGraphics(width, height, mapper);
// we set graphics options
if (!mapContent.isTransparent()) {
graphic.setColor(mapContent.getBgColor());
graphic.fillRect(0, 0, width, height);