我无法使用p:printer标签打印pe:qrCode生成的QR码。当我将renderMethod设置为img或div时,它根本不会渲染到屏幕上。我没有任何有关如何使用该属性的文档。我看过很多关于需要其他jar的帖子,但看起来是针对较早的p:bacode功能的。当我直接从浏览器中打印时,它将打印,但是我正在打印至标签,因此不想打印整个页面。由于它是由客户端上的jQuery生成的,也许我需要使用javascript使其起作用。在我走这条其他道路之前,我只想知道是否有人能成功打印由primefaces扩展生成的qr代码。
这是生成QR码但无法打印的代码示例。
<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>
答案 0 :(得分:2)
我能够使用简单的print()命令进行打印
<p:commandButton value="print()" onclick="print();"/>
我还需要CSS来告诉它不要打印我不想打印的内容。原来,我需要在页面上内联CSS。将其放在我的.css文件中不会忽略我不想打印的部分。这是CSS
<style type="text/css">
@media print {
.noPrint {
display: none;
}
}
</style>
使用styleClass进行引用
<h:panelGrid styleClass="noPrint">