KnpLabs / snappy

PHP library allowing thumbnail, snapshot or PDF generation from a url or a html page. Wrapper for wkhtmltopdf/wkhtmltoimage

Home Page:https://knplabs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uncaught Error: Class 'Knp\Snappy\Pdf' not found

mennei opened this issue · comments

Hi,
I have local Apache2.4 on window 10 with php 7.2.4 version.
When I send my html form to the server, I get
Uncaught Error: Class 'Knp\Snappy\Pdf' not found in C:\Apache24\htdocs\bitul-rishum\pdf.php:15
The pdf.php is:

<title>בקשת העברה למסגרת אחרת - בתי ספר - מחלקת החינוך</title>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js" ></script>
</head>
<body>
    <div class="container">
        <main><!-- main[white-bg] -->
           <?php echo str_replace("https://tk.bitul-rishum.automas.co.il", $dir, $_POST['html']);?>
        </main>
    </div>
   <script type="text/javascript">
      $('select').each(function(){
          $(this).replaceWith('<span style="    border-bottom: 1px solid #000; display: inline-block; height: 27px; margin-bottom: 5px;" class="text">'+$(this).val()+'</span>');
      });
  </script>
$snappy->setOption('page-size', 'A4');
$snappy->setOption('zoom', '1');
$snappy->setOption('margin-top', '0');
$snappy->setOption('margin-right', '0');
$snappy->setOption('margin-bottom', '0');
$snappy->setOption('margin-left', '0');

$pdfname = uniqid().'_'.time().'.pdf';

$snappy->generateFromHtml($html, $path .$pdfname);

if (file_exists($path.$pdfname)) {
echo $pdfname;
} else {
echo "error";
}
die();

I get the "Uncaught Error: Class 'Knp\Snappy\Pdf' not found in C:\Apache24\htdocs\bitul-rishum\pdf.php:15" message in http response of the post request that made from main.js.

I try to reinstall snappy by "composer require knplabs/knp-snappy", and it failed, saying:
..... can only install on of:....
and the last is:

  • Can only install one of: symfony/process[v5.0.4, v4.2.4].
    • Installation request for symfony/process (locked at v4.2.4) -> satisfiable by symfony/process[v4.2.4].
      Installation failed, reverting ./composer.json to its original content.

when I type:
PS C:\Apache24\htdocs\httpdocs\vendor> composer global why symfony/process -t
I get:
Changed current directory to C:/Users/user/AppData/Roaming/Composer
symfony/process v4.4.3 Symfony Process Component
└──laravel/installer v1.5.0 (requires symfony/process ~3.0|~4.0)
└──__root__ (requires laravel/installer ~1.1)

Please help,
Menachem
mennei.segal@gmail.com

Hello,
Can you please share your composer.json content?

{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.1.3",
"barryvdh/laravel-dompdf": "^0.8.4",
"barryvdh/laravel-snappy": "^0.4.4",
"consoletvs/charts": "6.",
"fideloper/proxy": "^4.0",
"laravel/framework": "5.8.
",
"laravel/tinker": "^1.0",
"maatwebsite/excel": "^3.1",
"nesbot/carbon": "^2.24"
},
"require-dev": {
"beyondcode/laravel-dump-server": "^1.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpunit/phpunit": "^7.5"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\Foundation\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-root-package-install": [
"@php -r "file_exists('.env') || copy('.env.example', '.env');""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
}
}

Do you need the composer.lock.json?

It seems that your issue is more a composer issue than a Snappy issue.
As far as I know Snappy library is already installed by barryvdh/laravel-snappy and it should be available.
Unfortunately I never used Laravel and I can't help you with that.
What if you remove the vendor directory and you re-install your dependencies with composer install?
Do you get any error?

Thank for your replay :)
You right and the real issue was to run laravel app on plesk server. That solve by php composer install by the web console in plesk.

Thank for your replay :)
You right and the real issue was to run laravel app on plesk server. That solve by php composer install by the web console in plesk.

hi i am facing similar issue like you. It able to run at my local window os but it can run at plesk server. may i know how you fix it