是否可以使用p:printer(或其他方法)打印由primefaces扩展生成的QR Code [英] Is it possible to print QR Code generated by primefaces extensions with p:printer (or other method)

查看:188
本文介绍了是否可以使用p:printer(或其他方法)打印由primefaces扩展生成的QR Code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用p:printer标签打印由pe:qrCode生成的QR码.当我将renderMethod设置为img或div时,它根本不会渲染到屏幕上.我没有看到有关如何使用该属性的任何文档.我看过许多有关需要其他jar的文章,但看起来是针对较早的p:bacode功能的.当我直接从浏览器打印时,它将打印,但是我正在打印到标签,所以不想打印整个页面.由于它是由客户端上的jQuery生成的,也许我需要使用javascript使其起作用.在我走这条其他道路之前,我只想知道是否有人能成功打印由primefaces扩展生成的qr代码.

I'm unable to print a QR Code generated by pe:qrCode using p:printer tag. When I set renderMethod to img or div, it doesn't render to the screen at all. I don't see any documentation on how to use that attribute. I've seen various posts about needing other jars but it looks like that was for the older p:bacode functionality. When I print directly from the browser it will print but I am printing to labels so don't want to be printing the whole page. Since it is generated by jQuery on the client perhaps I need to use javascript to make it work. Before I go down these other paths I just want to know if anyone has had success printing qr codes generated by primefaces extensions.

这里是生成QR码但无法打印的代码示例.

Here is a sample of code that is generation QR Code but unable to print.

<h:form>
<h:panelGrid>
    <p:commandButton value="Print QR">
        <p:printer target="qrCodeElem"/>
    </p:commandButton>

    <p:commandButton value="Print QR Panel">
        <p:printer target="qrPanelId"/>
    </p:commandButton>

    <p:commandButton value="Print Hello">
        <p:printer target="helloId"/>
    </p:commandButton>

    <p:panel id="qrPanelId">
        <pe:qrCode id="qrCodeElem"
                   renderMethod="canvas"
                   text="someqrcode"
                   label="qrCodeLabel"
                   size="200"/>
    </p:panel>
</h:panelGrid>

<p:panel id="helloId">
    <h:outputText value="hello "/>
</p:panel>
</h:form>

</html>

推荐答案

我能够使用简单的print()命令进行打印

I was able to print using a simple print() command

 <p:commandButton value="print()" onclick="print();"/>

我还需要CSS来告诉它不要打印我不想打印的内容.原来,我需要在页面上内联CSS.将其放在我的.css文件中不会忽略我不想打印的部分.这是CSS

I also needed css to tell it not to print the things I didn't want to print. It turned out I needed to have the CSS inline on the page. Putting it in my .css file did not ignore the parts I did not want to print. Here is the css

<style type="text/css">
@media print {
    .noPrint {
        display: none;
    }
  }
 </style>

使用styleClass进行引用

Reference it with styleClass

   <h:panelGrid styleClass="noPrint">

这篇关于是否可以使用p:printer(或其他方法)打印由primefaces扩展生成的QR Code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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