Tried to install this module with Ludwig https://www.drupal.org/project/ludwig and it almost works.

Get this error then visiting configuration page /admin/config/content/entityprint :

Error: Class 'Cpdf' not found in Dompdf\Adapter\CPDF->__construct() (line 198 of .../entity_print/lib/dompdf-dompdf/v0.8.3/src/Adapter/CPDF.php)

To support Ludwig this module should create ludwig.json file, and something else because this error.
Attached a patch with Ludwig file.

Comments

mindaugasd created an issue. See original summary.

mindaugasd’s picture

StatusFileSize
new327 bytes

Updated patch, download url was wrong previously.

mindaugasd’s picture

Issue summary: View changes
mindaugasd’s picture

StatusFileSize
new720 bytes

Found the problem, Ludwig does not support this loading type.
Just wrote about it in Ludwig issues here https://www.drupal.org/project/ludwig/issues/2914840#comment-13025150
As a temporary solution attached a patch - it works!

mecurran’s picture

@mindaugasd do you have the autoload.inc.php file in the lib/dompdf-dompdf/v0.8.3/ directory?

I am asking because when I add require_once('lib/dompdf-dompdf/v0.8.3/autoload.inc.php'); to my entity.module I get this error:

Fatal error: require_once(): Failed opening required 'lib/dompdf-dompdf/v0.8.3/autoload.inc.php' (include_path='/srv/bindings/ee6d52a3ec7948d99223654c03fba695/code/vendor/pear/archive_tar:/srv/bindings/ee6d52a3ec7948d99223654c03fba695/code/vendor/pear/console_getopt:/srv/bindings/ee6d52a3ec7948d99223654c03fba695/code/vendor/pear/pear-core-minimal/src:/srv/bindings/ee6d52a3ec7948d99223654c03fba695/code/vendor/pear/pear_exception:.:/usr/share/pear:/usr/share/php') in /srv/bindings/ee6d52a3ec7948d99223654c03fba695/code/modules/contrib/entity_print/entity_print.module on line 8

mindaugasd’s picture

Yes, I have this file /public_html/modules/entity_print/lib/dompdf-dompdf/v0.8.3/autoload.inc.php
Maybe you get this error because you don't have this file placed there?

mecurran’s picture

I had downloaded the library from https://github.com/dompdf/dompdf/archive/v0.8.3.zip. Which actually is NOT dompdf-0.8-3 (it is dompdf-0.8-2.3), and which doesn't have the autoload.inc.php file. Downloading the library from https://github.com/dompdf/dompdf/releases/download/v0.8.3/dompdf_0-8-3.zip, resolves that issue as it includes the autoload.inc.php file as well as a few others. Thank you for the require_once solution - works like a charm :)

mindaugasd’s picture

Welcome. Correct URL is listed in the patch itself https://www.drupal.org/files/issues/2019-03-16/ludwig-3040695-4.patch

mandus.cz’s picture

Status: Active » Reviewed & tested by the community

It works! Thanks.
Please add to the new release.

devad’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new787 bytes

Thnx @mindaugasd

I suppose it would be good to require_once() php file conditionally - if Ludwig module exists only. To avoid "File not found" errors for composer users.

New patch attached.

devad’s picture

Status: Needs review » Closed (won't fix)

After digging a bit deeper into Entity Print module composer installation it came to the surface that dompdf/dompdf library is not the only one which has to be included into ludwig.json file.

Three other libraries are required by dompdf/dompdf library either directly or indirectly (by it's child libraries).

Here is the full list of (currently) required libraries from composer report:

  - Installing sabberworm/php-css-parser (8.3.1): Loading from cache
  - Installing phenx/php-svg-lib (v0.3.3): Loading from cache
  - Installing phenx/php-font-lib (0.5.2): Loading from cache
  - Installing dompdf/dompdf (v0.8.6): Loading from cache

So, all these libraries should be added to ludwig.json file in order for Entity Print module to work nicely in full capacity.

In other words, this means that Entity Print module is on the edge of being convenient to be managed by Ludwig. Proper Ludwig support would require some manual work from Entity Print module maintainers when new release is published, plus some manual work from site managers when module update time comes.

devad’s picture

Title: Ludwig integration (installation without composer) » Entity Print - Ludwig integration abandoned
devad’s picture

Title: Entity Print - Ludwig integration abandoned » Entity Print - Ludwig integration given up
mmjvb’s picture

Title: Entity Print - Ludwig integration given up » Support installation using Ludwig
Status: Closed (won't fix) » Needs work

Sounds like the three libraries mentioned in #11 are needed as well.

Obviously, the dependency management is for the users, not the maintainers of this module. Would consider it their decision to support this or not.

devad’s picture

@mmjvb

Dependency management with Ludwig is simple if you have 1 or 2 PSR dependencies.

Here is a kind of mess which can arise if you have more libraries to manage by Ludwig. Example is from Search Api Solr project which abandoned Ludwig integration because it's issue queue had been flooded with ludwig issues:

#3082306: Fatal Error with Symfony Event Dispatcher when installing via ludwig instead of composer
#3082582: Search API Solr - Dropped Ludwig support

No one can handle such a mess. Except Composer of course. :)

Entity Print module do not have a lot of library dependencies (4), so it is up to mainteners to decide to add official Ludwig support or not.

devad’s picture

devad’s picture

Title: Support installation using Ludwig » Entity Print - Ludwig implementation
devad’s picture

devad’s picture

Title: Entity Print - Ludwig implementation » Entity Print - Ludwig integration
devad’s picture

StatusFileSize
new1.22 KB

The dompdf/dompdf library has "classmap" autoload part which is not supported by Ludwig yet.

New Ludwig 8.x-1.1 will display a warning about the 'classmap' autoload type for dompdf/dompdf library.

Read more at comment #15 here: #2914840-15: Add support for 'classmap' and 'files' autoload types

Manual integration with Ludwig is possible still, with one-line addition to entity_print.module file described in comment #9 in the same issue.

The all-in-one patch is attached.

The new Ludwig 8.x-1.1 will display a warning about the 'classmap' autoload type for dompdf/dompdf library still, but with require_once('lib/dompdf-dompdf/v0.8.6/autoload.inc.php'); added to entity_print.module file you can safely ignore the warning.

devad’s picture

Here is the extended ludwig.json file for those who would like to use an optional mikehaertl-phpwkhtmltopdf library for printing.

I have tested. The mikehaertl-phpwkhtmltopdf library and all of its dependencies are standard PSR-4 libraries and they work nicely with Ludwig.

{
  "require": {
    "sabberworm/php-css-parser": {
      "version": "v8.3.1",
      "url": "https://github.com/sabberworm/php-css-parser/archive/8.3.1.zip"
    },
    "phenx/php-svg-lib": {
      "version": "v0.3.3",
      "url": "https://github.com/phenx/php-svg-lib/archive/v0.3.3.zip"
    },
    "phenx/php-font-lib": {
      "version": "v0.5.2",
      "url": "https://github.com/phenx/php-font-lib/archive/0.5.2.zip"
    },
    "dompdf/dompdf": {
      "version" : "v0.8.6",
      "url": "https://github.com/dompdf/dompdf/releases/download/v0.8.6/dompdf_0-8-6.zip",
      "disable_warnings": "TRUE"
    },
    "mikehaertl/php-shellcommand": {
      "version": "v1.6.2",
      "url": "https://github.com/mikehaertl/php-shellcommand/archive/1.6.2.zip"
    },
    "mikehaertl/php-tmpfile": {
      "version": "v1.1.6",
      "url": "https://github.com/mikehaertl/php-tmpfile/archive/1.1.6.zip"
    },
    "mikehaertl/phpwkhtmltopdf": {
      "version": "v2.4.2",
      "url": "https://github.com/mikehaertl/phpwkhtmltopdf/archive/2.4.2.zip"
    }
  }
}

Please, note also that an another optional tecnickcom/tcpdf printing library is the 'classmap' autoload type and its integration with current Ludwig 8.x-1.1 is not supported.

devad’s picture

Title: Entity Print - Ludwig integration » Entity Print - Add Ludwig integration
Status: Needs work » Needs review
devad’s picture

StatusFileSize
new1.26 KB

Ludwig 8.x-1.2 released few days ago has added a new ludwig.json option: "disable_warnings": "TRUE"

This option can be used nicely by Entity Print module to suppress a "Classmap autoload type is not supported" warning for dompdf/dompdf library which is implemented manually inside .module file.

This is just an UX improvement. New patch attached.

Interdiff is just:

-      "url": "https://github.com/dompdf/dompdf/releases/download/v0.8.6/dompdf_0-8-6.zip"
+      "url": "https://github.com/dompdf/dompdf/releases/download/v0.8.6/dompdf_0-8-6.zip",
+      "disable_warnings": "TRUE"
devad’s picture

StatusFileSize
new1.77 KB

Hi

This is the improved patch which adds integration in entity_print.module file independent of future library version changes.

devad’s picture

StatusFileSize
new1.79 KB

Moving "if Ludwig module exists" part of code to the Helper function for simplicity reasons.

devad’s picture

StatusFileSize
new2.03 KB

Moving the Ludwig Helper function 'ludwig_require_once' to new ludwig.inc file so that any script (.module, .install, ...) can require it in the future if needed.

A note for Entity Print module maintainers

Please, note that with patch #26 in place, if the new version of dompdf/dompdf library will be required by some future Entity Print module release, only ludwig.json file will need to be updated accordingly to mirror the new composer.json file.

So, maintaining of Ludwig integration will take just a few minutes for maintainers once in a few months... or years... depending on how often the dompdf/dompdf library versions change.

If you would like to make happy all the Drupal 8/9 users not familiar with Composer yet - you can add the official Ludwig integration to Entity Print module (by committing patch #26).

Ludwig module has nice and very detailed documentation added to Drupal.org recently.

Ludwig is improved a lot in last 2 months, including stabile D9 release.

It has 6700+ users currently and very steady Weekly usage increase despite opinions that "Everybody is using Composer nowadays". :)

devad’s picture

StatusFileSize
new1.26 KB

Ignore this patch.

devad’s picture

StatusFileSize
new1.29 KB

In Ludwig ver. 8.x-1.5 a new Ludwig service is added which can be used instead of ludwig.inc file here.

The 'files' and 'classmap' libraries integration with Ludwig are more simple now.

New patch attached.

devad’s picture

Patch 28 is a different approach using new ludwig.require_once service. So, no need for interdiff.

devad’s picture

StatusFileSize
new1.3 KB

Patch reroll for new Ludwig 8.x-1.6 (due to slight service API change).

#2914840-20: Add support for 'classmap' and 'files' autoload types

One line interdiff:

-  $ludwig_require_once->ludwigRequireOnce('dompdf/dompdf', 'autoload.inc.php');
+  $ludwig_require_once->requireOnce('dompdf/dompdf', 'autoload.inc.php', dirname(__FILE__));
Duvan.Slabbert’s picture

Ran into some errors with Drupal 9.2.3 and PHP 8. I used some of patch 30 code to resolve issues and came up with this.

diff --git a/entity_print.module b/entity_print.module
index 0c372a4..967a590 100644
--- a/entity_print.module
+++ b/entity_print.module
@@ -12,6 +12,12 @@ use Drupal\Core\Form\FormStateInterface;
 use Drupal\Core\Url;
 use Drupal\entity_print\Renderer\ContentEntityRenderer;
 
+// Ludwig module integration.
+if (\Drupal::hasService('ludwig.require_once')) {
+  $ludwig_require_once = \Drupal::service('ludwig.require_once');
+  $ludwig_require_once->requireOnce('dompdf/dompdf', 'autoload.inc.php', dirname(__FILE__));
+}
+
 /**
  * Implements hook_theme().
  */
diff --git a/ludwig.json b/ludwig.json
new file mode 100644
index 0000000..ee765c2
--- /dev/null
+++ b/ludwig.json
@@ -0,0 +1,21 @@
+{
+  "require": {
+    "sabberworm/php-css-parser": {
+      "version": "v8.3.1",
+      "url": "https://github.com/sabberworm/PHP-CSS-Parser/archive/refs/tags/8.3.1.zip"
+    },
+    "phenx/php-svg-lib": {
+      "version": "v0.3.3",
+      "url": "https://github.com/PhenX/php-svg-lib/archive/refs/tags/v0.3.3.zip"
+    },
+    "phenx/php-font-lib": {
+      "version": "v0.5.2",
+      "url": "https://github.com/PhenX/php-font-lib/archive/refs/tags/0.5.2.zip"
+    },
+    "dompdf/dompdf": {
+      "version" : "v1.0.2",
+      "url": "https://github.com/dompdf/dompdf/releases/download/v1.0.2/dompdf_1-0-2.zip",
+      "disable_warnings": "TRUE"
+    }
+  }
+}
devad’s picture

Re: #31

Your PHP8 issue is not directly connected with Ludwig. It is a general issue with older versions of dompdf/dompdf library reported here:

#3227149: [PHP8] Update the recommended dompdf from 0.8.0 to 1.0.2

Thanks for reporting. New Ludwig patch very similar to your post #31 is here. Please try it and report back if it works for you.

Note: PHP8 tests fail is related to: #3227262: [PHP8] Tests fail

vortexcentrum’s picture

Hi

I know I'm being thick but I claim a steep learning curve after years of working in D5/6/7 and hating D8 so much I had a dalliance (divorce in progress) with WordPress.

D9 is, I'm learning, getting back to the idea that Drupal's success lay with the fact that it could be used by content creators without significant input from techies.

Ludwig is a major part of that puzzle. Thanks to everyone working on its integration. I really don't like using the command line on the server and, in any case, for some reason SSH doesn't like connecting from my location.

In relation to Entity Print (here's the really thick bit) of all the patches that have been posted here, is there one that resolves all the dependencies at once and, if so, which is it?

I'm on PHP7.4 or 7.3 depending on which site I'm working on.

Thanks.

devad’s picture

Re: #33

Patch #32 should be just fine. You can try it and report back if it works for you.

devad’s picture

vortexcentrum’s picture

@Devad

Thanks for the very prompt reply. I realise that I'm in a discussion with people who know what they are talking about and I'm struggling to keep up.

So I spent a long time this morning trying to identify what I'm doing wrong and how to solve it.

I also realise that it's far more likely that my problem is not specific or limited to this module but rather a my current lack of familiarity with all things D9.

So I'm sorry if I'm being a nuisance.

This is what I've done:

I first tried inserting the patch into entity_print_module here:

*****************

<?php

/**
* @file
* Print any entity.
*/

use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\entity_print\Renderer\ContentEntityRenderer;

diff --git a/entity_print.module b/entity_print.module
index 0c372a4..967a590 100644
--- a/entity_print.module
+++ b/entity_print.module
@@ -12,6 +12,12 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\entity_print\Renderer\ContentEntityRenderer;

+// Ludwig module integration.

******* et seq ****************

I cleared the cache, ran "Report > Packages" but there was no mention of entity print.

Next

I restored the original file entity_print_module.

Next I created ludwig.json on the desktop using a text editor to insert the full content of the patch and uploaded it by FTP to [site]/modules.entity_print.

Again, cleared the cache, ran the report and there was no mention of entity print.

I'm at a loss as to where I should put the patch.

I found https://www.drupal.org/docs/contributed-modules/ludwig/ludwig-integratio... by The Commerce Guys but Reports shows "Download and unpack missing packages (0)" and does not mention Entity Print. The page refers to a ""Download all missing libraries" button but I don't have that. I should say that it's working fine for Commerce and Stripe integration.

Can anyone set out an idiot's guide (for, not by, idiots) as to exactly what goes where and that assumes zero knowledge and will help many like me who are very happy to see Ludwig.

Thanks.

devad’s picture

Thanks @VortexCentrum. I have fixed the button name inconsistency inside Ludwig module documentation. Your reply was helpful.

Regarding your need for help with applying patches with Git... your question is not directly connected with this issue here. I will try to help you here with a few words and links... but if you will need more help I suggest that you post your questions at some Drupal or Git help forum... so that we do not continue to post here a bunch of off-topic questions.

----------

Here is a help link on how to apply a patch to Entity Print module:

https://www.drupal.org/node/2412091/git-instructions/8.x-2.x/nonmaintainer

If you have a zero knowledge about command line tools like Git I recommend that you learn it from scratch.

https://www.drupal.org/docs/develop/git/setting-up-git-for-drupal
https://www.drupal.org/docs/develop/git/introduction-to-drupal-git

It is a whole big new area to learn but once you learn it - it will make your developer life easier and you will be more ready to learn other useful command line tools like Composer and Drush.

If you are not ready to go to the learning way... this article can help you to properly understand all parts of the diff files and may help you to learn how to copy/paste needed line changes manually. If .diff file (.patch file) has just a few lines like in our case it might be a quick solution for you. There is also a helpful Wikipedia example here: https://en.wikipedia.org/wiki/Diff

------------

After you apply patch #32 properly to your files your entity_print.module file should have 5 new lines of code added between the previously existed lines.

... ... ... ...
use Drupal\Core\Url;
use Drupal\entity_print\Renderer\ContentEntityRenderer;

// Ludwig module integration.
if (\Drupal::hasService('ludwig.require_once')) {
  $ludwig_require_once = \Drupal::service('ludwig.require_once');
  $ludwig_require_once->requireOnce('dompdf/dompdf', 'autoload.inc.php', dirname(__FILE__));
}

/**
 * Implements hook_theme().
 */
... ... ... ...

And your newly created ludwig.json file should have this content:

{
  "require": {
    "sabberworm/php-css-parser": {
      "version": "v8.3.1",
      "url": "https://github.com/sabberworm/PHP-CSS-Parser/archive/8.3.1.zip"
    },
    "phenx/php-svg-lib": {
      "version": "v0.3.3",
      "url": "https://github.com/PhenX/php-svg-lib/archive/v0.3.3.zip"
    },
    "phenx/php-font-lib": {
      "version": "v0.5.2",
      "url": "https://github.com/PhenX/php-font-lib/archive/0.5.2.zip"
    },
    "dompdf/dompdf": {
      "version" : "v1.0.2",
      "url": "https://github.com/dompdf/dompdf/releases/download/v1.0.2/dompdf_1-0-2.zip"
    }
  }
}

Duvan.Slabbert’s picture

Updated patch for 8.x-2.6

Enviroment:
Drupal: 9.4.5
php: 8
Entity Print: 8.x-2.6

entity_print.module

use Drupal\entity_print\Renderer\ContentEntityRenderer;

if (\Drupal::hasService('ludwig.require_once')) {
  $ludwig_require_once = \Drupal::service('ludwig.require_once');
  $ludwig_require_once->requireOnce('dompdf/dompdf', 'autoload.inc.php', dirname(__FILE__));
}

/**
 * Implements hook_theme().
 */

ludwig.json

{
  "require": {
    "dompdf/dompdf": {
      "version": "v2.0.0",
      "url": "https://github.com/dompdf/dompdf/releases/download/v2.0.0/dompdf_2-0-0.zip"
    },
    "masterminds/html5": {
      "version": "v2.0.0",
      "url": "https://github.com/Masterminds/html5-php/archive/refs/tags/2.0.0.zip"
    },
    "phenx/php-font-lib": {
      "version": "v0.5.4",
      "url": "https://github.com/dompdf/php-font-lib/archive/refs/tags/0.5.4.zip"
    },
    "phenx/php-svg-lib": {
      "version": "0.4.0",
      "url": "https://github.com/dompdf/php-svg-lib/archive/refs/tags/0.4.0.zip"
    },
    "sabberworm/php-css-parser": {
      "version": "8.4.0",
      "url": "https://github.com/sabberworm/PHP-CSS-Parser/archive/refs/tags/8.4.0.zip"
    }
  }
}
devad’s picture

StatusFileSize
new1.26 KB

Here is a new patch with all library versions updated. Please review.

devad’s picture

dd 85’s picture

Status: Needs review » Reviewed & tested by the community

Patch #39 works great!
I strongly recommend that the maintainers add it to the next release of the module.

@devad thanks a lot!