Drupal 7 にローカル環境があり、mPDF ライブラリで Print モジュールを使用しています。
表示されないPDFの要素に背景のローカル画像を適用すると、それが見つからないことを示す赤いexはありませんが、呼び出すと
$mpdf->showImageErrors = true;
私のエラー ログには、PDF で画像が見つからないことが示されています。リンク全体を background-image プロパティに配置しても、何も機能しません。表示されているブラウザでアクセスしようとすると、画像が表示されます。Google からのランダムな画像へのリンクを使用すると、機能します。
イメージのパスへのアクセスを妨げている Drupal の何かがありますか?
後で編集:
これは私の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>
特別なことはしていません。指定したパスにイメージが存在します。そのアドレスにアクセスすると、ローカルで見ることができるからです。
PHP コードは、Print モジュールに常駐するコードです。showImageErrors 行のみを追加しました。コンテンツ エディターによって追加された画像は表示されますが、手動で HTML に追加された画像または CSS は表示されません。
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');
}