当前位置: 首页 > news >正文

html导出pdf

index.vue

<template><div class="app"><el-button type="primary" size="small" @click="exportPDF">导出pdf</el-button><h1>导出PDF进度:{{ progress }}</h1><vue-html2pdf:show-layout="controlValue.showLayout":float-layout="controlValue.floatLayout":enable-download="controlValue.enableDownload":preview-modal="controlValue.previewModal":filename="controlValue.filename":paginate-elements-by-height="controlValue.paginateElementsByHeight":pdf-quality="controlValue.pdfQuality":pdf-format="controlValue.pdfFormat":pdf-orientation="controlValue.pdfOrientation":pdf-content-width="controlValue.pdfContentWidth":manual-pagination="controlValue.manualPagination":html-to-pdf-options="htmlToPdfOptions"@progress="onProgress($event)"@hasDownloaded="hasDownloaded($event)"ref="html2Pdf"><pdf-content @domRendered="domRendered()" slot="pdf-content" /></vue-html2pdf></div>
</template><script>
import VueHtml2pdf from "vue-html2pdf";
import PdfContent from "./PdfContent.vue";
export default {components: {VueHtml2pdf,PdfContent,},data() {return {controlValue: {showLayout: true,floatLayout: true,enableDownload: true,previewModal: false,paginateElementsByHeight: 300,manualPagination: true,filename: "嘻嘻哈",pdfQuality: 2,pdfFormat: "a4",pdfOrientation: "portrait",pdfContentWidth: "800px",},progress: 0,};},computed: {htmlToPdfOptions() {return {margin: 0,filename: "嘻嘻哈.pdf",image: {type: "jpeg",quality: 0.98,},enableLinks: true,html2canvas: {scale: this.controlValue.pdfQuality,useCORS: true,},jsPDF: {unit: "in",format: this.controlValue.pdfFormat,orientation: this.controlValue.pdfOrientation,},};},},methods: {exportPDF() {this.$refs.html2Pdf.generatePdf();},domRendered() {console.log("Dom Has Rendered");this.contentRendered = true;},onProgress(progress) {this.progress = progress;},hasDownloaded(blob) {console.log("download-->", blob);},},
};
</script><style lang="less" scoped>
/deep/.vue-html2pdf .layout-container {top: 30px !important;
}
</style>

pdfcontent.vue

<template><div class="pdf-content"><h1>测试111</h1><img src="@/assets/imgs/1.png" alt="" /><h3 class="html2pdf__page-break">表格信息</h3><div class="table-box"><el-table :data="tableData" style="width: 100%"><el-table-column prop="date" label="日期" width="180"> </el-table-column><el-table-column prop="name" label="姓名" width="180"> </el-table-column><el-table-column prop="address" label="地址"> </el-table-column></el-table></div><div class="chart-box" ref="chart_box_ref"></div><p class="html2pdf__page-break">系休息嘻嘻</p><p>这里是很多的注释内容,当做一页</p></div>
</template><script>
import * as echarts from "echarts";
export default {data() {return {tableData: [{date: "2016-05-02",name: "王小虎",address: "上海市普陀区金沙江路 1518 弄",},{date: "2016-05-04",name: "王小虎",address: "上海市普陀区金沙江路 1517 弄",},{date: "2016-05-01",name: "王小虎",address: "上海市普陀区金沙江路 1519 弄",},{date: "2016-05-03",name: "王小虎",address: "上海市普陀区金沙江路 1516 弄",},],};},mounted() {const chart = echarts.init(this.$refs.chart_box_ref);const option = {tooltip: {trigger: "axis",axisPointer: {type: "shadow",},},legend: {},xAxis: [{type: "category",data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],},],yAxis: [{type: "value",},],series: [{name: "Direct",type: "bar",emphasis: {focus: "series",},data: [320, 332, 301, 334, 390, 330, 320],},{name: "Email",type: "bar",stack: "Ad",emphasis: {focus: "series",},data: [120, 132, 101, 134, 90, 230, 210],},{name: "Union Ads",type: "bar",stack: "Ad",emphasis: {focus: "series",},data: [220, 182, 191, 234, 290, 330, 310],},],};chart.setOption(option);},
};
</script><style lang="less" scoped>
.chart-box {height: 300px;
}
</style>
http://www.jsqmd.com/news/47080/

相关文章:

  • 【第7章 I/O编程与异常】为什么句柄看起来像指针却不是指针?
  • SQL 基础语法
  • 实用指南:暖手宝方案开发,暖手宝MCU控制方案开发设计
  • NVM 与 单节点下PM2进程守护 安装配置以及使用教程完整指南(含 Node.js 环境搭建)
  • 北大六院的诊断
  • Pycharm远程连接服务器项目 - 实践
  • django项目前端模版文件,在pycahrm无法使用ctrl+alt+l格式化代码的解决办法
  • 北大六院后看又相
  • TPAMI 2025 | 从分离到融合:新一代3D场景技术建立双重能力提升!
  • 详细介绍:后端开发常用Linux命令
  • QT:Qt5.14向文档输出表格--编译异常信息
  • 《程序员修炼之道》阅读笔记5
  • java面向对象知识补充
  • 卷积神经网络的引入3 —— MLP 与 CNN 在更大数据集上的性能对比实验
  • 全网都在找的Nano Banana Pro API 来了!便宜稳定0.15/张
  • 通过DataReader获取sql查询的字段元数据信息
  • 2025.11.21 - A
  • 2025年新版ADB工具箱下载+驱动+ADB指令集+fastboot刷机ROOT程序
  • P7960 [NOIP2021] 报数__洛谷题解
  • 与括号序列相关的 DP 笔记
  • 【251121】CF2171 Div.3 vp 总结
  • OI 笑传 #32
  • PyOpenGL实现Bresenham算法
  • 【Linux】教你在 Linux 上搭建 Web 服务器,步骤清晰无门槛 - 详解
  • 【第7章 I/O编程与异常】\r\n 和 \n\r是一回事吗?
  • 深入解析:windows显示驱动开发-CCD api的摘要及方案(一)
  • nju实验七 状态机及键盘输入
  • Gephi如何支持MySQL数据的复杂查询
  • Mozilla CI日志中暴露微软x-apikey的安全事件分析
  • Gephi怎样优化MySQL数据的展示效果