inside a custom module (custom form), I need to call the Dompdf() class. Here is my code:

use Dompdf; // or use Dompdf\Dompdf;
class myclass....

  public function buildPdf(array &$form, FormStateInterface $form_state) {

    $dompdf = new Dompdf();
    $dompdf->loadHtml('hello world');
    $dompdf->setPaper('A4', 'portrait');

But, the class isn't found and in logs I get this error:

Error : Class 'Dompdf' not found in...

At the module root, a composer.json file was created with this code:

  "name": "drupal/mymodule",
  "require": {
    "dompdf/dompdf": "~0.8.3"

In \vendor, the Dompdf directory exists.

I don't see how to resolve this problem. The vendor repertory is located in a parent level:



put on hold as unclear what you're asking by Kevin, mradcliffe, leymannx, kiamlaluno 2 days ago

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • How does your Drupal project's composer.json look like? Vendor outside of the project root won't be autoloaded. I wonder how it landed there in the first place? – leymannx Aug 14 at 17:27
  • If that’s where vendor is and you are not using the Drupal composer project template, how is any of it working without modification to autoloading? – Kevin Aug 14 at 21:27

Browse other questions tagged or ask your own question.