1

I'm trying to take a generated html file and convert it to PDF on the fly with PHP. It's going on my localhost and staying there so for the PDF conversion I'm using a Mac OSX utility, I guess you would call it.

The terminal command being:

/System/Library/Printers/Libraries/convert -f temporary.html -o destination/final.pdf

This works properly via terminal (produces a simple 20kb PDF file); however, when I run it inside PHP via passthru() the file (final.pdf) is created though it is a Zero KB file (corrupt).

The /destination folder is CHMOD 777, temporary.html is CHMOD 755.

Any help would be greatly appreciated.

Edit (Additional Detail): Now in the error log, amongst the debug lines there is an error of "ERROR: xhtmltopdf (PID 13204) crashed on signal 6!"

Jeff Andersen
  • 332
  • 8
  • 14
  • 1
    It's clear it's not a permissions issue since the file gets created. Does php show any error in its (or apache's) log file? Maybe the temporary html isn't accessible, for instance. – Dan Mar 02 '11 at 02:20
  • There are only references to a missing favicon. //Edit: Now there is an error after running a few more times: "xhtmltopdf (PID 13165) crashed on signal 6" – Jeff Andersen Mar 02 '11 at 02:23
  • is your path to the source html correct? you might need to provide a full absolute path, depending on where your php script is. – Ben Mar 02 '11 at 02:49
  • 2
    The conversion likely uses Quartz, which means you need a windowserver connection. So, you either need to run `convert` as the logged-in user, or use something else to convert HTML to PDF (perhaps http://code.google.com/p/wkhtmltopdf/ ?) – Nicholas Riley Mar 02 '11 at 02:51
  • @Nicholas. That should be placed as an answer – Ben Mar 02 '11 at 23:44
  • never really sure what to do when the question is underspecified... – Nicholas Riley Mar 03 '11 at 03:43

2 Answers2

0

When I need convert HTML in PDF I use this very nice software: http://www.princexml.com

You could have a look, it's free for personal use.

Steve
  • 355
  • 3
  • 8
0

I like to share what I do to generate PDF file on the fly. We use UNIX server to host.

I use tcpdf - a php library to convert HTML to PDF file. I use it in my projects and it works very well. TCPDF supports css, javascript, forms, images and lot more.

Website: http://www.tcpdf.org/

Demos: http://www.tcpdf.org/examples.php

Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70