GenericJonが提案したことを綴っているだけです...
背景バンドに画像要素を追加します (設定はスクリーンショットを参照)。
Renderable を実装し、パラメータ マップを介して Jasper Reports に渡します。
InputStream jasperReportInputStream = getClass().getResourceAsStream("/reports/Test.jasper");
JRBeanCollectionDataSource dataSource = ...
Map parameters = new HashMap();
parameters.put("watermark", new WaterMarkRenderer(true);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReportInputStream, parameters, dataSource);
透かしレンダラー:
@SuppressWarnings("deprecation")
public class WaterMarkRenderer extends JRAbstractRenderer
{
private boolean m_licenseTrial = false;
public WaterMarkRenderer(boolean isLicenseTrial)
{
m_licenseTrial = isLicenseTrial;
}
@Override
public byte getType()
{
// no idea what this does
return RenderableTypeEnum.SVG.getValue();
}
@Override
public byte getImageType()
{
// no idea what this does
return ImageTypeEnum.UNKNOWN.getValue();
}
@Override
public Dimension2D getDimension() throws JRException
{
// A4 in pixel: 595x842
// this seems to override whatever is configured in jasperreports studio
return new Dimension(595 - 2 * 40, 700);
}
@Override
public byte[] getImageData() throws JRException
{
// no idea what this does
return new byte[0];
}
@Override
public void render(Graphics2D g2, Rectangle2D rectangle) throws JRException
{
if(m_licenseTrial)
{
AffineTransform originalTransform = g2.getTransform();
// just for debugging
g2.setColor(Color.BLUE);
g2.draw(rectangle);
g2.translate(rectangle.getX() + 100, rectangle.getMaxY());
g2.rotate(-55 * Math.PI / 180);
Font font = new Font("Arial", Font.PLAIN, 120);
Shape shape = font.createGlyphVector(g2.getFontRenderContext(), "Trial License").getOutline();
g2.setColor(new Color(255, 0, 0, 100));
g2.setStroke(new BasicStroke(1));
g2.draw(shape);
g2.setTransform(originalTransform);
}
}
}
そして結果: