在我的项目中,我需要使用qr代码生成html(某些表格,标签等),并进行打印。除了在Chrome中打印二维码外,其他所有功能都可以正常运行。 Chrome不会打印二维码,这是页面。我在做什么错了?
<h:form id="printForm" prependId="false">
...
<div style="background-color: #f8f8f8;">
<button onclick="myFunction()" style="float: right;" class="btn btn-primary no-print">Печать</button>
<div >
<h:outputText id="print" value="#{formPrintController.content}" escape="false" style="line-height: 1"/>
</div>
</div>
...
</h:form>
JS代码
<script type="text/javascript">
function myFunction() {
var divToPrint=document.getElementById("print");
newWin= window.open("");
console.log(divToPrint.outerHTML);
newWin.document.write(divToPrint.outerHTML);
newWin.print();
newWin.close();
}
</script>
控制器
@Controller
@SpringViewScoped
public class FormPrintController{
private String content;
@PostConstruct
public void init() throws IOException, DocumentException {
...
HttpServletRequest request = (HttpServletRequest)
FacesContext.getCurrentInstance().getExternalContext().getRequest();
String url = request.getRequestURL().toString();
String qr ="https://api.qrserver.com/v1/create-qr-code/?data="+url+"&size=50x50";
content = "<img style=\"width:50px;height:50px\" src=\"" + qr+"\"/>";
System.out.println(content);
...
}
}
System.out.println(content)结果:
<img style="width:50px;height:50px" src="https://api.qrserver.com/v1/create-qr-code/?data=http://localhost:8080/view/constructor-form/form-print.xhtml&size=50x50"/>
我试图在Mozilla FireFox中打印它,一切正常。有什么问题吗?