Hi All,

I am trying to generate a membership card that our members can print out and carry with them.

I can create the card, populate it with name and expire date from database and view it fine with this code:

<?php
include_once 'includes/auth.php';
include 'includes/dbconnect.php';
?>
<style type="text/css">
<!--
#container {
width: 352px;
height:200px;
background-image: url(http://mywebsite.org/members/images/membership-card-bg.jpg);
background-repeat:no-repeat;
}

.card-font {
font-size:12px;
}
-->
</style></head>

<body>
<?php
// Get member information
$username = $_SESSION['username'];
$result = mysql_query("SELECT * FROM members WHERE EMAIL = '$username' LIMIT 1");
$row = mysql_fetch_array($result) or die(mysql_error());
?>
<div id="container">
<table width="350" height="195" border="0">
<tr>
<td height="141" colspan="2">&nbsp;</td>
</tr>
<tr>
<td width="21" height="21" class="card-font">&nbsp;</td>
<td width="319" class="card-font"><strong>Member Name:</strong> <?php print "$row[FIRST_NAME]"; ?><?php print " $row[LAST_NAME]"; ?></td>
</tr>
<tr>
<td height="25" class="card-font">&nbsp;</td>
<td height="25" class="card-font"><strong>Valid Through:</strong> <?php print "$row[PAID_THRU]"; ?></td>
</tr>
</table></div>
<p >&nbsp;</p>
</body>
</html>

BUT, the background does not print. So I am now trying to convert the above into a pdf, then print the new pdf with background intact. I am using DOMPDF (http://www.digitaljunkies.ca/dompdf) and I did get it working fine with a test image.

My question is how can I enter the code above where they want it (code below) where it defines $html

<?php
require_once("dompdf_config.inc.php");
include_once '../../members/includes/auth.php';
include '../../members/includes/dbconnect.php';

// Get member information
$username = $_SESSION['username'];
$result = mysql_query("SELECT * FROM members WHERE EMAIL = '$username' LIMIT 1");
$row = mysql_fetch_array($result) or die(mysql_error());

$html =
'<html><body>'.
'<p>Put your html here, or generate it with your favourite '.
'templating system.</p>'.
'</body></html>';

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("Membership-Card.pdf");

?>

Thank you for any help!

Scott

    you can turn background printing on and off in most browsers.
    File>page setup in fire fox, not sure where in IE

      Thanks Dagon, but we have over 1200 members and it would be better if we don't have to "e-x-p-l-a-i-n" too much to them.🙂

      Thanks again.

        instead of sending the html to screen, put it in a var and feed it in to dompdf

          I knew I had to do something like that, but that is a little over my php experience level.

          Would you explain a bit more, with an example would be great.

          Thanks again.

            you need to write a valid html document, but this is a start

            
            <?php
            include_once 'includes/auth.php';
            include 'includes/dbconnect.php';
            
            
            // Get member information
            $username = $_SESSION['username'];
            $result = mysql_query("SELECT * FROM members WHERE EMAIL = '$username' LIMIT 1");
            $row = mysql_fetch_array($result) or die(mysql_error());
            
            
            $html = <<<EOD
            
            <style type="text/css">
            <!--
            #container {
            width: 352px;
            height:200px;
            background-image: url(http://mywebsite.org/members/images/...-card-bg.jpg);
            background-repeat:no-repeat;
            }
            
            .card-font {
            font-size:12px;
            }
            -->
            </style></head>
            
            <body>
            
            
            <div id="container">
            <table width="350" height="195" border="0">
            <tr>
            <td height="141" colspan="2">&nbsp;</td>
            </tr>
            <tr>
            <td width="21" height="21" class="card-font">&nbsp;</td>
            <td width="319" class="card-font"><strong>Member Name:</strong> <?php print "$row[FIRST_NAME]"; ?><?php print " $row[LAST_NAME]"; ?></td>
            </tr>
            <tr>
            <td height="25" class="card-font">&nbsp;</td>
            <td height="25" class="card-font"><strong>Valid Through:</strong> <?php print "$row[PAID_THRU]"; ?></td>
            </tr>
            </table></div>
            <p >&nbsp;</p>
            </body>
            </html>
            EOD;
            
            require_once("dompdf_config.inc.php");
            include_once '../../members/includes/auth.php';
            include '../../members/includes/dbconnect.php';
            
            // Get member information
            $username = $_SESSION['username'];
            $result = mysql_query("SELECT * FROM members WHERE EMAIL = '$username' LIMIT 1");
            $row = mysql_fetch_array($result) or die(mysql_error());
            
            
            
            
            $dompdf = new DOMPDF();
            $dompdf->load_html($html);
            $dompdf->render();
            $dompdf->stream("Membership-Card.pdf");
            
            ?>
            
              Write a Reply...