我尝试动态加载图像,一切正常。我加载并以动态方式正确显示的图像,我添加了用于打印的标签。现在,如果我要求打印动态创建的图像,我将无法打印。
<pou:commandButton value="Print" type="button" icon="ui-icon-print">
<pou:printer target="image" />
</pou:commandButton>
<pou:graphicImage id="image" value="#{printDynamicBean.graphicIMG}" />
我的豆子是这样的:
public StreamedContent getGraphicIMG() {
//Graphic
BufferedImage bufferedImg;
try {
bufferedImg = ImageIO.read(baseImage);
} catch (IOException e) {
}
try {
Graphics2D g2 = bufferedImg.createGraphics();
g2.setColor(Color.black);
int style = Font.BOLD | Font.ITALIC;
Font f1 = new Font("TimesNewRoman", style , 60);
g2.setFont(f1);
g2.drawString("Hello Print", 80, 580);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImg, "png", os);
graphicIMG = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/png");
} catch (IOException ex) {
Logger.getLogger(PrintCartelliniBean.class.getName()).log(Level.SEVERE, null, ex);
}
return graphicIMG;
}
就好像她忘记了创造的形象。
谢谢。