Using PHP to create a PDF from a mix of plain text and HTML text [duplicate]

喜欢而已 提交于 2019-12-05 16:56:45

问题


Possible Duplicate:
Convert HTML + CSS to PDF with PHP?

I have a form with 5 fields, two of which are textboxes extended with tinyMCE, the rest are simple inputs of type text.

I need to generate a PDF from this input. I understand that I can use Zend_Pdf to generate the PDF and include the plain text data. But how, for example, can I include a bulleted list from the tinyMCE fields?

Would the best way be to create an HTML file, and then use for example DOMPDF or HTML2PDF? Ideally, I'd prefer to just use the zend framework to create the document, position and insert the fields, and save.

Thanks in advance.


回答1:


More info in Convert HTML + CSS to PDF with PHP?.

In my experience, Prince XML was the Rolls Royce of such technologies so far away and above any of the other ones it's not even funny. It's expensive though. But I had all sorts of problems with all the others.




回答2:


Some time ago I tried to use HTML to PDF conversion programs to convert... HTML to PDF, but in the end I gave up with that approach and just created the PDFs directly in code. I use fpdf (http://www.fpdf.org/) as a base and added supporting code for lists and grids etc.




回答3:


I am using Prince XML mentioned by cletus. Results are very good, even with css styled html with floats etc. It's expensive, but it just works and saves a lots of time.




回答4:


FPDF is very old library for PHP4. It propably won't even work nowadays. I'd recommend DOMPDF or TCPDF. They both are for PHP5+ and can eat HTML or CSS to some degree.




回答5:


You could convert it all to HTML and then use openoffice or some other tool (pandoc is quite nifty too) to convert from HTML to PDF.

Alternatively, you could take a look at LiveDocx, which has php-bindings too. It's a hosted service, but you can use it without charge.




回答6:


I personal recommend command line application instead of any php libraries.

Reasons :

  1. PHP libraries need more time and memory (cache) for conversion process

  2. They need well formatted html pages only, otherwise through errors or warning

  3. Not support for external style sheet.

Command Line Tool:

If run your script on Linux server then I suggest command line tool.

Reasons :

  1. They are extremely fast as compared to PHP libraries.

  2. Support css.

  3. Accept non well formatted html.

Which command line tool to use?

  1. wkhtmltopdf
  2. htmltopdf
  3. html2pdf

for more information refer Converting HTML to PDF (not PDF to HTML) using PHP



来源:https://stackoverflow.com/questions/560776/using-php-to-create-a-pdf-from-a-mix-of-plain-text-and-html-text

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