php - "Class 'Cpdf' not found" in "develop" branch

169

I am trying to pull in the develop branch, using composer, like this:

"require": {
    "dompdf/dompdf" : "dev-develop"
}

And requiring like this:

require 'vendor/autoload.php';
    use Dompdf/Dompdf;
// disable DOMPDF's internal autoloader if you are using Composer
define('DOMPDF_ENABLE_AUTOLOAD', false);
define("DOMPDF_ENABLE_REMOTE", true);

// include DOMPDF's default configuration
require_once 'vendor/dompdf/dompdf/dompdf_config.inc.php';

But I am getting error:

 Fatal error: Class 'Cpdf' not found in /vendor/dompdf/dompdf/src/Dompdf/Adapter/CPDF.php on line 190

Line 190:

    $this->_pdf = new \Cpdf(
477

Answer

Solution:

First of all, I would recommend not use develop branch. Please try:

$ composer require "dompdf/dompdf" "0.6.*"

Than in or class add:

<?php

require 'vendor/autoload.php';

define('DOMPDF_ENABLE_AUTOLOAD', false);
define("DOMPDF_ENABLE_REMOTE", true);

require_once __DIR__ . '/vendor/dompdf/dompdf/lib/class.pdf.php';


$pdf = new Cpdf();

The issue is the class\Cpdf is not defined in a namespace so composer does not include it in.\vendor\composer\autoload_classmap.php sorequire need to be used.

598

Answer

Solution:

Loading an elder commit solved the problem

191

Answer

Solution:

What solved it for me

  1. composer remove barryvdh/laravel-dompdf
  2. composer require barryvdh/laravel-dompdf
  3. composer update
  4. composer install

Note, laravel use 5.5.

If you are on Laravel, remember to include it in /config/app.php

Provider: Barryvdh \ DomPDF \ ServiceProvider :: class,

and

Aliases: 'PDF' => Barryvdh \ DomPDF \ Facade :: class,

People are also looking for solutions to the problem: java - Android Fatal Error: Async Task

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.