php - 是否支持 Dompdf 最大高度最大宽度?

标签 php css dompdf

我试图将图像限制为最大高度和宽度。所以我很自然地使用最大高度和最大宽度,这样图像在达到最大值时可以保持其纵横比。在 html 中工作,这是我的代码片段

'<table class="seperate" id="images-table">'.   
        '<tbody>'.
          '<tr>'.
            '<td>&nbsp;</td>'.
            '<td class="uscs-logo" ><img src="http://localhost/dompdfTest/dompdf/uscompliancesystems_logo.png" /></td>'.

            '<td class="signature-logo" ><img src="http://localhost/dompdfTest/dompdf/USCSDefaultSignature.jpg" /></td>'.
            '<td>&nbsp;</td>'.
          '</tr>'.
        '</tbody>'.
    '</table>'.

还有CSS:

table#images-table .uscs-logo {
  height: 100px;
  text-align: left;

}

table#images-table .uscs-logo img{
    max-height:200px;
    max-width: 200px;
}
table#images-table .signature {
  height: 125px;
  text-align: right;
  width: 300px;
  height: auto;
  max-height:200px;
  max-width: 200px;
}

但我在 pdf 中得到的是一个两页的 pdf,页面上没有图像,因为它们是全尺寸的。如果我在页面中呈现 html,结果很好。

所以我的问题是,img 标签上的 dompdf 真的支持最大宽度和最大高度吗?

最佳答案

使用 GD PHP 扩展动态调整图像大小并不难。就时间成本而言,如果您不这样做,浏览器必须进行扩展。

$filename ='/home/user/public_html/images/image.jpg';
$image = @imagecreatefromjpeg();
$originalWidth  = imagesx($image);
$originalHeight = imagesy($image);
$scale      = min($desiredWidth/$originalWidth, $desiredHeight/$originalHeight);
$newWidth  = ceil($scale*$originalWidth);
$newHeight = ceil($scale*$originalHeight);
$newPic = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($newPic, $image,0, 0, 0, 0,$newWidth, $newHeight, $originalWidth, $originalHeight);
if (imagejpeg($newPic,$tmpfile)){rename($tmpfile,$filename);}

并恢复内存清理。

imagedestroy($image);
imagedestroy($newPic);

关于php - 是否支持 Dompdf 最大高度最大宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28092211/

相关文章:

php - 从窗口调度程序执行php脚本而不显示cmd弹出窗口

php - 使用Google Spreadsheet API获取通过过滤器 View 过滤的值

php - 谷歌存储桶的签名 URL 与提供的签名不匹配

html - 向 flex 元素添加滚动

php - 寻找一个快速的库来使用 PHP 呈现 PDF 文件

php - fatal error : Class 'TCPDF' not found

HTML:样式 float 和导航样式之间的冲突?

javascript - 通过淡入使 div 可见

php - 带有西里尔字符的 DOMPDF 问题

css - DOMPDF - 如何将 PDF 呈现为完全没有边距?