Generate PDF file from HTML page while on shared hosting

心已入冬 提交于 2020-01-02 05:50:15

问题


I have very limited access to enable extensions etc on my hosting but am looking to generate a PDF from an HTML page (with css/images) through PHP.

Any ideas how I can achieve this with next to zero CL access etc? Preferable not a "hack" / relient on a service (as I'll be looking to use this long term).


回答1:


When generating HTML to render in to the PDF, create that HTML in single $html variable. This can be used to pass to the any of the pdf rendering api's.

Widely used API's are DOM PDF, html2pdf, html2ps.

Some of the API's like html2ps also supports the external css & classes also. Some required inline CSS.

I have used DOM PDF & html2ps

here are the links

domp df

HTML2PS & HTML2PDF




回答2:


A number of solutions exist out there: domPdf, mPdf, html2pdf, tcpdf, zendPDF (zend framework) etc. I have used domPdf and mPDF very extensively and others just "in passing". domPdf is very easy but doesn't quite have the bells and whistles. html2pdf is not bad either, however, I am partial to mPDF as I believe it has the best set of features out there. For full documentation see this link: http://mpdf1.com/manual/index.php

I've converted pretty complicated web pages into pdf and mPDF seems to render them the best.




回答3:


Found this yesterday just here at SO: mPDF. Haven't tried it, but the documentation is solid.




回答4:


Check out html2pdf, I never used it, but it looks promising.



来源:https://stackoverflow.com/questions/3454407/generate-pdf-file-from-html-page-while-on-shared-hosting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!