vue里面实现打印功能

安装依赖


// vue3 安装
npm install vue3-print-nb
// 或
yarn add vue3-print-nb
 
// vue2 安装
npm install vue-print-nb
// 或
yarn add vue-print-nb

在mian.js引用

import Print from 'vue3-print-nb'
app.use(Print)

页面使用

<el-button type="danger" v-print="'print'">
            打印 
</el-button>
 <div id="print">
  模板内容
 </div>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现pdf打印功能需要以下步骤: 1. 在Spring Boot中使用PDFBox或iText等库生成PDF文件。 2. 将生成的PDF文件保存到服务器上。 3. 在Vue中使用pdf.js或其他库加载服务器上的PDF文件。 4. 在Vue中使用window.print()方法打印PDF文件。 以下是具体的实现步骤: 1. 在Spring Boot中使用PDFBox或iText等库生成PDF文件 以PDFBox为例,可以使用以下代码生成PDF文件: ```java PDDocument document = new PDDocument(); PDPage page = new PDPage(); document.addPage(page); PDPageContentStream contentStream = new PDPageContentStream(document, page); // 在页面上添加内容 contentStream.beginText(); contentStream.setFont(PDType1Font.HELVETICA_BOLD, 12); contentStream.newLineAtOffset(100, 700); contentStream.showText("Hello, World!"); contentStream.endText(); contentStream.close(); document.save("example.pdf"); document.close(); ``` 2. 将生成的PDF文件保存到服务器上 可以使用Java的文件操作方法将生成的PDF文件保存到服务器上,例如: ```java File file = new File("example.pdf"); OutputStream outputStream = new FileOutputStream(file); document.save(outputStream); outputStream.close(); ``` 3. 在Vue中使用pdf.js或其他库加载服务器上的PDF文件 可以使用pdf.js库加载服务器上的PDF文件,并在Vue组件中显示PDF文件。 ```html <template> <div> <pdf :src="pdfFile" :page="1"></pdf> </div> </template> <script> import pdf from 'vue-pdf' export default { components: { pdf }, data () { return { pdfFile: 'http://localhost:8080/example.pdf' } } } </script> ``` 4. 在Vue中使用window.print()方法打印PDF文件 可以在Vue组件中添加一个打印按钮,并在点击时调用window.print()方法打印PDF文件。 ```html <template> <div> <pdf :src="pdfFile" :page="1"></pdf> <button @click="printPDF">Print</button> </div> </template> <script> import pdf from 'vue-pdf' export default { components: { pdf }, data () { return { pdfFile: 'http://localhost:8080/example.pdf' } }, methods: { printPDF () { window.print() } } } </script> ``` 这样就可以实现Spring Boot和Vue中的PDF打印功能了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值