Render Html as Image

Afdhal

New Member
I have a page with a form and button called preview. I need a method to generate a preview, converting the generated HTML to an image.Clicking on the preview button starts an ajax call to a controller action (I'm using Yii Framework), so I collected all the data from the form and generated a preview with the filled data. I need to convert the generated HTML to an image; in this way I'm able to re-size to my needed dimension.I've tried generating a .pdf on the fly and then generate the image from the pdf, and using mpdf extension and imagick. But imagick requires the pdf to be an existing file, while I prefer to generate a .pdf string with mpdf (I can't generate and delete a pdf for each click on preview button).What is a good method to generate an image from html or from pdf string generated "on the fly"?This is the code that I've used, but it return an error from imagick, saying image without dimension:\[code\] $html2pdf = Yii::app()->ePdf->mpdf('','A4'); $html2pdf->WriteHTML($this->render('preview', array("data" => $data, "imageProvider" => $arrayImage),true)); $content_PDF = $html2pdf->Output('', EYiiPdf::OUTPUT_TO_STRING); $im = new Imagick(); $im->readImageBlob( $content_pdf ); //$im->setIteratorIndex(0); $im->setResolution( 800, 600 ); $im->setImageFormat( "jpeg" ); header( "Content-Type: image/jpeg" ); echo $im->getImage();\[/code\]
 
Back
Top