Technology sharing

printJS instruments imprimendi imagines et pdf

2024-07-12

한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina

Download clientelas

NPM install print-js --save
inducere

import printJS from 'print-js'

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

Modus printFnc in duobus parametris transit, inscriptionis fasciculi et fasciculi typus

  1. printFnc(url, filetype) {
  2. let path = url
  3. let type = ''
  4. const acceptedFileTypes = ['png', 'jpeg', 'jpg', 'gif']
  5. if (acceptedFileTypes.includes(filetype)) {
  6. type = 'image'
  7. } else {
  8. type = filetype
  9. }
  10. printJS({
  11. printable: path,
  12. type: type,
  13. // showModal: true,//开启加载modal
  14. onErrorL: (err) => {
  15. return this.$message({
  16. type: "error",
  17. message: '打印失败,请检查打印机设置或尝试保存文件!'
  18. })
  19. }
  20. })
  21. },