mind-map/simple-mind-map/src/plugins/ExportPDF.js

39 lines
930 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import JsPDF from '../utils/jspdf'
// 导出PDF插件需要通过Export插件使用
class ExportPDF {
// 构造函数
constructor(opt) {
this.mindMap = opt.mindMap
}
// 导出为pdf
async pdf(name, img) {
return new Promise((resolve, reject) => {
const image = new Image()
image.onload = () => {
const imageWidth = image.width
const imageHeight = image.height
const pdf = new JsPDF({
unit: 'px',
format: [imageWidth, imageHeight],
compress: true,
hotfixes: ['px_scaling'],
orientation: imageWidth > imageHeight ? 'landscape' : 'portrait'
})
pdf.addImage(img, 'PNG', 0, 0, imageWidth, imageHeight)
pdf.save(name)
resolve()
}
image.onerror = e => {
reject(e)
}
image.src = img
})
}
}
ExportPDF.instanceName = 'doExportPDF'
export default ExportPDF