I have a local environment in Drupal 7 and I am using the Print module with the mPDF library.
When I apply a background local image to an element in the PDF it doesn't show, I don't have a red ex indicating that it cannot find it, but when I call
$mpdf->showImageErrors = true;
my error log tells me that my PDF cannot find the image, I even put the whole link in the background-image property and still, nothing works. The image is there if I try accessing it in the browser it shows. If I use a link to a random image from google, it works.
Is there something from Drupal preventing access to the image's path?
LATER EDIT:
So this is my CSS & HTML:
.field-name-body blockquote {
background-color: #f9f9f9;
background-image: url("https://local-website.dd:8443/profiles/local/themes/bootstrap_subtheme/img/pdf-icons/quote.png");
/*background-image: url("/<?php //print drupal_get_path('theme', 'bootstrap_subtheme')?>/img/pdf-icons/quote.png");*/
background-position: 24px 24px;
background-repeat: no-repeat;
background-size: 24px;
border: none;
color: #25a898;
font-size: 14px;
line-height: 17px;
margin: 24px 0;
padding: 24px 24px 24px 52px;
}
<div class="field field-name-body field-type-text-with-summary field-label-hidden">
<div class="field-items">
<div class="field-item even">
<div class="field-item even">
<blockquote><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec risus nibh, mattis sed mi tincidunt, porta blandit nibh. Maecenas vulputate imperdiet augue, a tempus nulla venenatis vitae. Etiam rhoncus laoreet luctus. Phasellus dolor justo, tincidunt a eleifend vel, ornare nec dolor.</p>
</blockquote>
</div>
</div>
</div>
</div>
I am not doing anything special, my image resides in the path I specified because I can see it locally when I access that address.
The PHP code is the code that resides in the Print module. I only added the showImageErrors line. Images that are added by a content editor are visible, images added in HTML manually or CSS aren't.
function print_pdf_mpdf_print_pdf_generate($html, $meta, $paper_size = NULL, $page_orientation = NULL) {
module_load_include('inc', 'print', 'includes/print');
$pdf_tool = explode('|', variable_get('print_pdf_pdf_tool', PRINT_PDF_PDF_TOOL_DEFAULT));
// Version 7 of the mpdf library uses a composer autoloader.
// Also there no longer is way to truly detect the library version, so this
// seems like the best alternative.
$mpdf_version_7_plus = strpos($pdf_tool[1], 'autoload.php') !== FALSE;
if (empty($paper_size)) {
$paper_size = variable_get('print_pdf_paper_size', PRINT_PDF_PAPER_SIZE_DEFAULT);
}
if (empty($page_orientation)) {
$page_orientation = variable_get('print_pdf_page_orientation', PRINT_PDF_PAGE_ORIENTATION_DEFAULT);
}
$images_via_file = variable_get('print_pdf_images_via_file', PRINT_PDF_IMAGES_VIA_FILE_DEFAULT);
$config = array();
if ($mpdf_version_7_plus) {
$config['tempDir'] = drupal_realpath('public://print_pdf/print_pdf_mpdf/');
}
else {
// Deprecated since mpdf v7.x.
if (variable_get('print_pdf_autoconfig', PRINT_PDF_AUTOCONFIG_DEFAULT)) {
if (!defined('_MPDF_TTFONTDATAPATH')) {
define('_MPDF_TTFONTDATAPATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/ttfontdata/'));
}
if (!defined('_MPDF_TEMP_PATH')) {
define('_MPDF_TEMP_PATH', drupal_realpath('public://print_pdf/print_pdf_mpdf/tmp/'));
}
}
}
$tool_path = DRUPAL_ROOT . '/' . $pdf_tool[1];
if (file_exists($tool_path)) {
require_once $tool_path;
}
else {
watchdog('print_pdf', 'Configured PDF tool does not exist at path: %path', array('%path' => $tool_path), WATCHDOG_ERROR);
throw new Exception("Configured PDF tool does not exist, unable to generate PDF.");
}
$format = ($page_orientation == "landscape") ? $paper_size . "-L" : $paper_size;
// Try to use local file access for image files.
$html = _print_access_images_via_file($html, $images_via_file);
// Set document information.
if ($mpdf_version_7_plus) {
$config['mode'] = 'utf-8';
$config['format'] = $format;
$mpdf = new \Mpdf\Mpdf($config);
}
else {
$mpdf = new mPDF('UTF-8', $format);
}
if (isset($meta['name'])) {
$mpdf->SetAuthor(strip_tags($meta['name']));
}
$mpdf->SetCreator(variable_get('site_name', 'Drupal'));
$mpdf->WriteHTML($html);
// Try to recover from any warning/error.
ob_clean();
return $mpdf->Output('', 'S');
}