欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 文化 > printJS实现打印图片和pdf

printJS实现打印图片和pdf

2025/3/19 13:47:55 来源:https://blog.csdn.net/weixin_46631078/article/details/140238338  浏览:    关键词:printJS实现打印图片和pdf

下载依赖

npm install print-js --save
引入

import printJS from 'print-js'

<el-dialog title="提示" :visible.sync="dialogVisible" width="30%" :before-close="handleClose"><span slot="footer" class="dialog-footer"><span>{{ form.address }}</span><span>{{ form.name }}</span><span>{{ form.password }}</span><el-button @click="dialogVisible = false">取 消</el-button><el-button type="primary" @click="dialogVisible = false">确 定</el-button><el-button type="primary" @click="share(form)">复制</el-button><el-button type="primary"@click="printFnc('https://inews.gtimg.com/om_bt/OGlQWfsaAoKkuCcMZ2o9IVEPqd-72DQy5EAN02XBHUwfYAA/641', 'jpeg')">打印</el-button></span></el-dialog>

printFnc方法传入两个参数,文件地址和文件类型

 printFnc(url, filetype) {let path = urllet type = ''const acceptedFileTypes = ['png', 'jpeg', 'jpg', 'gif']if (acceptedFileTypes.includes(filetype)) {type = 'image'} else {type = filetype}printJS({printable: path,type: type,// showModal: true,//开启加载modalonErrorL: (err) => {return this.$message({type: "error",message: '打印失败,请检查打印机设置或尝试保存文件!'})}})},

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词