Toq*_*uis 6 javascript php pdf moodle
我想要一个链接,当点击它时,会自动开始下载网页的可打印版本。
我正在使用 Moodle。我想要的内容完全相同如果我使用 ctrl + p 下载页面并保存为 pdf 或使用
<a href=\"whatever.htm\" onClick=\"window.print();return false\">Download web page</a>
Run Code Online (Sandbox Code Playgroud)
I want exactly that content because using this way, the header, sidebar and footer is removed. I don't want css.
I'm not using this because this doesn't work in some browsers.
I'd rather not using pdf libraries like tcpdf because Moodle loads the content in a dynamic way and send this to a libraries like that is a mess.
I tried using sites like pdfcrowd.com but this kind of sites don't work when the site you want to convert to pdf uses a server-side session to identify the user.
**使用 jsPDF 的方法很简单,非常简单,只需使用 JSpdf 库即可 **
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
function onClick() {
var pdf = new jsPDF('p', 'pt', 'letter');
pdf.canvas.height = 72 * 11;
pdf.canvas.width = 72 * 8.5;
pdf.fromHTML(document.body);
pdf.save('test.pdf');
};
var element = document.getElementById("clickbind");
element.addEventListener("click", onClick);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
32368 次 |
| 最近记录: |