javascript 将 div 的内容导出为 PDF

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21809290/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 21:44:17  来源:igfitidea点击:

Exporting a div's content to PDF

javascriptphpjquerypdfhtml

提问by gogo_rulez

I know that there are a number of points regarding this question, but I just can't find what I'm looking for so I hope someone can answer me. So, what I'm trying to do is:

我知道关于这个问题有很多观点,但我找不到我要找的东西,所以我希望有人能回答我。所以,我想做的是:

imagine you have a div that is 400 X 400 px. The user uploads an image and enters text via input[type="text"] and all of it is shown inside that div. I want to export all of the content of that div in a PDF, possibliy by JavaScript (jQuery) od PHP. What would be the best way to do it?

假设您有一个 400 X 400 像素的 div。用户上传图像并通过 input[type="text"] 输入文本,所有内容都显示在该 div 中。我想通过 JavaScript (jQuery) od PHP 以 PDF 格式导出该 div 的所有内容。最好的方法是什么?

If anyone could show a small example (code), I would appreciate it!

如果有人可以展示一个小例子(代码),我将不胜感激!

采纳答案by Vahid Taghizadeh

回答by Baptiste Donaux

You can generate a PDF since a HTML page, with the WeasyPrintpackage. It's very easy to use and its most speed that javascript.

您可以使用WeasyPrint包从 HTML 页面生成 PDF 。它非常易于使用,而且速度最快是 javascript。

回答by michael.zech

Maybe you could combine the PHP-Printer functions-api (http://www.php.net/manual/en/book.printer.php) with a software like, for example, PDF-Creator (http://sourceforge.net/projects/pdfcreator/). But this would imply that PDF-Creator is installed on the system of the user.

也许您可以将 PHP-Printer functions-api ( http://www.php.net/manual/en/book.printer.php) 与诸如 PDF-Creator ( http://sourceforge.pdf) 之类的软件结合使用。净/项目/pdfcreator/)。但这意味着 PDF-Creator 安装在用户的系统上。

It's just a general idea ...

这只是一个普遍的想法......