简体   繁体   中英

How i use dompdf with laravel without a wrapper

I'm trying to use dompdf without the barryvdh's wrapper because I have laravel cashier installed on my project and get the message:

 - Root composer.json requires barryvdh/laravel-dompdf ^0.9.0 -> satisfiable by barryvdh/laravel-dompdf[v0.9.0].
    - Conclusion: don't install dompdf/dompdf v0.8.4 (conflict analysis result)
    - Conclusion: don't install dompdf/dompdf v1.0.2 (conflict analysis result)
    - Conclusion: don't install dompdf/dompdf v0.8.5 (conflict analysis result)
    - Conclusion: don't install dompdf/dompdf v1.1.0 (conflict analysis result)
    - Conclusion: don't install dompdf/dompdf v0.8.6 (conflict analysis result)
    - Conclusion: don't install dompdf/dompdf v1.1.1 (conflict analysis result)
    - laravel/cashier is locked to version v10.7.1 and an update of this package was not requested.
    - laravel/cashier v10.7.1 requires dompdf/dompdf ^0.8.0 -> satisfiable by dompdf/dompdf[v0.8.0, ..., v0.8.6].
    - You can only install one version of a package, so only one of these can be installed: dompdf/dompdf[v0.8.0, ..., v0.8.6, v1.0.0, ..., v1.1.1].
    - barryvdh/laravel-dompdf v0.9.0 requires dompdf/dompdf ^1 -> satisfiable by dompdf/dompdf[v1.0.0, ..., v1.1.1].
    - Conclusion: don't install dompdf/dompdf v1.0.1 (conflict analysis result)

Whenever I tried to install the package. So I'm using the 0.8.6 version that ships with the cashier to generate my pdf. I made a simple test:

Route::get('manual-test-pdf', function () {
  $dompdf = new Dompdf();
  $html = view('pdf.test')->render();
  $dompdf->loadHtml($html);

  return $dompdf->stream();
});

Trying to render the view:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Pdf test</title>
</head>

<body>
  <h1>Test one</h1>
</body>

</html>

But the result is always a blank page. ->render() or ->stream() gave the same result. I think I'm doing something wrong, but I didn't found anything online about the correct way of returning/rendering a pdf with pure dompdf since everyone uses barryvdh's version.

Can anyone give me a light on this one?

The latest stable version of laravel/cashier as of this posting is v13.7.0 which requires:
"dompdf/dompdf": "^0.8.6|^1.0.1" .
"php": "^7.3|^8.0"

The latest stable version of barryvdh/laravel-dompdf as of this posting is v0.9.0 which requires: "dompdf/dompdf": "^1"
"php": "^7.1 || ^8.0"

It looks a lot like these packages are compatible with each other for recent PHP versions.

Your composer.json file already specifies:
"barryvdh/laravel-dompdf": "^0.9.0"
But your composer.json file is locking laravel/cashier to version v10.7.1. So basically you just need to update your cachier version from v10.7.1 to a more recent build such as the current latest as of the time of this posting: v13.7.0

You should be able to get by with a simple:
composer update .

You can also trying deleting your composer.lock file so you're not locked down to a specific version then retry installing/updating with either composer install or composer update .
If you need to retain any specific versions of something after deleting the composer.lock file, such as if it breaks code, specify them in your composer.json file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM