Blame view

admin-web-master/src/views/activity/activityHis -副本1.vue 1.72 KB
2d521f7d   杨鑫   最新2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  <template>
  	<div>
  		<div ref="contentToConvert">
  		  <div>这个是活动方案1</div>
  		  <div>这个是活动方案2</div>
  		  <div>这个是活动方案3</div>
  		  <div>这个是活动方案4</div>
  		  <div>这个是活动方案5</div>
  		  <div>这个是活动方案6</div>
  		  <div>这个是活动方案6</div>
  		</div>
  		<el-button @click="gitOut" style="background-color: #3F9B6A;color: #fff;margin-top:50px">导出
  		</el-button>
  	</div>
  </template>
  
  <script>
  	import html2canvas from 'html2canvas'
  	import jsPDF from 'jspdf'
  	export default {
  		data() {
  			return {
  				
  			}
  		},
  		computed: {},
  		created() {
  		
  		},
  		mounted() {
  
  		},
  		methods: {
  			 gitOut() {
  				const content = this.$refs.contentToConvert;
  				setTimeout(function() {
  				     /* html2canvas 1.0.5 版本 */
  					 
  				   html2canvas(content).then(canvas => {
  				        // 获取画布的图像数据
  				        const imgData = canvas.toDataURL('image/png');
  				        			
  				        // 创建一个新的 PDF 文档
  				        const pdf = new jsPDF('p', 'mm', 'a4');
  				        			
  				        // 添加图像到 PDF,第二个参数是图像格式,第三个参数是缩放比例
  				        const imgWidth = 190; // 图像的宽度(mm)
  				        const imgHeight = (canvas.height * imgWidth) / canvas.width; // 保持图像的宽高比
  				        			
  				        pdf.addImage(imgData, 'PNG', 10, 10, imgWidth, imgHeight); // 10, 10 是图像在 PDF 中的位置(mm)
  				        			
  				        // 保存 PDF 文件
  				        pdf.save('downloaded.pdf');
  				   })
  				   
  				}, 500);
  				
  			
  				// 使用 html2canvas 将 div 渲染为画布
  				// const canvas = await html2canvas(content);
  			
  				
  			},
  		}
  	}
  </script>
  
  <style scoped>
  	
  </style>