You would probably want to use PHP to build the PDF. Not sure if there are any javascript libraries out there to do such a thing. As @Sn0opy said, this could become a server problem though if many people are generating PDFs (especially if they are large).
There are a number of PDF builders for PHP out there. I've used html2ps and tcpdf both with success.
Read about limitations and if they are too much for your project use PHP like people advised.
If you know that the client has flash/acrobat plugin installed you can use them on the client to generate PDFs, look here for details: http://www.adobe.com/devnet/acrobat.html
发布评论
评论(6)
您可能希望使用 PHP 来构建 PDF。
不确定是否有任何 javascript 库可以做这样的事情。正如 @Sn0opy 所说,如果很多人生成 PDF(特别是当它们很大时),这可能会成为服务器问题。有许多适用于 PHP 的 PDF 生成器。我已经成功使用了 html2ps 和 tcpdf 。
You would probably want to use PHP to build the PDF.
Not sure if there are any javascript libraries out there to do such a thing.As @Sn0opy said, this could become a server problem though if many people are generating PDFs (especially if they are large).There are a number of PDF builders for PHP out there. I've used html2ps and tcpdf both with success.
有几种纯js解决方案,但它们不是很可靠,不能在所有浏览器中工作。您可以在这里查看:
http://andreasgal.com/2011/06/15 /pdf-js/
这是他们很酷的例子:
http://mozilla.github.com/pdf.js/web/viewer.html
还有这个项目:
http://code.google.com/p/jspdf/
了解限制以及是否存在限制对于您的项目来说,像人们建议的那样使用 PHP 太多了。
如果您知道客户端安装了flash/acrobat插件,您可以在客户端上使用它们来生成PDF,详细信息请看这里:
http://www.adobe.com/devnet/acrobat.html
There are several pure js solutions, but they are not very reliable, don't work in all browsers. You can take a look here:
http://andreasgal.com/2011/06/15/pdf-js/
here is their cool example:
http://mozilla.github.com/pdf.js/web/viewer.html
There is also this project:
http://code.google.com/p/jspdf/
Read about limitations and if they are too much for your project use PHP like people advised.
If you know that the client has flash/acrobat plugin installed you can use them on the client to generate PDFs, look here for details:
http://www.adobe.com/devnet/acrobat.html
我非常喜欢这个 php: html2pdf
I like a lot this one for php: html2pdf
以下是 PHP 中 PDF 扩展的 PHP 手册条目:
http://php.net/manual /en/book.pdf.php
此外,本文准确展示了在 PHP 中生成 PDF 所需执行的操作:
http://www.sitepoint.com/generate-pdfs-php/
Here's the PHP manual entry for the PDF extension in PHP:
http://php.net/manual/en/book.pdf.php
Also, this article shows exactly what you need to do to generate a PDF in PHP:
http://www.sitepoint.com/generate-pdfs-php/
我更喜欢 mPDF 生成 PDF:
您可以使用 PHP 生成 PDF 并通过 AJAX 获取它打电话,这是唯一的好办法。当然,在 mPDF 中您可以使用 CSS 设计文档样式。
如果您想使用 javascript 阅读 PDF,请阅读:开源 Javascript PDF 查看器
编辑:现在已经是 2016 年了,mPDF 肯定是不推荐的、已弃用的软件。还有很多更好的,只需看看 GitHub:
PHP: https://github.com/search?l=PHP&o=desc&q=pdf&ref=searchresults&s=stars&type=Repositories&utf8=%E2%9C%93
JavaScript :<一href="https://github.com/search?utf8=%E2%9C%93&q=node+pdf&type=Repositories&ref=searchresults" rel="nofollow noreferrer">https://github.com /search?utf8=%E2%9C%93&q=node+pdf&type=Repositories&ref=searchresults
I prefer mPDF to generate PDFs:
You can generate the PDF using PHP and grab it by doing an AJAX call, that's the only good way. Of course in mPDF you can style document using CSS.
If you want read PDF using javascript, read: Open Source Javascript PDF viewer
edit: now it's 2016 and mPDF is for sure not recommended, deprecated piece of software. There exists much better ones, just take a look at GitHub:
PHP: https://github.com/search?l=PHP&o=desc&q=pdf&ref=searchresults&s=stars&type=Repositories&utf8=%E2%9C%93
JavaScript: https://github.com/search?utf8=%E2%9C%93&q=node+pdf&type=Repositories&ref=searchresults
如果您需要精确的格式,请查看 DocRaptor。它们是围绕 Prince XML 构建的 SaaS。
https://docraptor.com/
这是一个使用 PHP 的示例(不过输出到 Excel 电子表格而不是 PDF)
< a href="https://docraptor.com/documentation#php_example" rel="nofollow">https://docraptor.com/documentation#php_example
Check out DocRaptor if you need the formatting to be precise. They are a SaaS built around Prince XML.
https://docraptor.com/
Here's an example using PHP (outputting to an excel spreadsheet instead of a PDF though)
https://docraptor.com/documentation#php_example