Skip to content
Advertisement

DOMPDF images have poor quality when processing in server

I am working on a website with different jQuery forms that output to a html result page, this html is converted to a pdf file with DOMPDF library. When the conversion is made in local, there is no problem, but when it takes place in the server, the resulting pdf images have lower quality than the originals, with white scratches and blur (I can upload an example if necessary).

Doing some research, I tried the following solutions:
– tried different image formats (jpg, png, gif)
– tried different values for “DOMPDF_PDF_BACKEND” (rendering backend to use) (CPDF, PDFLib, GD)
– tried different “DOMPDF_DPI” values
– “DOMPDF_ENABLE_REMOTE” value is set to “true”
– tried opening the resulting pdf with different applications (ubuntu pdf viewer, adobe acrobat pdf, gimp, photoshop)

all with the same result.

Also took a look at phpinfo() both in local and server:

PHP version
local: PHP Version 5.5.11
server: PHP Version 5.3.29

GD version:
both: bundled (2.1.0 compatible)

GD FreeType Version :
local: 2.4.8
version: 2.4.9

libPNG Version:
local: 1.5.9
server: 1.2.49


I don’t know what other parameters to compare.

I don’t know what else to try.

Thanks in advance.

Advertisement

Answer

Thanks for the anwswer, I saw that post yesterday, I had tried different image formats, but I had pending playing with the libraries.

Finally, commenting out the code regarding the imagick image processing “// Use PECL imagick + ImageMagic to process transparent PNG images” solved the problem, that was due to images containing transparencies (alpha) such as png and gif.

// Use PECL imagick + ImageMagic to process transparent PNG images
}elseif (extension_loaded("imagick")) {
  $imagick = new Imagick($file);
  $imagick->setFormat('png');

  // Get opacity channel (negative of alpha channel)
  $alpha_channel = clone $imagick;
  $alpha_channel->separateImageChannel(Imagick::CHANNEL_ALPHA);
  $alpha_channel->negateImage(true);
  $alpha_channel->writeImage($tempfile_alpha);

  // Cast to 8bit+palette
  $imgalpha_ = imagecreatefrompng($tempfile_alpha);
  imagecopy($imgalpha, $imgalpha_, 0, 0, 0, 0, $wpx, $hpx);
  imagedestroy($imgalpha_);
  imagepng($imgalpha, $tempfile_alpha);

  // Make opaque image
  $color_channels = new Imagick();
  $color_channels->newImage($wpx, $hpx, "#FFFFFF", "png");
  $color_channels->compositeImage($imagick, Imagick::COMPOSITE_COPYRED, 0, 0);
  $color_channels->compositeImage($imagick, Imagick::COMPOSITE_COPYGREEN, 0, 0);
  $color_channels->compositeImage($imagick, Imagick::COMPOSITE_COPYBLUE, 0, 0);
  $color_channels->writeImage($tempfile_plain);

  $imgplain = imagecreatefrompng($tempfile_plain);

}

Then it would use the “}else{” option that extracts the image without alpha channel.

You can also disable imagick module in the php.ini

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement