帖子
帖子
用户
博客
课程
显示全部楼层
216
帖子
5
勋章
5909
Y币

sysPrintPlus模块demo示例

[复制链接]
发表于 2022-2-21 11:13:54
sysPrintPlus 封装了Android系统打印、iOS系统AirPrint,支持ipad、打印图片 pdf webView文档


  1. <!DOCTYPE html>
  2. <html>

  3. <head>
  4.         <title>Module Develop</title>
  5.         <meta charset="utf-8">
  6.         <meta name="viewport"
  7.                 content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  8.         <style type="text/css">
  9.                 html,
  10.                 body {
  11.                         height: 100%
  12.                 }

  13.                 body {
  14.                         background-color: #fff;
  15.                         margin: 0;
  16.                 }

  17.                 #wrap {
  18.                         height: 100%;
  19.                         position: relative;
  20.                 }

  21.                 #header {
  22.                         padding-top: 20px;
  23.                         background-color: #5082c2;
  24.                         height: 44px;
  25.                         position: relative;
  26.                 }

  27.                 #header h1 {
  28.                         font-size: 20px;
  29.                         height: 44px;
  30.                         line-height: 44px;
  31.                         margin: 0em;
  32.                         color: #fff;
  33.                         margin-left: 100px;
  34.                         margin-right: 100px;
  35.                         text-align: center;
  36.                 }

  37.                 #main {
  38.                         display: -webkit-box;
  39.                         -webkit-box-orient: vertical;
  40.                         -webkit-box-pack: center;
  41.                 }

  42.                 a.button {
  43.                         display: -webkit-box;
  44.                         -webkit-box-orient: vertical;
  45.                         -webkit-box-pack: center;
  46.                         -webkit-box-align: center;
  47.                         height: 32px;
  48.                         margin: 8px;
  49.                         background-color: rgba(240, 240, 240, 1.0);
  50.                         border-color: rgba(220, 220, 220, 1.0);
  51.                         border-width: 2px;
  52.                         border-style: solid;
  53.                 }

  54.                 a.active {
  55.                         background-color: rgba(240, 240, 240, 0.7);
  56.                 }
  57.         </style>
  58. </head>

  59. <body>
  60.         <div id="wrap">
  61.                 <div id="main">
  62.                         <br />
  63.                         <a class="button" tapmode="active" onclick="toSystemPrintPage()" >跳转系统打印设置页面</a>
  64.                         <a class="button" tapmode="active" onclick="printPdf()" >打印pdf</a>
  65.             <a class="button" tapmode="active" onclick="printWebPage()" >打印web</a>
  66.             <a class="button" tapmode="active" onclick="printHtml()" >打印html</a>
  67.                         <a class="button" tapmode="active" onclick="printImg()" >打印图片</a>
  68.                         <a class="button" tapmode="active" onclick="hasPrintService()" >判断是否有打印服务</a>
  69.                         <br />
  70.                 </div>
  71.         </div>
  72. </body>
  73. <script type="text/javascript">
  74.         var demo = null;
  75.         apiready = function () {
  76.                 demo = api.require('sysPrintPlus');
  77.                 if (!demo) {
  78.                         alert("请添加模块后编译");
  79.                         return;
  80.                 }
  81.         }
  82.         function toSystemPrintPage() {
  83.                 demo.toSystemPrintPage();
  84.         }

  85.         function printPdf() {
  86.                 demo.printPdf({
  87.                         filePath: 'widget://res/XF_appsFlyer.pdf',
  88.                 }, function (ret, err) {
  89.                         //alert(JSON.stringify(ret));
  90.                 });
  91.         }

  92.         function printWebPage() {
  93.                 demo.printWebPage({
  94.                         url: 'https://**.**/Android',
  95.                 }, function (ret, err) {
  96.                         //alert(JSON.stringify(ret));
  97.                 });
  98.         }

  99.         function printHtml() {
  100.                 demo.printHtml({
  101.                         html: '<html><body><h1>TPS Report for: {{reportDate}}</h1><p>Here are the contents of this week\'s TPS report:</p><p>{{message}}</p><p>If you have any questions regarding this report, pleasedo <b>not</b> ask Mark Murphy.</p></body></html>',
  102.                 }, function (ret, err) {
  103.                         //alert(JSON.stringify(ret));
  104.                 });
  105.         }

  106.         function printImg() {
  107.                 demo.printImg({
  108.                         filePath: 'widget://res/cloud_pic.png',
  109.                 }, function (ret, err) {
  110.                         //alert(JSON.stringify(ret));
  111.                 });
  112.         }

  113.         function hasPrintService() {
  114.                 var ret = demo.hasPrintService();
  115.                 alert(JSON.stringify(ret));
  116.         }
  117. </script>

  118. </html>
复制代码


380
帖子
4
勋章
6
Y币
支持
24
帖子
0
勋章
235
Y币
这个模块 ios用的 系统打印 也就是 airprint  需要打印设备支持 airprint  现在就没找到 有哪款标签打印机 支持airprint的
1
帖子
0
勋章
18
Y币
sysPrintPlus 这个模块打印闪退啊
216
帖子
5
勋章
5909
Y币
找下闪退日志呢。
0
帖子
0
勋章
10
Y币

你好这边遇到类似问题,有更新版的示例嘛
您需要登录后才可以回帖 登录

本版积分规则