views:

1853

answers:

2

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

A: 

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.

HTH, flokra

flokra
That seems to refer to an older version. The version I have doesn't use that directory; it has the cache directory in the same place as its others (alongside classes, demo, etc). Even the demo/test scripts fail, with any URL.I'll have to update my post with the errors as it's too long for a comment.
If there are any files left in the cache directory, did you try to empty it? html2pdf does not handle "left-overs" very well.
flokra
Only the readme.txt that came with it. Removing that didn't help. Is it possible the directory is not writable even though my FTP client claims it is (attribute 666)?
Since you're (forced) to use windows, you might want to check the properties of the directory. Check, that the user in which context the webserver is run has "Full Controll" in the "Security"-Tab of the folders properties. It should look similar to the settings of "Internet Guest Account" in this picture: http://tinyurl.com/pdtzkq
flokra
Apparently I don't have sufficient privilege to do this, so I changed the cache directory in config.inc.php, line 115:define('CACHE_DIR', sys_get_temp_dir());That seems to have done it.
A: 

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 http://stackoverflow.com/questions/1403820/html-to-pdf-not-pdf-to-html-in-php

santosh