欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JavaScript代碼生成PDF文件的方法

 更新時間:2016年02月26日 11:09:18   投稿:mrr  
如何使用js生成pdf文件呢,下面通過本文給大家分享JavaScript代碼生成PDF文件的方法,需要的朋友參考下吧

如何使用js生成pdf文件呢?相信很多朋友都被這一問題迷惑著,下面由腳本之家小編通過本文給大家簡單介紹下。

可以使用javascript生成PDF的類庫–jsPDF,先下載jsPDF-0.9.0rc2下載地址:;請點這里 ,以下是完整實例代碼:

<!doctype>
<html>
<head>
<title>jsPDF</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<script type="text/javascript" src="js/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="../jspdf.js"></script> 
</head> 
<body>
<iframe frameborder="0" width="500" height="400"></iframe>
<script>
$(document).ready(function() {
var pdf = new jsPDF('p','in','letter')
, sizes = [12, 16, 20]
, fonts = [['Times','Roman'],['Helvetica',''], ['Times','Italic']]
, font, size, lines
, margin = 0.5 // inches on a 8.5 x 11 inch sheet.
, verticalOffset = margin
, loremipsum = ' ipsum dolor sit amet, consectetur adipiscing elit. Phasellus id eros turpis. Vivamus tempor urna vitae sapien mollis molestie. Vestibulum in lectus non enim bibendum laoreet at at libero. Etiam malesuada erat sed sem blandit in varius orci porttitor. Sed at sapien urna. Fusce augue ipsum, molestie et adipiscing at, varius quis enim. Morbi sed magna est, vel vestibulum urna. Sed tempor ipsum vel mi pretium at elementum urna tempor. Nulla faucibus consectetur felis, elementum venenatis mi mollis gravida. Aliquam mi ante, accumsan eu tempus vitae, viverra quis justo.\n\nProin feugiat augue in augue rhoncus eu cursus tellus laoreet. Pellentesque eu sapien at diam porttitor venenatis nec vitae velit. Donec ultrices volutpat lectus eget vehicula. Nam eu erat mi, in pulvinar eros. Mauris viverra porta orci, et vehicula lectus sagittis id. Nullam at magna vitae nunc fringilla posuere. Duis volutpat malesuada ornare. Nulla in eros metus. Vivamus a posuere libero.'
// Margins:
pdf.setDrawColor(0, 255, 0)
.setLineWidth(1/72)
.line(margin, margin, margin, 11 - margin)
.line(8.5 - margin, margin, 8.5-margin, 11-margin)
// the 3 blocks of text
for (var i in fonts){
if (fonts.hasOwnProperty(i)) {
font = fonts[i]
size = sizes[i]
lines = pdf.setFont(font[0], font[1])
.setFontSize(size)
.splitTextToSize(loremipsum, 7.5)
// Don't want to preset font, size to calculate the lines?
// .splitTextToSize(text, maxsize, options)
// allows you to pass an object with any of the following:
// {
// 'fontSize': 12
// , 'fontStyle': 'Italic'
// , 'fontName': 'Times'
// }
// Without these, .splitTextToSize will use current / default
// font Family, Style, Size.
//console.log(lines);
pdf.text(0.5, verticalOffset + size / 72, lines)
verticalOffset += (lines.length + 0.5) * size / 72
}
}
var string = pdf.output('datauristring');
$('iframe').attr('src', string);
});
</script>
</body>
</html>

以上內(nèi)容給大家介紹了JavaScript代碼生成PDF文件的方法,希望對大家有所幫助!

相關(guān)文章

  • Bootstrap每天必學(xué)之級聯(lián)下拉菜單

    Bootstrap每天必學(xué)之級聯(lián)下拉菜單

    Bootstrap每天必學(xué)之級聯(lián)下拉菜單,主要應(yīng)用場合有省市級關(guān)聯(lián)菜單等,感興趣的小伙伴們可以參考一下
    2016-03-03
  • VsCode插件自動生成注釋插件koroFileHeader使用教程

    VsCode插件自動生成注釋插件koroFileHeader使用教程

    這篇文章主要介紹了VsCode插件自動生成注釋插件koroFileHeader使用教程,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-01-01
  • JavaScript驗證知識整理

    JavaScript驗證知識整理

    本文主要介紹了JavaScript驗證的相關(guān)知識整理。具有很好的參考價值。下面跟著小編一起來看下吧
    2017-03-03
  • Swiper 4.x 使用方法(移動端網(wǎng)站的內(nèi)容觸摸滑動)

    Swiper 4.x 使用方法(移動端網(wǎng)站的內(nèi)容觸摸滑動)

    Swiper是純javascript打造的滑動特效插件,面向手機、平板電腦等移動終端,這里為大家簡單介紹一下Swiper4的用法,需要的朋友可以參考下
    2018-05-05
  • Web表單提交之disabled問題js解決方法

    Web表單提交之disabled問題js解決方法

    這篇文章主要介紹了Web表單提交之disabled問題js解決方法,分析了通過js解決保存值也能保留用戶不能輸入的功能,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-01-01
  • js特殊字符過濾的示例代碼

    js特殊字符過濾的示例代碼

    本篇文章主要是對js特殊字符過濾的示例代碼進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助
    2014-03-03
  • ES6深入理解之“l(fā)et”能替代”var“嗎?

    ES6深入理解之“l(fā)et”能替代”var“嗎?

    這篇文章主要介紹了關(guān)于ES6之"let"能替代"var"的相關(guān)資料,文中介紹的非常詳細,對大家具有一定的參考學(xué)習(xí)價值,需要的朋友們下面跟著小編一起來學(xué)習(xí)學(xué)習(xí)吧。
    2017-06-06
  • 微信小程序?qū)崿F(xiàn)二維碼簽到考勤系統(tǒng)

    微信小程序?qū)崿F(xiàn)二維碼簽到考勤系統(tǒng)

    這篇文章主要介紹了微信小程序?qū)崿F(xiàn)二維碼簽到考勤系統(tǒng),本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-01-01
  • JavaScript給事件委托批量添加事件監(jiān)聽詳細流程

    JavaScript給事件委托批量添加事件監(jiān)聽詳細流程

    事件委托,一般來講,會把一個或者一組元素的事件委托到它的父層或者更外層元素上,真正綁定事件的是外層元素,當(dāng)事件響應(yīng)到需要綁定的元素上時,會通過事件冒泡機制從而觸發(fā)它的外層元素的綁定事件上,然后在外層元素上去執(zhí)行函數(shù)
    2021-10-10
  • Js實現(xiàn)滾動變色的文字效果

    Js實現(xiàn)滾動變色的文字效果

    滾動變色的文字js特效,可看到文字在交替變色顯示,以吸引人的注意,效果真心不錯哦,需要的朋友可以參考下
    2014-06-06

最新評論