原始打印动态图像 [英] Primefaces Print Dynamic Images

查看:107
本文介绍了原始打印动态图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图动态加载图像,一切正常。
图像我被加载并正确显示在动态的
中,我添加了打印标签。
现在,如果我要求打印动态创建的图像,我无法打印。

I tried to load an image dynamically, and everything works. The image I is loaded and displayed correctly in a dynamic, I added the tag for printing. Now if I ask to print the image created dynamically I can not print.

       <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;


}

就好像她忘记了图像创建。

it is as if she had forgotten the image created.

谢谢。

推荐答案

using CDI bean you can do this : 

@Model
public class ImageBean {

    private StreamedContent image;

    @Produces
    @Named
    public StreamedContent getImage() {
        if (FacesContext.getCurrentInstance().getRenderResponse()) {
            // rendering the view, return a stub StreamedContent to generate right URL.
            image = new DefaultStreamedContent();
        } else {
            // requesting the image
            image = your dynamic image;
        }

        return image;
    }
}




  • 在您的视图中: < pou:graphicImage id =imagevalue =#{image}/>

    • in your view : <pou:graphicImage id="image" value="#{image}" />
    • 这篇关于原始打印动态图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆