Cordova 如何解决SAPUI5 fiori客户端中的打印问题?
我开发了一个SAPUI5应用程序,它有一个打印按钮,当我点击打印按钮时,我在页面的特定区域使用了window.print()Cordova 如何解决SAPUI5 fiori客户端中的打印问题?,cordova,printing,sapui5,sap-fiori,Cordova,Printing,Sapui5,Sap Fiori,我开发了一个SAPUI5应用程序,它有一个打印按钮,当我点击打印按钮时,我在页面的特定区域使用了window.print() var win = window.open("", "PrintWindow"); var headContents = $("head").html(); win.document.write('<html><head>'+ headContents + '</head><body>'); var bodyContent
var win = window.open("", "PrintWindow");
var headContents = $("head").html();
win.document.write('<html><head>'+ headContents + '</head><body>');
var bodyContent = $(".printArea").html();
win.document.write("<div style='width=220mm'>" + bodyContent + "</div>");
win.document.write('</body></html>');
setTimeout(function() {
win.print();
win.stop();
}, 2000);
var-win=window.open(“,“PrintWindow”);
var headContents=$(“head”).html();
win.document.write(“”+标题内容+“”);
var bodyContent=$(“.printArea”).html();
win.document.write(“+bodyContent+”);
win.document.write(“”);
setTimeout(函数(){
win.print();
赢。停();
}, 2000);
它在浏览器中工作正常,但当我在FIORI客户端中打开它时,它不工作。
在阅读了一些博客后,我了解到window.print在FIORI客户端不起作用。博客建议使用Cordova print Plugin而不是window.print
然后我使用了Cordova打印插件,如下所示
var headContents = $("head").html();
var he = '<html><head><title>Form</title>' + headContents + '</head><body>';
var bodyContent = $(".printArea").html();
var co = "<div style='width=220mm' class='formpage'>" + bodyContent + "</div>";
var clo = "</body></html>";
var htmlpage = he + co + clo;
cordova.plugins.printer.print(htmlpage, {
duplex: 'long'
}, function(res) {
alert(res ? 'Done' : 'Canceled');
});
var headContents=$(“head”).html();
var he='表格'+目录+'';
var bodyContent=$(“.printArea”).html();
var co=“”+bodyContent+”;
var clo=“”;
var htmlpage=he+co+clo;
cordova.plugins.printer.print(htmlpage{
双工:“长”
},功能(res){
警报(res?'Done':'cancelled');
});
我需要任何CSS样式表在我的HTML页面应该在打印也。
Cordova打印插件建议使用嵌入式CSS或绝对样式表URL。
因为我使用的是SAPUI5视图,所以无法编写内联CSS
1)如何在Cordova打印插件中给出library.css的绝对URL?
2)如何从SAPUI5 CSS中为打印文档提供嵌入样式?关于第一个问题,要获得外部CSS的绝对路径,您需要提供CSS文件(包括域)的完整路径。 但是,如果要打印整个页面,则不需要执行此步骤 要打印包含CSS的页面部分,需要将html元素的字符串内容传递给Cordova print插件的打印功能。 在第二个代码示例中,我看到您已将bodyContent元素封装到包含嵌入式CSS样式的div中。 由于您无法编写嵌入式CSS,因此这是一个很好的解决方法 但是,CSS语法并不正确
style=’width:220mm;’
相反
此外,我建议您将代码段包装到print按钮的onclick函数中。
通过这种方式,您可以确保所有DOM元素都已可访问
因此,一个可能的解决办法是:
function printArea() {
var headContents = $("head").html();
var he = '<html><head><title>Form</title>' + headContents + '</head><body>';
var bodyContent = $(".printArea").html();
var co = "<div style=’width:220mm;’ class='formpage'>" + bodyContent + "</div>";
var clo = "</body></html>";
var htmlpage = he + co + clo;
cordova.plugins.printer.print(htmlpage, {
duplex: 'long'
}, function(res) {
alert(res ? 'Done' : 'Canceled');
});
}
函数printArea(){
var headContents=$(“head”).html();
var he='表格'+目录+'';
var bodyContent=$(“.printArea”).html();
var co=“”+bodyContent+”;
var clo=“”;
var htmlpage=he+co+clo;
cordova.plugins.printer.print(htmlpage{
双工:“长”
},功能(res){
警报(res?'Done':'cancelled');
});
}
您可以在共同包含的div中添加所需的CSS。
现在,您应该能够打印包含CSS的页面部分。我试图理解这个问题:您不想打印整个页面,而只是打印页面的特定区域?IIRC打印整个页面应该可以通过设置菜单在Fiori客户端中使用。@是的,我只想打印页面的特定区域。您在哪个平台上运行应用程序?是iOS还是Android?目前,我正在使用Android,但iOS和Android都需要它。