I am trying to create pdf with Laravel snappy.
The problem is when I try to run wkhtmltopdf command in the console for example:
wkhtmltopdf http://google.com google.pdf
it works fine and generates pdf.
But when I try to generate pdf in my controller, then it throws this exception:
RuntimeException
The file
'/home/alemil/Projects/test/storage/app/annual_reports/Pdf test.pdf' was not created
(command: /usr/local/bin/wkhtmltopdf --lowquality --orientation
'landscape' --page-size 'a3'
'/tmp/knp_snappy5bb49cd6bfcf14.16728595.html'
'/home/alemil/Projects/test/storage/app/annual_reports/Pdf test.pdf').
I tried to copy command above and execute directly in console. This is what I get:
Loading pages (1/6)
Error: Failed to load http://tmp/knp_snappy5bb49cd6bfcf14.16728595.html, with network status code 3 and http status code 0 - Host tmp not found
Error: Failed loading page http:///tmp/knp_snappy5bb49cd6bfcf14.16728595.html (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: HostNotFoundError
As I can see, it tries to fetch local file as it is remote. I couldn't find this issue so I am asking if someone can solve this or has any idea.
My environment is Ubuntu 18.04 PHP and PHP 7.2.10.
This is my code:
// app.php aliases
'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
// controller code
PDF::loadView('admin.reports.annual.pdf_template', $data)
->setPaper('a3', 'landscape')
->save(
storage_path('app/annual_reports/') . $report->pdf,
true // when there is file with same name it throws file already exists so I had to set owerwrite to true
);
Also, one more thing to point out, I was using barryvdh/laravel-dompdf and everything was working fine except it cannot render charts so I'm now trying to set up snappy.
In my case the problem was that I passed null in $html to Knp\Snappy\Pdf::getOutputFromHtml($html). Under the hood it cheks if $html !== null and creates a temporary file for further PDF generating. If temporary file doesn't exist wkhtmltopdf throws error like described in question.
hmm
I think (not sure) that there are a a blocking in your application that blocks your controller from getting to the link. Or at the creating of the PDF.
It can also be your code syntax.
you can try this for html :
$pdf = new Pdf('/usr/local/bin/wkhtmltopdf');
$pdf->generateFromHtml('<h1>test</h1><p>test from test</p>', '/tmp/test-123.pdf');
Related
I am using mPDF library to generate a pdf from my php server script. I have used composer to install the library into my live server file system.
I was being able to generate the pdf file successfully for quite a couple of months, until today morning. Everytime I try to generate the pdf it shows this error in the console:
Notice: file_get_contents(): Read of 8192 bytes failed with errno=21 Is a directory in /home/user/domains/report_generation/backend_pdfgen/vendor/mpdf/mpdf/src/File/LocalContentLoader.php on line 10
According to the console, I went to line 10 in LocalContentLoader.php. This is the code:
<?php
namespace Mpdf\File;
class LocalContentLoader implements \Mpdf\File\LocalContentLoaderInterface
{
public function load($path)
{
return file_get_contents($path);
}
}
This is my pdf generation script (pdfgen.php):
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf(['setAutoTopMargin' => 'stretch']);
$mpdf->SetTitle("report.pdf");
$mpdf->SetAuthor("Anonymous");
$mpdf->WriteHTML('<div style="text-align:center";>Some data here</div>');
$mpdf->Output("reports/report.pdf");
?>
My file hierarchy:
I am not being able to understand what's wrong with it. I surfed on the internet and found a post where it was mentioned that I have to increase the upload_max_filesize, it's already increased to 1 GB, but still the error message shows. Where am I going wrong. Please guide me.
Surprisingly, the error doesn't show when I run the script in my localhost server.
This is very likeley because of insufficient disk space.
Try another location or verify you have enough space. Check where report.pdf is intended to be safed.
I'm trying to use Puppeteer and BrowserShot on an Ubuntu machine to make and screenshot of a static HTML.
The thing is that every time I try to make and screenshot:
Screenshot::loadView('monthly_resume.resume')
->waitUntilNetworkIdle(true)
->windowSize(1200, 630)
->noSandbox()
->storeAs($this->pathFor($user), 'image.php');
It returns an error. It seems that the HTML it's stored properly under a folder inside /tmp, in this case tmp/441150534-0230735001662479158/index.html.
But when node tries to find it says that the file it's not found even when it's there. Any idea why node can't find it?
Symfony\Component\Process\Exception\ProcessFailedException
The command "PATH=$PATH:/usr/local/bin:/opt/homebrew/bin NODE_PATH=`npm root -g` node '/home/forge/monse.app/vendor/spatie/browsershot/src/../bin/browser.js' '{"url":"file:\/\/\/tmp\/441150534-0230735001662479158\/index.html","action":"screenshot","options":{"type":"png","path":"\/tmp\/1562301876-0230606001662479158\/BrowsershotOutput1662479158hbgfB.png","args":["--no-sandbox"],"viewport":{"width":1200,"height":630},"displayHeaderFooter":false,"waitUntil":"networkidle0"}}'" failed.
Exit Code: 1(General error)
Working directory: /home/forge/monse.app
Output:
================
Error Output:
================
Error: net::ERR_FILE_NOT_FOUND at file:///tmp/441150534-0230735001662479158/index.html
at navigate (/home/forge/node_modules/puppeteer/lib/cjs/puppeteer/common/Frame.js:225:23)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Frame.goto (/home/forge/node_modules/puppeteer/lib/cjs/puppeteer/common/Frame.js:195:21)
at async Page.goto (/home/forge/node_modules/puppeteer/lib/cjs/puppeteer/common/Page.js:1143:16)
at async callChrome (/home/forge/monse.app/vendor/spatie/browsershot/bin/browser.js:249:26)
I encountered exact error message that you got. But then I just change temp path and its working fine. I'm using spatie/browsershot by the way
To change temp path at spatie/browsershot:
Browsershot::html('some html string')
->setCustomTempPath('/home/your/other/path')
->save('filename.jpg')
I'm working on using puphpeteer, which is a PHP wrapper for the original puppeteer functionality, to do some automated downloads from a website. I've followed the instructions as they were written in the documentation and tried to create an object:
public function getReport(){
$puppeteer = new Puppeteer;
}
Simply instantiating the object above produces the following error:
Exit Code: 1(General error) Working directory: C:\Users\username\Projects\projectfolder\public
Output: ================ Error Output: ================
node' is not recognized as an internal or external command, operable program or batch file
I did find that the object is just failing to be instantiated in the __constructor(). I can follow the stack trace of the code but none of it is helping me understand what is going wrong, which is that Laravel/artisan do not see node as a valid command.
General notes:
PHP 7.3.9
Laravel 7.1.3
Composer 1.9.0
node v12.16.1
node is in my path as the first variable
using Windows 10
How do I get Laravel/artisan to recognize that I have a node installation for this package?
Do you know the location of node on your system? Try placing it here:
$puppeteer = new Puppeteer([
'executable_path' => "PATH_TO_NODE_HERE"
]);
I am facing the same problem with Laravel/Artisan.
'node' is not recognized as an internal or external command, operable program or batch file
after adding
$puppeteer = new Puppeteer([
'executable_path' => "PATH_TO_NODE_HERE"
]);
Puppeteer generate socket error so I move my project to wamp instead of Laravel/Artisan.
all working fine with out adding 'executable_path' on wamp. better to move your project to Wamp or Xampp server. you can read nesk comment here
https://github.com/rialto-php/puphpeteer/issues/35
I need to upload my symfony 3 project online, but I have only access to ftp. So I did all necessary steps I found:
composer update
Clear the cache for production: php app/console cache:clear --env=prod
Upload all app folder on server
After I open my website I got the following error:
Fatal error: require(): Failed opening required
'/nfsmnt/hosting2_1/a/8/a87b3594-7cfe-459e-ad62-286d2dba2c54/zorbfutbal.sk/web/var..\vendor\symfony\symfony\src\Symfony\Component\ClassLoader\ApcClassLoader.php'
(include_path='.:/usr/php56/lib/php') in
/nfsmnt/hosting2_1/a/8/a87b3594-7cfe-459e-ad62-286d2dba2c54/zorbfutbal.sk/web/var/bootstrap.php.cache on line 1780
I checked the file and I have it there and also set all permissions.
What is confusing me is that path from error before my actual domain name.
"/nfsmnt/hosting2_1/a/8/a87b3594-7cfe-459e-ad62-286d2dba2c54/"
I dont know where it comed from and how to fix it.
Any idea? Thanks
You are absolutely sure you set the file permissions correctly like indicated here:
http://symfony.com/doc/current/setup/file_permissions.html#using-acl-on-a-system-that-supports-setfacl-linux-bsd
The message you posted seems to point to something like that.
Also run:
php bin/symfony_requirements
just to check that you've met all the other requirements.
I have log4php working via the command line successfully but I am struggling when using it with an PHP API (via Apache).
The error I am getting is;
PHP Warning: log4php: Configuration failed. Error loading configuration file: failed
to load external entity "logging.xml"
logging.xml is in the same directory as the PHP file and is loaded via;
$configFile = "logging.xml";
Logger::configure($configFile);
Ideas please? I tried changing it to use the full URL for the file and the full local path and they result in the same error.
The same setup works via the CLI.