从html dom创建可打印的PDF [英] Create printable PDF from html dom

查看:163
本文介绍了从html dom创建可打印的PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,其中有相当数量的内容是动态建立的(jQuery ajax等),并且需要提供它的可打印版本。


I我遇到了所有关于HTML /打印的常见问题,我可能会(在给定时间内)绕过这些问题,但这让我想到了 - 是否有一种方法可以采用DOM并使用JavaScript生成PDF。这可能是一个愚蠢的问题 - 听起来有点棘手,即使我可以使用JavaScript构建一个PDF文件,我也不太确定,然后我将如何呈现给用户。 />人们会怎么想?

I have a web page in which a fair amount of the content is dynamically built up (jquery ajax etc) and have a requirement to present a printable version of it.

I'm coming across all the usual issues re html / printing, which I can probably (given time) get round, but it got me thinking - is there a way of taking the DOM and generating a PDF out of it using javascript. It's probably a bit of a daft question - it sounds a bit tricky, and I'm not too sure even if I could build up a PDF file using javascript, how I would then present it to the user.

What do people think?

推荐答案

var doc = new jsPDF();
doc.text(20, 20, 'Hello world!');
doc.text(20, 30, 'This is client-side Javascript, pumping out a PDF.');
doc.addPage();
doc.text(20, 20, 'Do you like that?');
// Output as Data URI
doc.output('datauri');

https://parall.ax/products/jspdf ,我想这会帮助你

这篇关于从html dom创建可打印的PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆