amitdivya / dompdf

Automatically exported from code.google.com/p/dompdf
0 stars 0 forks source link

max-width and max-height property not working for images #442

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I have some quite a few images Large and small and I want to use the max-height 
and max-width property for these images, but I absolutely can't get it to work. 
They are always displayed in it's original dimensions.

I am using version 0.5.2

I'm working on MVC Codeigniter, here is the controller to generate the pdf:
function generate_pdf ($design_comp_id=false) {
        if (is_numeric($design_comp_id)) {
            error_reporting(E_ALL);
            $limit = (is_numeric($this->uri->segment(5))) ? $this->uri->segment(5) : 10;

            require_once($_SERVER['DOCUMENT_ROOT']."/application/libraries/dompdf/dompdf_config.inc.php");

            $data['compDetails'] = $this->designcomp->get ($design_comp_id, true);
            $data['results']     = $this->designcomp->getEntries (array('designcomps.designcompID' => ($design_comp_id*1)), 'entries.points DESC', $limit, 0, 'entries.*, users.uname, users.bio');

            $content = $this->load->view ('admin/designcomp/comp/entry_list_pdf', $data, TRUE);

            $dompdf = new DOMPDF();         
            $dompdf->load_html($content);
            $dompdf->render();
            $dompdf->stream("Designcomp-".$design_comp_id.".pdf");
        }
     }

And this is the View I want to convert to pdf:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <style type="text/css">
        body {
            width:560px;
            padding:0 20px;
            margin: 20px;
            font-family: Helvetica, Arial;
            font-size: 13px;
        }

        img {
            max-height:500px;
            max-width: 500px;       
        }               
    </style>
</head>

<body>

<?php
        $pageHeader = $compDetails['title'];
        $pageHeader .= ($compDetails['sectionID']=='5') ? " | Design the poster competition" : " | Design Brief competition";
        $pageHeader .= "<br />".$compDetails['date_live']." - ".$compDetails['date_vote_start']." - ".$compDetails['date_vote_end'];

        foreach ($results AS $row) {
                $img = '<img src="'.$_SERVER['DOCUMENT_ROOT'].'/media/designcomps/entries_'.$compDetails['designcompID'].'/large/'.$row['filename'].'" alt="by '.$row['uname'].'" />';
                //$img = '<img src="/media/designcomps/entries_'.$compDetails['designcompID'].'/large/'.$row['filename'].'" alt="by '.$row['uname'].'" />';
                echo '
                    <table style="width: 100%;">
                        <tr>
                            <td align="center" colspan="2" height="15">'.$pageHeader.'</td>
                        </tr>
                        <tr>
                            <td align="center" colspan="2"><h1 style="text-transform:uppercase; color:white; background-color:#9F63CE;">'.$row['uname'].' / '.$row['points'] .' points </h1></td>
                        </tr>
                        <tr>
                            <td align="center" style="text-align: center;" colspan="2">'.$img.'</td>
                        </tr>
                        <tr>
                            <td align="center" style="margin-right:15px; text-transform:uppercase; color:white; background-color:#9F63CE;">Entry Commentry</td>
                            <td align="center" style="text-transform:uppercase; color:white; background-color:#9F63CE;">Artist Profile </td>
                        </tr>
                        <tr>
                            <td width="50%" style="margin-right:15px;text-align:justify; font-style: italic; padding:5px;">'.
                                str_replace('\n', '<br />', $row['description'])
                            .'</span></td>
                            <td width="50%" style="text-align:justify; font-style: italic; padding:5px;">'.
                                str_replace('\n', '<br />', $row['bio'])
                            .'</span></td>
                        </tr>
                    </table>
                    <p style="page-break-after: always">&nbsp;</p>';
        }
?>

</body>

</html>

Original issue reported on code.google.com by arlong...@gmail.com on 16 Mar 2012 at 10:38

GoogleCodeExporter commented 9 years ago
This does appear to be buggy. I can't get it to work with 0.6.0 beta 3, either.

FYI, we are no longer patching the 0.5.x code base so you will have to upgrade 
to 0.6.0 once the issue is addressed.

Original comment by eclecticgeek on 17 Mar 2012 at 3:00

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r483.

Original comment by fabien.menager on 25 Mar 2012 at 5:01

GoogleCodeExporter commented 9 years ago
Either this doesn't seem to be fixed, or the fix is only applied to the <img> 
tag, because I don't see it working, inline, on a <td> tag...

Original comment by erikmwoods on 23 Jan 2013 at 11:40

GoogleCodeExporter commented 9 years ago
I'm also unsure if max-height is supported... can anyone confirm whether it is 
or not?

Also to add more to my last comment: I know it may seem strange to ever use 
max-width on <td>, but I assure you that I've got a use case for emails.

Original comment by erikmwoods on 23 Jan 2013 at 11:57

GoogleCodeExporter commented 9 years ago
@erikmwoods this doesn't look to have been addressed with regard to tables, 
which receive different treatment from block or inline elements. You might want 
to open a new issue since the original specifically targets images. Can you do 
that and post a test case? If so, please do so on github (we're transitioning 
to that platform): https://github.com/dompdf/dompdf/issues/

FYI, you can find this issue on github here: 
https://github.com/dompdf/dompdf/issues/448

Original comment by eclecticgeek on 24 Jan 2013 at 3:43

GoogleCodeExporter commented 9 years ago

Original comment by eclecticgeek on 30 May 2013 at 5:16