php - MPDF not supporting image/icon rotation


I would like to generate a PDF from my HTML script.Now the script is


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

$mpdf = new \Mpdf\Mpdf();

$mpdf->WriteHTML('<div ><div onmousedown="objSelection(this)" ontouchstart="objSelection(this)" id="pmObj-1"  x="330" y="117" angle="240.59253473738065" scalex="1" scaley="1"><svg xmlns="" version="1.1" xmlns:xlink="" height="136.2166748046875" width="136.2166748046875"><polygon 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>');


But the problem is here the triangle icon is showing without rotation.




Save your SVG to a file and link it through animg element which supports CSStransform: rotate property:

<img src="triangle.svg" id="pmObj-1" >

See more on supported CSS in the documentation.




You may want to try PrinceXML - it is a Linux command-line tool specifically designed to convert HTML + CSS into print-ready PDF. There is a PHP wrapper class and I usually use it like this


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');
  $prince->setBaseURL(''); // to resolve relative URLs in the HTML

People are also looking for solutions to the problem: javascript - Google Charts -- Chart not changing on selection


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.