I'm trying to output a PDF of a twig file using Snappy oh my Symfony project. When I click the link my page redirects and I get the following exception:
The exit status code '1' says something went wrong:
stderr: "The system cannot find the path specified.
"
stdout: ""
command: /usr/local/bin/wkhtmltopdf --lowquality "C:\Users\user\AppData\Local\Temp\knp_snappy52333e6a9d6731.29137239.html" "C:\Users\user\AppData\Local\Temp\knp_snappy52333e6a9e84c9.03326780.pdf".
I checked the AppData folder and the html file has been rendered. There is no PDF which is what I assume Snappy is trying to generate.
I have a call similar to the following in my controller:
$html = $this->renderView('MyBundle:Foo:bar.html.twig', array(
'some' => $vars
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
This is my config.yml
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf
options: []
image:
enabled: true
binary: /usr/local/bin/wkhtmltoimage
options: []
Is there something that I have missed? I am running this on my local Windows machine, could it be a permissions error?
Most likely you have put the wrong path to the executable file.
/usr/local/bin/wkhtmltopdf - Linux path to wkhtmltopdf binary.
You must find where your wkhtmltopdf placed and set right path at config.
The issue was that I hadn't installed wkhtmltopdf, doh!
Related
following the README I installed PHP FFmpeg through Composer and I downloaded binaries from https://ffmpeg.zeranoe.com/builds/
now I'm trying to run the "Basic Usage" example:
<?php
require("vendor/autoload.php");
$ffmpeg = FFMpeg\FFMpeg::create();
$video = $ffmpeg->open('video.mpg');
$video
->filters()
->resize(new FFMpeg\Coordinate\Dimension(320, 240))
->synchronize();
$video
->frame(FFMpeg\Coordinate\TimeCode::fromSeconds(10))
->save('frame.jpg');
$video
->save(new FFMpeg\Format\Video\X264(), 'export-x264.mp4')
->save(new FFMpeg\Format\Video\WMV(), 'export-wmv.wmv')
->save(new FFMpeg\Format\Video\WebM(), 'export-webm.webm');
?>
but i receive "Executable not found" errors because I didn't understand where to put them
I also tried specifying binaries ffmpeg.exe and ffprobe.exe with:
$ffmpeg = FFMpeg\FFMpeg::create(array(
'ffmpeg.binaries' => '/pathtobin/ffmpeg',
'ffprobe.binaries' => '/pathtobin/ffprobe',
'timeout' => 3600, // The timeout for the underlying process
'ffmpeg.threads' => 12 // The number of threads that FFMpeg should use
), $logger);
but still same error... am I making a mountain out of a molehill? any help is appreciated... Thanks
EDIT 1
I added ffmpeg\bin folder to system path and I can run executables from cmd from anywhere, but now I'm getting this error: "Executable not found, proposed : avprobe, ffprobe"...
instead, if I give binary paths explicitly, I get 'ffprobe failed to execute command "C:/FFmpeg/bin/ffprobe.exe" "-help" "-loglevel" "quiet"'
what am I doing wrong?
EDIT 2
web server config
Windows 10 Pro
IIS 10
PHP 7.0.9
site root ---> C:\inetpub\wwwroot\site\
content:
- index.php
- input.mp4
- vendor/ (PHP-FFMpeg library folder)
FFmpeg binaries ---> C:\inetpub\wwwroot\FFmpeg\
content:
- ffmpeg.exe
- ffplay.exe
- ffprobe.exe
index.php
<?php
ini_set('display_errors', 'On'); error_reporting(E_ALL);
require("vendor/autoload.php");
$ffmpeg = FFMpeg\FFMpeg::create(array(
'ffmpeg.binaries' => 'C:/inetpub/wwwroot/FFmpeg/ffmpeg.exe',
'ffprobe.binaries' => 'C:/inetpub/wwwroot/FFmpeg/ffprobe.exe',
'timeout' => 3600, // The timeout for the underlying process
'ffmpeg.threads' => 12, // The number of threads that FFMpeg should use
));
$video = $ffmpeg->open('input.mp4');
?>
result
Fatal error: Uncaught Alchemy\BinaryDriver\Exception\ExecutionFailureException: ffprobe failed to execute command "C:/inetpub/wwwroot/FFmpeg/ffprobe.exe" "-help" "-loglevel" "quiet" in C:\inetpub\wwwroot\site\vendor\alchemy\binary-driver\src\Alchemy\BinaryDriver\ProcessRunner.php:100 Stack trace: #0 C:\inetpub\wwwroot\site\vendor\alchemy\binary-driver\src\Alchemy\BinaryDriver\ProcessRunner.php(72): Alchemy\BinaryDriver\ProcessRunner->doExecutionFailure('"C:/inetpub/www...') #1 C:\inetpub\wwwroot\site\vendor\alchemy\binary-driver\src\Alchemy\BinaryDriver\AbstractBinary.php(209): Alchemy\BinaryDriver\ProcessRunner->run(Object(Symfony\Component\Process\Process), Object(SplObjectStorage), false) #2 C:\inetpub\wwwroot\site\vendor\alchemy\binary-driver\src\Alchemy\BinaryDriver\AbstractBinary.php(137): Alchemy\BinaryDriver\AbstractBinary->run(Object(Symfony\Component\Process\Process), false, NULL) #3 C:\inetpub\wwwroot\site\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\FFProbe\OptionsTester.php(61): Alchemy\Binary in C:\inetpub\wwwroot\site\vendor\php-ffmpeg\php-ffmpeg\src\FFMpeg\FFProbe\OptionsTester.php on line 63
The docs say:
This library requires a working FFMpeg install. You will need both FFMpeg and FFProbe binaries to use it. Be sure that these binaries can be located with system PATH to get the benefit of the binary detection, otherwise you should have to explicitly give the binaries path on load.
You will need to store these somewhere permanent and then add this path to your System or User PATH variable:
You would add ";c:\my\path\to\ffmpeg" to the end of the PATH value.
I had this problem too. Spent two days using procmon to determine why PHP wasn't starting ffprobe.exe on a new Windows 2016 install.
Turns out if your IIS AppPool identity doesn't have at least modify writes on the C:\Windows\temp folder, you will get this misleading error.
You can get the App Pool identity/context of your site using (not to be confused with the user context provided from get_current_user(). ):
echo "Get ENV: ".getenv("APP_POOL_ID");
Or
echo "Get SERVER: ".$_SERVER["APP_POOL_ID"];
From my analysis, this is because PHP-CGI.exe, CMD.exe & the ffmpeg exe's (ffmpeg.exe, ffprobe.exe, ffplay.exe) use flat files in the temp folder to exchange and parse information. When PHP-CGI.exe creates a temp file in this location all other processes can only read from the temp file, leaving it empty 0 bytes. Every page load, I had these empty temp files being written to C:\Windows\Temp and ffprobe.exe would never execute.
Hope this helps someone.
I am wondering if anyone has attempted to automate the deployment of wordpress and puphpet.
I am not to familiar with puphpet but I know it uses the hiera.yaml file along with the manifets and modules folder. I attempted something simple
I added this to config.yaml file and imported the wordpress module from vagrant press
wordpress:
install: '1'
It looks like I may need to add something to the main manifest.pp file that puphpet generates. If anyone has attempted something like this I would appreciate any advice. Or is it better to just use yeoman instead?
Update
I add this to the config.yaml file
wordpress:
install: '1'
Then in the manifest.pp file I added this at the bottom form (wordpress vagrant box) and it seems to work:
# Begin wordpess
if $wordpress_values == undef {
$wordpress_values = hiera('wordpress', false)
if hash_key_equals($wordpress_values, 'install', 1) {
# Download WordPress
exec {"download_wordpress":
command => "wget http://wordpress.org/latest.tar.gz",
cwd => "/tmp",
creates => "/tmp/latest.tar.gz",
path => ["/usr/bin", "/bin", "/usr/local/bin"],
unless => "test -f /var/www/index.php",
}
# Extract WordPress
exec {"extract_wordpress":
command => "tar xzf /tmp/latest.tar.gz",
cwd => "/tmp",
creates => "/tmp/wordpress",
path => ["/usr/bin", "/usr/local/bin", "/bin"],
require => Exec["download_wordpress"],
unless => "test -f /var/www/index.php",
}
# Install WordPress
exec {"install_wordpress":
command => "cp -r /tmp/wordpress/* /var/www/wordpress",
cwd => "/tmp",
path => ["/usr/bin", "/usr/local/bin", "/bin", "/usr/local/sbin", "/usr/sbin", "/sbin"],
require => Exec["extract_wordpress"],
unless => "test -f /home/www/index.php",
}
}
}
PuPHPet uses hiera but not in the traditional Puppet way. You still need to actually create the Puppet code that interacts with the hiera values.
I'm new to symfony2 and very to use external libraries.
I want to use the KNP Snappy Bundle, my first third party bundle.
I did exactly that is told in the git link.
{
"require": {
"knplabs/knp-snappy-bundle": "dev-master"
}
}
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
//...
new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
app/config/config.yml
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf
options: []
image:
enabled: true
binary: /usr/local/bin/wkhtmltoimage
options: []
Then I added following line in ACME welcome controller to test
$this->get('knp_snappy.pdf')->generate('http://www.google.fr', '/Symfony/file.pdf');
It says The exit status code '1' says something went wrong:
stderr: "The system cannot find the path specified.
"
stdout: ""
command: /usr/local/bin/wkhtmltoimage --format "jpg" "http://www.google.fr" "/Symfony/file.pdf".
I tried
$this->get('knp_snappy.pdf')->generateFromHtml(
$this->renderView(
'AcmeDemoBundle:Welcome:index.html.twig'),
'/Symfony/file.pdf'
);
It shows The exit status code '1' says something went wrong:
stderr: "The system cannot find the path specified.
"
stdout: ""
command: /usr/local/bin/wkhtmltopdf --lowquality "C:\Windows\TEMP\knp_snappy530da4525584b8.92211088.html" "/Symfony/file.pdf".
What I'm missing? Do I need to install anything ? Please describe how can I run it and generate a proper pdf????? I searched, I'm guessing I need to install wkhtmltoimage etc. But from where and how?
you can also manage wkhtmltopdf with composer too, I did it in a recent project:
in your composer.json you can add:
"h4cc/wkhtmltopdf-amd64": "0.11.0-RC1"
and in your config.yml:
binary: %kernel.root_dir%/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64
Few months later, but here is what helped me.
I put the path to wkthmltopdf folder in escaped double quotes.
knp_snappy:
pdf:
binary: "\"C:/Program Files (x86)/wkhtmltopdf/wkhtmltopdf.exe\""
You can do one of these
1- Update your config.yml
pdf:
enabled: true
binary: wkhtmltopdf
options: []
And update your windows environment PATH with path/to/my/wkhtmltopdf
2- Or set the path directly in config.yml
pdf:
enabled: true
binary: /path/to/my/wkhtmltopdf
options: []
Help me out here....
I have installed wkhtml2pdf 0.9.9 static for mac os and installed it in the /usr/bin. Wkhtml2pdf works fine from the terminal, with the wkhtmltopdf [source website][generated file to be saved].
Though I am unable to use it in Symfony 2.3.7, with the knpSnappy and knpSnappyBundle installed. I am sure I have entered everything correctly. I have checked it a million times and searched all of the google and yet couldnt find why it would do that (been searching for two days.
I have downloaded knpSnappy and knpSnappyBundle through composer and it is in the vendor and as well as enabled in the config.yml and added to appkernel.php, other than that Following is my configuration:
Composer:
"knplabs/knp-snappy-bundle": "dev-master",
"knplabs/knp-snappy": "*"
Appkernel:
new Knp\Bundle\SnappyBundle\KnpSnappyBundle(),
Controller:
public function generateAction($date)
{
$em = $this->getDoctrine()->getManager();
$publishedAds = $em->getRepository('pdfRenderAdBundle:Ads')
->getAllAds();
if (!$publishedAds) {
throw $this->createNotFoundException(
'No ads found for today!'
);
}
$html = $this->renderView('pdfRenderAdBundle:Application:generate.html.twig', array(
'publishedAds' => $publishedAds
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
400,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
}
SYMFONY VER: 2.3.7
WKHTMLTOPDF: 0.9.9 STATIC OSX KNPSNAPPY LIB &
KNPSNAPPY BUNDLE: THE LATEST ONE THROUGH SYMFONY
Whenever I try to access the controller it gives the:
The process has been signaled with signal "5" - 500 Internal Server Error - RuntimeException
I will really appreciate it if any one of you can help out of this well..... Stuck here for a very long time now.
For anyone else that comes across this, here's the post on how to get this working:
http://oneqonea.blogspot.com/2012/04/why-does-wkhtmltopdf-work-via-terminal.html
Here's the short version:
Comment out the following line in /Applications/MAMP/Library/bin/envvars
#export DYLD_LIBRARY_PATH
And then add this line:
export PATH=/parent/path/of/wkhtmltopdf/executable:$PATH
I had this problem as well, and if IIRC the solution was to use wkhtmltopdf version 0.9.6.
When I go to /fileDownload I receive a 500 Internal Server Error - RuntimeException:
The process stopped because of a "0" signal.
Controller Action:
public function fileAction()
{
$html = $this->render('MyBundle:Downloads:file.html.twig', array(
'fileNumber' => '1234'
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="file.pdf"'
)
);
}
I've used terminal commands for WKHTMLTOPDF and it has successfully generated the PDF. It just will not work in Symfony2 app.
In my config.yml:
knp_snappy:
pdf:
enabled: true
binary: /usr/local/bin/wkhtmltopdf
options: []
I'm assuming Symfony is issuing an exec() at some stage. You need to get the exact command line error returned. The fact it works for you in a terminal session doesn't necessarily mean it will work when a different user/process is running it.
Check permissions on wkhtmltopdf that apache or whoever is running your web server has access to run the command.
Also, check this question out wkhtmltopdf: cannot connect to X server and also the first post here: http://geekisland.org/index.php?m=05&y=11&entry=entry110518-114630
X Server is required to run certain builds of wkhtmltopdf and it is not present when running via cron or from within an apache process. If this is the case you need to use the bash wrapper in the first link above.
Be sure that wkhtmltopdf is indeed in the folder you specify, with correct permissions: /usr/local/bin/wkhtmltopdf
I am successfully using KNP Snappy Bundle with Symfony 2.0, try using RenderView instead of render when generating the html (check my code that is working):
Controller:
$html = $this->renderView('YOPYourOwnPoetBundle:thePoet:poemPDF.html.twig', array(
'poem' => $customizedPoem,
'fontType' => $fontType,
'fontSize' => $formData['fontSize'],
'fontWeight' => $fontWeight,
'fontStyle' => $fontStyle,
));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="'.$session->get('poemTitle').'.pdf"',
)
);
I had this same issue and i finally solved it, my advice is if you installed the wkhtmltopdf lib from your OS repos then remove it, and download the static version from the google code website, and don't use version 11rc, use the version 9 static lib, it's the one that worked with me.
http://code.google.com/p/wkhtmltopdf/downloads/list
It looks like the selinux is blocking your command, I had the same issue once but I solved it by disabling the SELinux and now I'm able to generate the pdf file using wkhtmltopdf+php.
exec("/usr/local/bin/wkhtmltopdf http://www.google.com /var/www/html/google.pdf");
To disable selinux run setenforce 0,
try again and see if it works.
Re-enable it with setenforce 1
But disabling selinux is not the best solution for this, you need to extend it instead using audit2allow, it will automatically create a custom policy module that will resolve this issue,
First install audit2allo if not already installed
yum -y install policycoreutils-python
grep httpd_t /var/log/audit/audit.log | audit2allow -m httpdlocal > httpd.te
checkmodule -M -m -o httpdlocal.mod httpd.te
semodule_package -o httpdlocal.pp -m httpdlocal.mod
semodule -i httpdlocal.pp
try again and see if it works
I experienced the same issue on same scenario with wkhtmltopdf. And I got rid of with the following command:
setsebool httpd_execmem on