JS中FireFox新开窗口预览打印处理的方式
仅提供思路,勿喷如下↓
/**
* 打印方法
* @param dom 要被打印的dom元素
* @param parentClassName 该组件的页面根组件class名
* @param pageMargin @page中的maring值
*/
static print = (dom, parentClassName = '', pageMargin = '20px') => {
if (navigator.userAgent.indexOf("Firefox") > ) { let previewDom = document.getElementById('previewDom_serviceCharges');
if (previewDom && previewDom.offsetHeight) {
const imgNumber = parseInt(String(previewDom.offsetHeight / )) + ; let webConfig = (<any>window).config;
let hostAddress = webConfig.isDebug ? `http://${window.location.host}` : `http://${window.location.host}/erpfront/dist`;
let backimg = document.createElement('div'), htmlStr = '';
for (let i = ; i < imgNumber; i++) {
htmlStr += `
<img src='${hostAddress}/assets/images/contract-background.jpg'>
` ;
}
backimg.innerHTML = htmlStr;
backimg.setAttribute('style', `
position: absolute;
bottom: 0px;
padding: 0px;
margin: 0px;
top: ;
z-index: -;
width: %;
`);
//backimg.className = 'backimg';
previewDom.appendChild(backimg);
} const domPrint = document.createElement('div');
domPrint.className = parentClassName;
domPrint.id = 'dom-content-for-print-printutils';
domPrint.innerHTML = dom.outerHTML; let page = window.open('', '_blank');// 打开一个新窗口,用于打印
page.document.body.innerHTML = domPrint.outerHTML;// 写入打印页面的内容 const domPrintStyle = document.createElement('style');
domPrintStyle.id = 'dom-style-for-print-printutils';
domPrintStyle.innerHTML = PrintUtils.getFirefoxStyle(pageMargin); page.document.head.appendChild(domPrintStyle); page.print();// 打印
page.close();// 关闭打印窗口 }
}
static getFirefoxStyle(pageMargin: any) {
PrintUtils.firefoxStyleString = `
@media print {
body {
float: none !important;
position: static !important;
display: inline;
page-break-after: always;
}
body > * {
display: none;
}
body * {
color: # !important;
border-color: # !important;
}
@page {
margin: ${pageMargin}
}
#dom-content-for-print-printutils{
display: block
}
}
.icon {
margin-left: 11px;
font-size: 18px;
color: #32c5d2;
font-weight: ;
cursor: pointer;
}
.hr {
width: %;
color: #f5f5f5;
}
.inputCenter {
position: relative;
top: 20px;
}
.contractPreview {
margin: 0px auto;
width: %;
border: none;
position: relative;
z-index: ;
overflow: hidden;
}
return PrintUtils.firefoxStyleString;
}
JS中FireFox新开窗口预览打印处理的方式的更多相关文章
- Vue.js 3.0 新特性预览
总结起来,Vue 3 以下方面值得我们期待 : 更快 更小 更易于维护 更多的原生支持 更易于开发使用 完整的PPT:docs.google.com/presentatio… Evan 和 Vue 团 ...
- 基于Three.js的360X180度全景图预览插件
基于Three.js的360X180度全景图预览插件 时间 2015-08-12 10:01:10 HTML5中国 原文 http://www.html5cn.org/article-8621-1 ...
- js实现图片上传预览及进度条
原文js实现图片上传预览及进度条 最近在做图片上传的时候,由于产品设计的比较fashion,上网找了比较久还没有现成的,因此自己做了一个,实现的功能如下: 1:去除浏览器<input type= ...
- js实现移动端图片预览:手势缩放, 手势拖动,双击放大...
.katex { display: block; text-align: center; white-space: nowrap; } .katex-display > .katex > ...
- C# 9.0 新特性预览 - 类型推导的 new
C# 9.0 新特性预览 - 类型推导的 new 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章将向大 ...
- C# 9.0 新特性预览 - 空参数校验
C# 9.0 新特性预览 - 空参数校验 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章将向大家展示它 ...
- C# 9.0 新特性预览 - 顶级语句
C# 9.0 新特性预览 - 顶级语句 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章将向大家展示它们 ...
- C# 9.0 新特性预览 - init-only 属性
C# 9.0 新特性预览 - init-only 属性 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章 ...
- 20天等待,申请终于通过,安装和体验IntelliJ IDEA新UI预览版
欢迎访问我的GitHub 这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos 关于IDEA的预览版 IDEA会启用新的UI,这事情之 ...
随机推荐
- 3 触发器报警-->远程执行命令
0.需求 上节课我们讲了,触发器报警,发送邮件,这节课主要讲下远程执行命令 流程图如下 item--> triggers-->action--->Email |——>远 ...
- HDU 6040 - Hints of sd0061 | 2017 Multi-University Training Contest 1
/* HDU 6040 - Hints of sd0061 [ 第k小数查询,剪枝 ] 题意: 给出随机数列 a[N] (N < 1e7) 询问 b[M] (M < 100) ,对于每个询 ...
- 【Winfrom-禁止重复启动程序】 程序不能重复启动
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Sy ...
- ubuntu 添加字体
1. 下载自己需要安装的字体文件 eg: yaheiconsolashybrid.ttf 2. 将字体文件放在目录/home下 3. 到目录/usr/share/fonts/truetype/下建立目 ...
- 【Python之路】特别篇--Bottle
Bottle Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除了Python的标准库外,其不依赖任何其他模块. Bottle框架大致可以分为以下部分 ...
- Gym 100971A Treasure Island BFS 思维题
A - Treasure Island Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64 ...
- android自定义键盘(解决弹出提示的字体颜色问题)
最近准备要做一个项目,需要用到自定义小键盘来确保安全,而且还需要精确获得用户点击键盘时的落点位置.力度.指尖接触屏幕的面积等参数. 在写自定义键盘的时候,用到了国内网上的一些代码,出处是 向先人致敬! ...
- [笔记]共享内存(shm)
一.特点 共享内存允许多个不同的进程可以访问同一块内存.相较于其他IPC形式,具有速度快,效率高的特点,共享内存的存在降低了在大规模数据处理过程中内存的消耗. 二.创建共享内存 1.头文件 #incl ...
- Spring之Bean管理------注解方式
编写测试类 1,编写相关的类 public interface UserDao { public void sayHello(); } public class UserDaoImpl impleme ...
- The remote system refused the connection.
使用SecureCRT连接Ubuntu时,报错: The remote system refused the connection. 说明Ubuntu上没有安装openssh-server,使用命令: ...