【问题标题】:MPDF not supporting image/icon rotationMPDF 不支持图像/图标旋转
【发布时间】:2018-07-11 12:41:08
【问题描述】:

我想从我的 HTML 脚本生成 PDF。现在脚本是

<?php

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();

$mpdf->WriteHTML('<div class="pageContatiner noSelect ui-droppable slctCon"><div onmousedown="objSelection(this)" ontouchstart="objSelection(this)" id="pmObj-1" class="shape obj" style="width: 136.217px; height: 136.217px; position: absolute; transform: matrix(-0.491017, -0.87115, 0.87115, -0.491017, 0, 0); margin-left: 312px; margin-top: 99px;" x="330" y="117" angle="240.59253473738065" scalex="1" scaley="1"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" height="136.2166748046875" width="136.2166748046875"><polygon class="svgObj" fill="rgba(51,122,183,1)" stroke="rgba(51,122,183,0.99)" stroke-width="1" points="96,100 50,5 4,100" width="136.2166748046875" height="136.2166748046875"></polygon></svg></div></div>');
$mpdf->Output();

?>

但问题是三角形图标显示没有旋转。

【问题讨论】:

  • 你想试试 PrinceXML (princexml.com) 吗?
  • @IVOGELOV 如果您有任何将 html 转换为 pdf 的示例脚本,请发给我吗?

标签: php mpdf html-to-pdf


【解决方案1】:

将您的 SVG 保存到文件并通过支持 CSS transform: rotate 属性的 img 元素链接它:

<img src="triangle.svg" id="pmObj-1" class="shape obj" style="transform: rotate(45deg);">

在supported CSS in the documentation上查看更多信息。

【讨论】:

    【解决方案2】:

    您可能想尝试PrinceXML - 它是一个 Linux 命令行工具,专门用于将 HTML + CSS 转换为可打印的 PDF。有一个PHP wrapper class 我一般是这样用的

    include_once("./inc/prince.php");
    
    if($template = @file_get_contents($tmpdir.'/temp/deal/custom/show/pr_offer3.htm'))
    {
      // populate/fill placeholders in your template with the real values
      // e.g. $template = str_replace('{PLACE_HOLDER}', $real_value, $template);
    
      // finally generate the PDF and send it to browser - the class offers
      // also possibility to save as file locally on server
      $prince = new Prince('/usr/bin/prince');
      header('Content-Type: application/force-download');
      header('Content-Disposition: attachment;  filename="offer_'.$_REQUEST['id'].'.pdf"');
      header('Content-Transfer-Encoding: binary');
      header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
      header('Pragma: public');
      ob_end_flush();
      $prince->setHTML(true);
      $prince->setBaseURL('http://my.domain.com'); // to resolve relative URLs in the HTML
      $prince->convert_string_to_passthru($template);
    }
    

    【讨论】:

      猜你喜欢
      • 2020-10-29
      • 2019-11-25
      • 2013-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多