HTML tables to PDF in PHP - neither DOMPDF nor html2ps/pdf are working

…衆ロ難τιáo~ 提交于 2019-12-24 20:09:50

问题


For the longest time now I've been trying to convert HTML pages containing large tables to PHP. These are styled with CSS and can be several pages long.

I first tried DOMPDF. It works great, until a document is more than one page. None of the fixes I've found work. Either it errors out, or any element that would be even partially on the second page gets lumped over the content of page 1. I've tried both the latest release and the SVN copy I checked out today.

I also tried html2ps/pdf, and it gives me "permission denied" errors writing to the cache directory, even though the directory is fully writable. The system requirements test script passes. The server is running PHP 5 under IIS (not my choice heh).

Can either of these be convinced to work, or is there a library that can do it?

Errors from the demo/test scripts:

Warning: file_put_contents(C:\Inetpub\wwwroot\JM\pdf\html2ps\cache/7d888258e9745b3716532ea81342daaf.css.compiled) [function.file-put-contents]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\JM\pdf\html2ps\css.cache.class.php on line 33

Warning: fopen(C:\Inetpub\wwwroot\JM\pdf\html2ps\cache/unicode.lb.classes.dat) [function.fopen]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\JM\pdf\html2ps\inline.content.builder.php on line 991

Warning: flock() expects parameter 1 to be resource, boolean given in C:\Inetpub\wwwroot\JM\pdf\html2ps\inline.content.builder.php on line 992

Warning: fwrite(): supplied argument is not a valid stream resource in C:\Inetpub\wwwroot\JM\pdf\html2ps\inline.content.builder.php on line 1011 (this error repeats several thousand times)

Warning: fopen(C:\Inetpub\wwwroot\JM\pdf\html2ps\cache/times.z) [function.fopen]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\JM\pdf\html2ps\pdf.fpdf.makefont.php on line 318

Can't write to file C:\Inetpub\wwwroot\JM\pdf\html2ps\cache/times.z


回答1:


A similar problem with html2pdf under IIS has been discussed here.

The solution was quite simple, yet weird. If this doesn't help you, a full error-message and / or a little bit of code would help me to help you.




回答2:


I personally recommend command line applications 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 throw errors or warnings.

  3. No support for external style sheets.

Command Line Tool:

If you run your script on a Linux server then I suggest command line tools.

Reasons :

  1. They are extremely fast 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 to Converting HTML to PDF (not PDF to HTML) using PHP.



来源:https://stackoverflow.com/questions/1280173/html-tables-to-pdf-in-php-neither-dompdf-nor-html2ps-pdf-are-working

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