Is it possible to print QR Code generated by primefaces extensions with p:printer (or other method)
Asked Answered
B

1

1

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.

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>
Brandi answered 16/5, 2019 at 0:25 Comment(2)
have you tried setting the target in p:printer to the id of the pe:qrCode directly?Randle
yes, that's what the first commandButton doesBrandi
B
2

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

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

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>

Reference it with styleClass

   <h:panelGrid styleClass="noPrint">
Brandi answered 22/5, 2019 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.