mikehaertl / phpwkhtmltopdf

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface
MIT License
1.6k stars 238 forks source link

Corrupted PDF File generated using Windows wamp server #69

Closed maryglo closed 10 years ago

maryglo commented 10 years ago

Hi, I'm using laravel framework and installed on my local machine (windows OS with wamp server installed, AMD) the package together with the binary using composer. I created a test class. Please see below: use mikehaertl\wkhtmlto\Pdf; class PDFConverter {

public function __construct() {

}

public function createPDF() {
    $pdf = new Pdf('http://gmail.com/');

    $pdf->binary = base_path(). '/vendor/bin/wkhtmltopdf-amd64';
    $pdf->saveAs(base_path()."/public/documents/sample.pdf");
    //$pdf->send();
    $pdf->send('sample.pdf');
    var_dump($pdf);

}

However, the generated pdf file was 0kb and my pdf reader showed an alert with this message, "format error, not a pdf or corrupted".
 I really don't know what caused this error.

Please help. It's been weeks since I've been searching for a good package that will convert html file to pdf with too many nested tables.

  Thank you!
mikehaertl commented 10 years ago

Don't try with gmail. Try with your own HTML. I've seen pdftk having problems especially with google sites. Apart from that it's very likely that your problem comes from pdftk itself, which means: I can't fix it. This is only a wrapper class around the command line tool.

Also check the content of $pdf->getError() after you tried to save the file.

maryglo commented 10 years ago

Same thing happened, I tried $pdf = new Pdf('

hello world

'); I dumped var_dump($pdf); and here's the results, last 5 lines of the dumped variable:

protected '_stdErr' => string '' (length=0) protected '_exitCode' => int 0 protected '_error' => string '' (length=0) protected '_executed' => boolean true protected '_error' => string '' (length=0)

Which means that the exec Command was executed, and no error encountered.

Do I need to install something to make this work or I've already done the correct procedures in installing package?

mikehaertl commented 10 years ago

You should really try $pdf->getError(). The var_dump doesn't help. Also do $pdf->getCommand()->getExecCommand() to get the raw output of the shell command.

maryglo commented 10 years ago

$pdf->getError() returns string with length 0 which means no error.

mikehaertl commented 10 years ago

You should then first try, if the wkhtmltopdf-amd64 command works on the command line (forget what i said about pdftk above - i was confused with another project of mine).

maryglo commented 10 years ago

Do i need install to something in order to make ti work in the command line?

mikehaertl commented 10 years ago

Yes, please first consult the installation instructions again. You need the wkhtmltopdf binary on your systems and there are different ways to get that.

mikehaertl commented 10 years ago

I see you've changed the title and you use a WAMP server. I'm sorry, but I can not really assist you how to install wkhtmltopdf there, as I do not (and never will) use Windows for development. There are Windows executables of wkhtmltopdf and you first need to make sure, that this works. Then you need to configure the path to that .exe in the $pdf->binary property. But in principle this library also works with the windows version.

maryglo commented 10 years ago

I already installed the binary using composer, composer require h4cc/wkhtmltopdf-amd64.

Can you give me an example to be executed on the command line?

maryglo commented 10 years ago

I know how to install the binary using composer, and I installed it already, now the problem how can I test on the command line.

mikehaertl commented 10 years ago

The composer packages of wkhtmltopdf are Linux binaries. They will not run on Windows.

maryglo commented 10 years ago

Oh, are there composer package for Windows? tried the code that I did on a linux server and I got a Permission denied error to my binary file. This is the part of the code $pdf->binary = base_path(). '/vendor/bin/wkhtmltopdf-i386';

mikehaertl commented 10 years ago

I don't know, if there are composer packages. If you get permission errors, you need to verify the file permissions of the binary file.

But all this is really out of the scope of this library, I can't help you any further here.

Please understand, that I have to close this issue for now, as it is not related to my library. Please consult Google for how to get wkhtmltopdf working on your system.