我在Drupal 7中有一个本地环境,并且正在使用带有mPDF库的打印模块。
当我在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 module中的代码。我只添加了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');
}