Problem/Motivation

When I updated the DomPDF library to v0.8.6 I suffer some problems with relative images, searching on dompdf, aparently DomPDF does not support internal images. This same problem exists for v0.8.0+ when using S3 as the Drupal file system.

Steps to reproduce

Use a relative internal image path on /admin/commerce/config/billy-invoice/pdf Logo section. For example "/sites/all/themes/custom/my_theme/images/pdf-logo.jpg". Or, use a full path to an image hosted on AWS S3 when the Drupal file system has been replaced with the s3fs module.

Proposed resolution

Determine if the invoice logo file exists, and its proper path based on the relative or full path entered into the settings configuration. If it does exist, retrieve its contents through base64 encoding. If it does not exist, display no logo and write an error message to watchdog.

Comments

eduardo morales alberti’s picture

Updated patches for 7.x-1.3 and 7.x-1.x with the changes necessary to work images with v0.8.0+ versions.

eduardo morales alberti’s picture

4kant’s picture

Thanks Eduardo,

patch in #3 works for me! ;-)

shaneonabike’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm that this issue is working properly. It would be great if this could be included in a release.

klausi’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update

Thanks, I think the approach makes sense. I like the base64 encoding more than allowing remote files.

  1. +++ b/modules/commerce_billy_pdf/commerce_billy_pdf.module
    @@ -233,11 +233,25 @@ function commerce_billy_pdf_commerce_order_view($order, $view_mode) {
    + * @return string
    

    There should be an empty line after the @param section

  2. +++ b/modules/commerce_billy_pdf/commerce_billy_pdf.module
    @@ -233,11 +233,25 @@ function commerce_billy_pdf_commerce_order_view($order, $view_mode) {
    +  $imageData = base64_encode(file_get_contents($image_path));
    

    we should first check if the file exists and only then do the base64 encoding. We should write a watchdog error if the file does not exist.

    We also don't want to support remote files for security reasons, so the file_exists() check is correct.

Can you update the issue summary and fix the minor things I found?

sgdev’s picture

I have created a revised patch for review and an interdiff. I will also update the issue summary.

Per this patch I wrote in 2019 (https://www.drupal.org/project/commerce_billy/issues/3081653), there is also a critical 0.8.0+ issue with the invoice logo that does not allow it to work when the local file system has been replaced with S3, as is the case for our sites.

Given it is clear from this thread that the wish is to avoid the use of isRemoteEnabled, the patch in #3 has been modified to include @klausi's recommendations, and to support the use of full paths that reconcile with available Drupal file system schemes. Therefore, users can enter relative paths, and paths that are prefixed by https://, public://, s3://, etc., as long as the path reconciles to a Drupal scheme.

Please review and let me know your feedback, thank you.

sgdev’s picture

Title: Relatives images are not supported on DomPDF v0.8.0+ » Relative and S3 images are not supported on DomPDF v0.8.0+
Issue summary: View changes
Issue tags: -Needs issue summary update
klausi’s picture

Title: Relative and S3 images are not supported on DomPDF v0.8.0+ » Relative images are not supported on DomPDF v0.8.0+
Status: Needs review » Needs work

Thanks Ron, very sorry to bump this back again.

I think we should not mix 2 issues here. The S3 and other file system support should be a separate issue. Let's fix the simple base64 approach here first to get that out of the way.

So we should have a relatively short patch hear based on Eduardo's patch above.

sgdev’s picture

@klausi, that's fine. Was trying to incorporate both since I'm always concerned when will be the next time someone might look at these old patches and make a commit.

I'll re-roll the patch, and open the other issue with a separate patch for S3.

sgdev’s picture

Status: Needs work » Needs review
StatusFileSize
new1.75 KB
new2.03 KB

See attached patch and interdiff, thanks.

  • klausi committed 1aee863 on 7.x-1.x authored by ron_s
    fix(dompdf): Relative images are not supported on DomPDF v0.8.0+ (#...
klausi’s picture

Status: Needs review » Fixed

Thanks!

+++ b/modules/commerce_billy_pdf/commerce_billy_pdf.module
@@ -226,11 +226,35 @@ function commerce_billy_pdf_commerce_order_view($order, $view_mode) {
+  watchdog('commerce_billy_pdf', 'Invoice logo does not exist or cannot be found: <em>%path</em>',

this will create double em tags, the %placeholder already adds them.

Fixed that and committed it!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.