pdf在线查看 html代码,PDF网页在线阅读器pdfjs

pdfjs是PDF网页在线阅读器,直接本地或远程加载PDF,设置输出文本字体、自适应页面显示、自定义头部底部显示。

b3ccde1337c14a1a59f336ccfdeb8886.png

var doc = new pdfjs.Document({

font: assets.openSansRegular

})

var tr, td, text

var header = doc.header()

table = header.table({ widths: ['50%', '50%']})

tr = table.tr()

tr.td('pdfjs', { font: assets.openSansBold })

tr.td('github.com/rkusa/pdfjs', { font: assets.openSansLight, textAlign: 'right' })

var footer = doc.footer()

footer.text({ textAlign: 'center' }).pageNumber().append('/').pageCount()

doc.image(assets.logo, { width: 128 })

text = doc.text({

fontSize: 14, lineSpacing: 1.35

})

text.add('Content can be composed of')

text.add('different', { font: assets.openSansBold })

text.add('fonts', { font: assets.sourceCodeProMedium })

text.add('and')

text.add('different', { fontSize: 10 })

text.add('sizes', { fontSize: 18 })

text.add('.')

var lorem = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cum id fugiunt, re eadem quae Peripatetici, verba. Tenesne igitur, inquam, Hieronymus Rhodius quid dicat esse summum bonum, quo putet omnia referri oportere? Quia nec honesto quic quam honestius nec turpi turpius.'

doc.text(new Array(2).join(lorem + '\n\n'), {

fontSize: 14, lineSpacing: 1.35, textAlign: 'justify', color: 0xdddddd

})

table = doc.table({

headerRows: 1, fontSize: 14,

borderHorizontalWidth: 0.1,

widths: ['10%', '10%', '50%', '15%', '15%']

})

tr = table.tr({ font: assets.openSansBold, borderBottomWidth: 1.5 })

tr.td('#')

tr.td('Unit')

tr.td('Subject')

tr.td('Price')

tr.td('Total')

var rows = [

{

quantity: 2,

name: 'Article A',

description: lorem,

price: 500

},

{

quantity: 1,

name: 'Article B',

description: lorem,

price: 250

},

{

quantity: 3,

name: 'Article C',

description: lorem,

price: 750

}

]

rows.forEach(function(row) {

tr = table.tr()

tr.td(row.quantity)

tr.td('pc.')

var article = tr.td().text()

article.add(row.name, { fontSize: 14, font: assets.openSansBold })

.br()

.add(lorem, { fontSize: 11, textAlign: 'justify' })

tr.td(row.price.toFixed(2) + ' €', { textAlign: 'right' })

tr.td((row.price * row.quantity).toFixed(2) + ' €', { textAlign: 'right' })

})

var pdf = doc.render()

document.querySelector('#preview').setAttribute('src', pdf.toDataURL())

相关链接

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值