Jspdf是一个将html内容生成pdf文件的库,原理是对输入浏览器的文字或二进制图片进行base64编码转换,以pdf中应有的形式组织,最终以data uri scheme,
data:application/pdf;base64;[content] 的格式输出
里面的save方法是如何做到浏览器端保存文件的呢?
看下这个:
<a href="data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAHsAAAAyCAIAAADz8jOMAAAAmklEQVR42u3QQQoAIQgAQP//aRc2NsQ8xJ7HQ2hkykS8kZnrXMm+3GV+Ue9r0lqyxFmOE9vLlo9za+P9kq1rzMe590uOH8Y5njhx4sSJEydOnDhx4sSJEydOnDhx4sSJEydOnDhx4sSJEydOnDhx4sSJEydOnDhx4sSJEydOnDhx4sSJEydOnDhx4sSJEydOnDhx4sSJE/8t/gBbNfIWdjsEtgAAAABJRU5ErkJggg==" download="文件名">A标签</a>
通过给href属性添加data uri scheme,给download属性添加文件名称,点击时就能下载。