http://mrrio.github.io/

     jsPDF 是一个基于 HTML5 的客户端解决方案,用于生成各种用途的 PDF 文档。使用方法很简单,只要引入 jsPDF 库,然后调用内置的方法就可以了。浏览器兼容性: IE 10, Firefox 3+, Chrome, Safari 3+, Opera,未来将兼容 IE 10 以下版本,对于 IE10 以下的版本会使用 Downloadify 来实现文件下载功能。

1、文本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var  doc =  new  jsPDF();
 
doc.text(20, 20,  'This is the default font.' );
 
doc.setFont( "courier" );
doc.setFontType( "normal" );
doc.text(20, 30,  'This is courier normal.' );
 
doc.setFont( "times" );
doc.setFontType( "italic" );
doc.text(20, 40,  'This is times italic.' );
 
doc.setFont( "helvetica" );
doc.setFontType( "bold" );
doc.text(20, 50,  'This is helvetica bold.' );
 
doc.setFont( "courier" );
doc.setFontType( "bolditalic" );
doc.text(20, 60,  'This is courier bolditalic.' );

2、图片

1
2
3
4
5
6
7
8
9
// You'll need to make your image into a Data URL
// Use http://dataurl.net/#dataurlmaker
var  imgData = 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4ge....../2Q== ';
 
var doc = new jsPDF();
 
doc.setFontSize(40);
doc.text(35, 25, "Octonyan loves jsPDF");
doc.addImage(imgData, ' JPEG', 15, 40, 180, 180);

3、HTML

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var  doc =  new  jsPDF();
 
// We'll make our own renderer to skip this editor
var  specialElementHandlers = {
     ' #editor': function(element, renderer){
         return  true ;
     }
};
 
// All units are in the set measurement for the document
// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
doc.fromHTML($(' #render_me').get(0), 15, 15, {
     'width ': 170,
     ' elementHandlers': specialElementHandlers
});

插件下载:http://www.jq22.com/jquery-info517

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值