Error generating document: Failed to generate PDF with DOMPDF

Created on 29 March 2017, over 7 years ago
Updated 18 January 2023, almost 2 years ago

I have installed Entity Print on Drupal core 8.2.6

The following is my configuration:

Enable Default CSS
Force Download
Default PDF engine for printing = Dompdf
Paper Size = Letter
Paper Orientation = Portrait
Enable HTML5 Parser
Enable Remote URLs

When clicking View print via the Entity Print block, the following error is displayed:

Error generating document: Failed to generate PDF: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known, file_get_contents(http://dev2.uspnf.com/sites/default/files/css/css_w6e_sNVvIjxEWdBNonpUitS4mheMH0BuAKcTwMQ-YG8.css?onlc1k): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known, Unable to load css file http://dev2.uspnf.com/sites/default/files/css/css_w6e_sNVvIjxEWdBNonpUitS4mheMH0BuAKcTwMQ-YG8.css?onlc1k

--------------------------
Potentional solution
This issue is not in the module scope. The reason is using file_get_contents() from pdf library. Dompdf library doesn't see your file cause your host may not be visible for the webserver. It often happens when you use Lando or any other kind of docker virtualization.

So put this code in your settings.php

for nginx:
$settings['file_public_base_url'] = 'http://nginx/sites/default/files';

for lando:
$settings['file_public_base_url'] = 'http://appserver_nginx/sites/default/files';

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States sassafrass

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs review almost 2 years ago
  • πŸ‡§πŸ‡ͺBelgium kwinten-hardies Vlaams-Brabant

    I have the same error as #110 πŸ› Error generating document: Failed to generate PDF with DOMPDF Needs work With patch from 118 and entity_print 2.11 and dompdf v1.2.2 as v2.0.1. But even with dompdf v2.0.1 it's not working.

  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    v2.0.1 of dompdf is working for us with the latest entity_print release.
    This patch is still working for me provided that I put in a base_url

    I have some css resources that it otherwise can't load and throws an error if the base_url isn't set thanks to the patch.

    This is the patch that we're using. Otherwise http://default/sites/default/files/css/xyz.css never resolves to our css
    but when we put http://domain.docker.localhost into the base_url setting provided by this patch number 116, it works.

        "drupal/entity_print": {
          "2865185 - DomPDF incorrect url internally to docker container, override with setting.": "https://www.drupal.org/files/issues/2023-01-18/entity_print-dompdf_base_url-2865185-116.patch"
        },
  • πŸ‡¦πŸ‡ΊAustralia sonnykt Melbourne, Australia

    @Rar9 @kwinten-hardies you should probably check the output HTML for printing. Do you have HTML5 Parser enabled for Dompdf plugin?

  • πŸ‡©πŸ‡ͺGermany Rar9

    Html parser is enabled, and base url is defined to point to our css.

    Watch the html for what?

  • πŸ‡¦πŸ‡ΊAustralia sonnykt Melbourne, Australia

    @Rar9 probably check for malformed HTML. The error message from dompdf likely relates to the HTML structure instead of remote assets.

  • πŸ‡¦πŸ‡ΊAustralia sonnykt Melbourne, Australia

    I notice that Entity Print 8.x-2.11 introduced a new root setting Base URL:

    It also has the entity_print.post_render_subscriber event subscriber to change all root relative URIs in <link href>, <a href>, and <img src> into absolute URLs using the new base URL setting above.

    I have tried to remove the patch from this issue and instead use that new Base URL setting and notice that dompdf is still able to load CSS/images on my Docker-based project.

    I wonder if this issue is still valid with the new setting.

  • πŸ‡©πŸ‡ͺGermany macdev_drupal Wiesbaden

    For me, it seems like this new Base_url field in entity_print 2.11 does not work for us.

    We have differences between stages, we are coping with like installations which can not curl themselves at all, installations which can curl only via localhost, installations which can resolve their domain names and docker / ddev for development.
    And then there is multisite, we have to deal with. Further, we are using it with webform, which has some special issues when private files and the signature field are used.

    I got it working in ddev / docker, but not at installations which can call themselves only via localhost. It, too, seems that the file:/// syntax is not supported.
    If the patch is applied against 2.11 it doesn't work either. I guess the base_url field form module needs to be overridden to bring back the previous behavior.
    Meanwhile, I'll roll back to the patched 2.7 and try to figure out if a differently patched 2.11 would be an option.

  • Status changed to Needs work over 1 year ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    With this there are now two base url fields, so we need to rework it to use the root base url field

  • πŸ‡¦πŸ‡ΊAustralia gigimaor Narangba/Brisbane

    This patch works for me on Drupal 10

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    54 pass
  • πŸ‡¨πŸ‡¦Canada sillygwailo Toronto, ON
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    54 pass
  • πŸ‡¨πŸ‡·Costa Rica jorgewray93

    The issue continue for me, comparing the patch 113 and the patch 129, I see that two lines are not adding in the patch 129.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    54 pass
  • πŸ‡¦πŸ‡ΊAustralia alex.skrypnyk Melbourne

    Re-rolled #132 + fixed coding standards for version 2.13

  • First commit to issue fork.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    54 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    54 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    54 pass
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    54 pass
  • πŸ‡¦πŸ‡ΊAustralia jannakha Brisbane!

    ready for review MR https://git.drupalcode.org/project/entity_print/-/merge_requests/19/diffs

    patches were not up to date with latest version (and were not tested as base_url was not even passed through)

    can we please stick to git-flow with patches?

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    54 pass
  • πŸ‡¦πŸ‡ΊAustralia sonnykt Melbourne, Australia

    Re-rolled patch file from #116 and #133 on the latest 8.x-2.13. This new patch now uses the root base_url setting from entity_print.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update about 1 year ago
    54 pass
  • πŸ‡¨πŸ‡·Costa Rica jorgewray93

    Adding the missing line in the patch #132

  • Status changed to RTBC about 1 year ago
  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    Re #137 The missing line was missing for a reason, it is not needed πŸ˜‰
    Re #136 Your patch is omitting a fix from the MR and adding a schema field which is unused in this issue? If it's missing it should be added in it's own issue, not as part of a different issue.

    Re #134/#135 I reviewed the merge request and to me this seems okay. The Base URL is properly passed now.

    Let's stick to the MR now.

  • Status changed to Needs work 12 months ago
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10

    Can we get an issue summary update here and have the redundant MRs and patches hidden.

    There are two MRs so I'm not sure which one is RTBC

    Additionally the issue summary talks about the issue being something to do with settings.php, let's update it to reflect the new approach.

  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    Let's stick with the latest MR as it's more complete as the other patches.

  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    BramDriesen β†’ changed the visibility of the branch 2865185-error-generating-document to hidden.

  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ
  • Status changed to Needs review 3 months ago
  • πŸ‡¨πŸ‡¦Canada joseph.olstad

    I have developed a patch for the dompdf library that works around this issue or most Drupal 10+ sites that are using docker setups with reverse proxy issues or other issues with certificates. Total workaround.
    Here it is:

                "dompdf/dompdf": {
                    "2865185 or https://github.com/drupalwxt/docker-scaffold/issues/43": "https://github.com/user-attachments/files/17000656/dompdf_change_local_http_uri_to_a_file.patch.txt"
                },
    
  • Status changed to RTBC 14 days ago
  • πŸ‡ΊπŸ‡ΈUnited States mkindred

    I applied MR19 against core 10.3.9 and entity_print 8.x-2.15, and it's working great. This MR fixes my css rendering issues in local docker containers via the base_url setting already in entity_print.settings.

  • πŸ‡§πŸ‡ͺBelgium BramDriesen Belgium πŸ‡§πŸ‡ͺ

    Issue summary still needs to be updated.

  • πŸ‡­πŸ‡·Croatia milosr Croatia, Montenegro
Production build 0.71.5 2024