KnpLabs / snappy

PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage
https://knplabs.com
MIT License
4.4k stars 436 forks source link

Need Symfony to work ? #175

Closed crouti closed 9 years ago

crouti commented 9 years ago

I installed the package in my webroot (Ubuntu) and correctly inserted php code in my wordpress plugin. But, generating pdf (whichever method : generateFromHtml,getOutputFromHtml, getOutput, ...) i get the following error :

`PHP Fatal error: Class 'Symfony\Component\Process\Process' not found in /var/www/snappy-master/src/Knp/Snappy/AbstractGenerator.php on line 467``

Do i need Symfony to use snappy ? Thank you very much

jeremyb commented 9 years ago

I think you faced the same issue as this one: #171. You should use Composer autoloader instead of Snappy's one. require __DIR__ . '/vendor/autoload.php';

crouti commented 9 years ago

Thank you but, it's been installed in root dir, so how to properly set the permissions on it ? Thanks

2015-07-31 17:40 GMT+02:00 Jeremy Barthe notifications@github.com:

I think you faced the same issue as this one: #171 https://github.com/KnpLabs/snappy/issues/171. You should use Composer autoloader instead of Snappy's one. require DIR . '/vendor/autoload.php';

— Reply to this email directly or view it on GitHub https://github.com/KnpLabs/snappy/issues/175#issuecomment-126727371.

Max UNGER 09.54.69.54.53

www.termel.fr

crouti commented 9 years ago

Also, i don't have any Symfony installed, do i absolutely need it ?

jeremyb commented 9 years ago

knplabs/knp-snappy has only a dependency to one Symfony component (symfony/process) so you don't need to install the whole Symfony framework.

Basically if you have installed Snappy through Composer like that composer require knplabs/knp-snappy you just need to require this autoload file: require __DIR__ . '/vendor/autoload.php';

crouti commented 9 years ago

Yes i did installed Snappy through Composer, but i find the autoload inside /root/vendor/ and i am wondering how to link to it from php, which still says Permission denied when trying to access with suggested method. Do i need a symbolic link inside my webroot ? How ? Thank you very much

crouti commented 9 years ago

My referencing file is inside my wordpress custom plugin directory.

akovalyov commented 9 years ago

@crouti you need to run composer install in your webroot or in your plugin directory, not in your user home dir. Or have you executed composer global install?

crouti commented 9 years ago

Ok thanks, i didn't ran it into my plugin dir, i'll try that right now.

crouti commented 9 years ago

I've just installed composer in my plugin dir, then snappy and process, but i have now a runtime exception:

`PHP Fatal error: Uncaught exception 'RuntimeException' with message 'The exit status code '1' says something went wrong: stderr: "wkhtmltopdf: cannot connect to X server``

Any idea ?

akovalyov commented 9 years ago

@crouti well, snappy works :) which wkhtmltopdf version are you using?

crouti commented 9 years ago

wkhtmltopdf 0.9.9 from apt-get on ubuntu LTS

akovalyov commented 9 years ago

@crouti as stated in Snappy README, You will have to download wkhtmltopdf 0.12.x in order to use Snappy.. You can either download deb package from http://wkhtmltopdf.org/ or you can also install in through composer as described in README

crouti commented 9 years ago

Oh, sorry, my fault, i then used: http://askubuntu.com/questions/556667/how-to-install-wkhtmltopdf-0-12-1-on-ubuntu-server

ti install wkhtmltopdf 0.12.0 final

i restarted apache2 server, but still got the same error....

crouti commented 9 years ago

it seems i have to restart my server...

crouti commented 9 years ago

unfortunately, same problem after server restart...

crouti commented 9 years ago

had to reinstall pre-packaged version : http://wkhtmltopdf.org/downloads.html the test : wkhtmltopdf http://www.google.com test.pdf works

akovalyov commented 9 years ago

@crouti and from Snappy side?

crouti commented 9 years ago

seems to almost work, but can't make the file open in my browser (or available for download) with following command header('Content-Type: application/pdf'); //header('Content-Disposition: attachment; filename="file.pdf"'); echo $snappy->getOutput('http://www.github.com');

crouti commented 9 years ago

in firefox

crouti commented 9 years ago

Can't see how to make it work... no error outputed in log, but no file appearing in browser... Here is my complete function:

function doff_process_ajax_show_pdf_preview() {
        log_me('doff_show_pdf_preview');
        $doff_template_result = do_shortcode( '[doff-custom-header]' );
        $snappy = new Pdf(PATH_TO_WKHTMLTOPDF); 
        header('Content-Type: application/pdf');
        header('Content-Disposition: attachment; filename="file.pdf"');
        $args = array();
        echo $snappy->getOutputFromHtml($doff_template_result,$args,true);
        log_me('END::doff_show_pdf_preview');
        die();
    }
crouti commented 9 years ago

although file writing works, with

$snappy->generateFromHtml(myhtml, $filename);

for example.

any idea ? thanks a lot

akovalyov commented 9 years ago

@crouti Snappy uses file_get_contents to retrieve the content. If fetching of remote URL does not work, it might be http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-fopen.

crouti commented 9 years ago
allow_url_fopen = On

in my php.ini

crouti commented 9 years ago

is it a problem if i generate the file within an ajax jquery call ?

crouti commented 9 years ago

without ajax call, seems to work in Firefox, but not in chrome

akovalyov commented 9 years ago

@crouti you can't download a file with AJAX call. You should either request file generation and oncomplete redirect the user to the file endpoint or use libs like https://github.com/johnculviner/jquery.fileDownload to stream the content and save it on user machine. Anyway, it is not related to Snappy at all and to the first issue as well. Please, feel free to open a new issue if you need any help with Snappy.

crouti commented 9 years ago

Thank you very much!