?
Solved

PHP to PDF reduces the size of contents and page.

Posted on 2012-08-30
24
Medium Priority
?
1,149 Views
Last Modified: 2012-09-14
My problem is that when this creats the PDF the contents of document do not go to the bottom of the page, and at the same time the contents are reduced in size.
The results are undesireable and will not allow the PDF to print on AVERY Business Cards properly.
Is there a way to fix this code so that it will print a full 8.5 x 11 size (Letter) to its full dimensions? And do so without reducing the size of the content?
Thanks,
Sas
<?php
//http://www.ExpertsEx.com/_PDF3/CourtesyCard_PDF.php
$pDate = 'August 29, 2012';
$var1 = '15% Off Hotel Room';

//$fileName=$_POST['FileName'];
$fileName='sas.png';

$UniqueIdentity='646824600138'; //646824600158
$LogoART ='';
$A_phone ='(000) 555-5555';
$address = "1076 Expert Ave, LA, CA";
$account_name = 'Expert';

$content = '
<table border=4 width="100%" height="100%" color="#000000">
<TR><TD style="font-size:24px;font-family:ariel;">
Print using Avery Business Card Template # TBD

<BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>
<span style="font-size:12px; color:#FFFFFF;">
<P>&nbsp;.<P></span>
<img src="http://www.ExpertsEx.com/r/'.$UniqueIdentity.'/ART_logo/'.$fileName.'" width=385 border=0 alt="'.$account_name.'">
<center>
<span style="font-size:12px;font-family:ariel; color:#000000;"><center>'.$address.'</span>
<span style="font-size:38px;font-family:ariel; color:#840822;"><center>COURTESY CARD</span>
<!-- <span style="font-size:11px;font-family:ariel; color:#000000;"><center>Entitles only the bearer to:</span>&nbsp;<P> -->

<span style="font-size:11px;font-family:ariel; color:#000000;"><center>Valid For Barer Use Only</span>&nbsp;<P>
<span style="font-size:28px;font-family:ariel; color:#000000;"><center><B>'.$var1.'</B></span>&nbsp;<BR><BR>
<span style="font-size:18px;font-family:ariel; color:#000000;"><center>Expiration Date: '.$pDate.'</span></center>
<p align=right>
<BR>&nbsp;<BR>
<img src="http://www.ExpertsEx.com/ART/Transparent_Spacer.png" width=280 height=2 border=1>
<!--
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_LARGE.png" width=30 border=0 alt="">
<font size="3" color="#840822"><B>ExpertsEx</font><font size="2" color="#c0c0c0">.com</font></B>
-->
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_200x49.png" width=180 border=0 alt="ExpertsEx.com">


<span style="font-size:93px; color:#FFFFFF;">
<P>&nbsp;RJV<P></span>
<img src="http://www.ExpertsEx.com/r/'.$UniqueIdentity.'/ART_logo/'.$fileName.'" width=195 border=0 alt="'.$account_name.'">
<center>
<span style="font-size:12px;font-family:ariel; color:#000000;"><center>'.$address.'</span>
<span style="font-size:38px;font-family:ariel; color:#840822;"><center>COURTESY CARD</span>
<!-- <span style="font-size:11px;font-family:ariel; color:#000000;"><center>Entitles only the bearer to:</span>&nbsp;<P> -->

<span style="font-size:11px;font-family:ariel; color:#000000;"><center>Valid For Barer Use Only</span>&nbsp;<P>
<span style="font-size:28px;font-family:ariel; color:#000000;"><center><B>'.$var1.'</B></span>&nbsp;<BR><BR>
<span style="font-size:18px;font-family:ariel; color:#000000;"><center>Expiration Date: '.$pDate.'</span></center>
<p align=right>
<BR>&nbsp;<BR>
<img src="http://www.ExpertsEx.com/ART/Transparent_Spacer.png" width=280 height=2 border=1>
<!--
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_LARGE.png" width=30 border=0 alt="">
<font size="3" color="#840822"><B>ExpertsEx</font><font size="2" color="#c0c0c0">.com</font></B>
-->
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_200x49.png" width=180 border=0 alt="ExpertsEx.com">



<span style="font-size:93px; color:#FFFFFF;">
<P>&nbsp;RJV<P></span>
<img src="http://www.ExpertsEx.com/r/'.$UniqueIdentity.'/ART_logo/'.$fileName.'" width=195 border=0 alt="'.$account_name.'">
<center>
<span style="font-size:12px;font-family:ariel; color:#000000;"><center>'.$address.'</span>
<span style="font-size:38px;font-family:ariel; color:#840822;"><center>COURTESY CARD</span>
<!-- <span style="font-size:11px;font-family:ariel; color:#000000;"><center>Entitles only the bearer to:</span>&nbsp;<P> -->

<span style="font-size:11px;font-family:ariel; color:#000000;"><center>Valid For Barer Use Only</span>&nbsp;<P>
<span style="font-size:28px;font-family:ariel; color:#000000;"><center><B>'.$var1.'</B></span>&nbsp;<BR><BR>
<span style="font-size:18px;font-family:ariel; color:#000000;"><center>Expiration Date: '.$pDate.'</span></center>
<p align=right>
<BR>&nbsp;<BR>
<img src="http://www.ExpertsEx.com/ART/Transparent_Spacer.png" width=280 height=2 border=1>
<!--
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_LARGE.png" width=30 border=0 alt="">
<font size="3" color="#840822"><B>ExpertsEx</font><font size="2" color="#c0c0c0">.com</font></B>
-->
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_200x49.png" width=180 border=0 alt="ExpertsEx.com">




<span style="font-size:93px; color:#FFFFFF;">
<P>&nbsp;RJV<P></span>
<img src="http://www.ExpertsEx.com/r/'.$UniqueIdentity.'/ART_logo/'.$fileName.'" width=195 border=0 alt="'.$account_name.'">
<center>
<span style="font-size:12px;font-family:ariel; color:#000000;"><center>'.$address.'</span>
<span style="font-size:38px;font-family:ariel; color:#840822;"><center>COURTESY CARD</span>
<!-- <span style="font-size:11px;font-family:ariel; color:#000000;"><center>Entitles only the bearer to:</span>&nbsp;<P> -->

<span style="font-size:11px;font-family:ariel; color:#000000;"><center>Valid For Barer Use Only</span>&nbsp;<P>
<span style="font-size:28px;font-family:ariel; color:#000000;"><center><B>'.$var1.'</B></span>&nbsp;<BR><BR>
<span style="font-size:18px;font-family:ariel; color:#000000;"><center>Expiration Date: '.$pDate.'</span></center>
<p align=right>
<BR>&nbsp;<BR>
<img src="http://www.ExpertsEx.com/ART/Transparent_Spacer.png" width=280 height=2 border=1>
<!--
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_LARGE.png" width=30 border=0 alt="">
<font size="3" color="#840822"><B>ExpertsEx</font><font size="2" color="#c0c0c0">.com</font></B>
-->
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_200x49.png" width=180 border=0 alt="ExpertsEx.com">




<span style="font-size:93px; color:#FFFFFF;">
<P>&nbsp;RJV<P></span>
<img src="http://www.ExpertsEx.com/r/'.$UniqueIdentity.'/ART_logo/'.$fileName.'" width=195 border=0 alt="'.$account_name.'">
<center>
<span style="font-size:12px;font-family:ariel; color:#000000;"><center>'.$address.'</span>
<span style="font-size:38px;font-family:ariel; color:#840822;"><center>COURTESY CARD</span>
<!-- <span style="font-size:11px;font-family:ariel; color:#000000;"><center>Entitles only the bearer to:</span>&nbsp;<P> -->

<span style="font-size:11px;font-family:ariel; color:#000000;"><center>Valid For Barer Use Only</span>&nbsp;<P>
<span style="font-size:28px;font-family:ariel; color:#000000;"><center><B>'.$var1.'</B></span>&nbsp;<BR><BR>
<span style="font-size:18px;font-family:ariel; color:#000000;"><center>Expiration Date: '.$pDate.'</span></center>
<p align=right>
<BR>&nbsp;<BR>
<img src="http://www.ExpertsEx.com/ART/Transparent_Spacer.png" width=280 height=2 border=1>
<!--
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_LARGE.png" width=30 border=0 alt="">
<font size="3" color="#840822"><B>ExpertsEx</font><font size="2" color="#c0c0c0">.com</font></B>
-->
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_200x49.png" width=180 border=0 alt="ExpertsEx.com">

</center>




</TD>
<TD style="font-size:28px;font-family:ariel;">







<center><BR>&nbsp;<BR>&nbsp;<BR>&nbsp;<BR>

<B>Please Make Your Hotel Reservations</B>
<span style="font-size:20px; font-family:ariel; color:black;">
<BR><BR>By Phone: 
'.$A_phone.'
<BR><BR>
Or Online: www.ExpertsEx.com/r/'.$UniqueIdentity.'/
</span>
<p>
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_600x146.png" width=300 border=0 alt=" ">
<!--
<img align=bottom src="http://www.ExpertsEx.com/ART/Nxt_Logo_LARGE.png" width=80 border=0 alt="">
<span style="font-size:18px; font-family:helvetica,arial; color:#840822;"><B>ExpertsEx</B><FONT COLOR="#c0c0c0;"><B>.com</B></span>
-->
<span style="font-size:20px; font-family:helvetica,arial; color:black;">
<BR>&nbsp;<BR>
<B>Or Just Stop In</B></span>
<BR>&nbsp;<BR>

<span style="font-size:9px; font-family:helvetica,arial; color:black;">
<FONT COLOR=gray>&#169; ExpertsEx.com &nbsp; All rights reserved.&nbsp; &nbsp; <BR>
All product and service names mentioned are the properties of their respective holders.<BR>
Use of the ExpertsEx.com services constitutes acceptance of the Terms of Use.</font>
</span><hr color=#FFFFFF width=650 size=1>


<span style="font-size:56px; color:#FFFFFF;">
<BR>&nbsp;RJV<BR></span>
<BR>&nbsp;<BR>
<B>Please Make Your Hotel Reservations</B>
<span style="font-size:20px; font-family:ariel; color:black;">
<BR><BR>By Phone: 
'.$A_phone.'
<BR><BR>
Or Online: www.ExpertsEx.com/r/'.$UniqueIdentity.'/
</span>
<p>
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_600x146.png" width=300 border=0 alt=" ">
<!--
<img align=bottom src="http://www.ExpertsEx.com/ART/Nxt_Logo_LARGE.png" width=80 border=0 alt="">
<span style="font-size:18px; font-family:helvetica,arial; color:#840822;"><B>ExpertsEx</B><FONT COLOR="#c0c0c0;"><B>.com</B></span>
-->
<span style="font-size:20px; font-family:helvetica,arial; color:black;">
<BR>&nbsp;<BR>
<B>Or Just Stop In</B></span>
<BR>&nbsp;<BR>

<span style="font-size:9px; font-family:helvetica,arial; color:black;">
<FONT COLOR=gray>&#169; ExpertsEx.com &nbsp; All rights reserved.&nbsp; &nbsp; <BR>
All product and service names mentioned are the properties of their respective holders.<BR>
Use of the ExpertsEx.com services constitutes acceptance of the Terms of Use.</font>
</span><hr color=#FFFFFF width=650 size=1>


<span style="font-size:56px; color:#FFFFFF;">
<BR>&nbsp;RJV<BR></span>
<BR>&nbsp;<BR>
<B>Please Make Your Hotel Reservations</B>
<span style="font-size:20px; font-family:ariel; color:black;">
<BR><BR>By Phone: 
'.$A_phone.'
<BR><BR>
Or Online: www.ExpertsEx.com/r/'.$UniqueIdentity.'/
</span>
<p>
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_600x146.png" width=300 border=0 alt=" ">
<!--
<img align=bottom src="http://www.ExpertsEx.com/ART/Nxt_Logo_LARGE.png" width=80 border=0 alt="">
<span style="font-size:18px; font-family:helvetica,arial; color:#840822;"><B>ExpertsEx</B><FONT COLOR="#c0c0c0;"><B>.com</B></span>
-->
<span style="font-size:20px; font-family:helvetica,arial; color:black;">
<BR>&nbsp;<BR>
<B>Or Just Stop In</B></span>
<BR>&nbsp;<BR>

<span style="font-size:9px; font-family:helvetica,arial; color:black;">
<FONT COLOR=gray>&#169; ExpertsEx.com &nbsp; All rights reserved.&nbsp; &nbsp; <BR>
All product and service names mentioned are the properties of their respective holders.<BR>
Use of the ExpertsEx.com services constitutes acceptance of the Terms of Use.</font>
</span><hr color=#FFFFFF width=650 size=1>


<span style="font-size:56px; color:#FFFFFF;">
<BR>&nbsp;RJV<BR></span>
<BR>&nbsp;<BR>
<B>Please Make Your Hotel Reservations</B>
<span style="font-size:20px; font-family:ariel; color:black;">
<BR><BR>By Phone: 
'.$A_phone.'
<BR><BR>
Or Online: www.ExpertsEx.com/r/'.$UniqueIdentity.'/
</span>
<p>
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_600x146.png" width=300 border=0 alt=" ">
<!--
<img align=bottom src="http://www.ExpertsEx.com/ART/Nxt_Logo_LARGE.png" width=80 border=0 alt="">
<span style="font-size:18px; font-family:helvetica,arial; color:#840822;"><B>ExpertsEx</B><FONT COLOR="#c0c0c0;"><B>.com</B></span>
-->
<span style="font-size:20px; font-family:helvetica,arial; color:black;">
<BR>&nbsp;<BR>
<B>Or Just Stop In</B></span>
<BR>&nbsp;<BR>

<span style="font-size:9px; font-family:helvetica,arial; color:black;">
<FONT COLOR=gray>&#169; ExpertsEx.com &nbsp; All rights reserved.&nbsp; &nbsp; <BR>
All product and service names mentioned are the properties of their respective holders.<BR>
Use of the ExpertsEx.com services constitutes acceptance of the Terms of Use.</font>
</span><hr color=#FFFFFF width=650 size=1>


<span style="font-size:56px; color:#FFFFFF;">
<BR>&nbsp;RJV<BR></span>
<BR>&nbsp;<BR>
<B>Please Make Your Hotel Reservations</B>
<span style="font-size:20px; font-family:ariel; color:black;">
<BR><BR>By Phone: 
'.$A_phone.'
<BR><BR>
Or Online: www.ExpertsEx.com/r/'.$UniqueIdentity.'/
</span>
<p>
<img src="http://www.ExpertsEx.com/ART/Nxt_Logo_600x146.png" width=300 border=0 alt=" ">
<!--
<img align=bottom src="http://www.ExpertsEx.com/ART/Nxt_Logo_LARGE.png" width=80 border=0 alt="">
<span style="font-size:18px; font-family:helvetica,arial; color:#840822;"><B>ExpertsEx</B><FONT COLOR="#c0c0c0;"><B>.com</B></span>
-->
<span style="font-size:20px; font-family:helvetica,arial; color:black;">
<BR>&nbsp;<BR>
<B>Or Just Stop In</B></span>
<BR>&nbsp;<BR>

<span style="font-size:9px; font-family:helvetica,arial; color:black;">
<FONT COLOR=gray>&#169; ExpertsEx.com &nbsp; All rights reserved.&nbsp; &nbsp; <BR>
All product and service names mentioned are the properties of their respective holders.<BR>
Use of the ExpertsEx.com services constitutes acceptance of the Terms of Use.</font>
</span><hr color=#FFFFFF width=650 size=1>
</TD></TR>


</TABLE>
';


//echo "Your Courtesy Card has been downloaded.";
//==============================================================
//==============================================================
//==============================================================
include("mpdf.php");

	
		 $mpdf = new mPDF('utf-8', 'Letter', 
		 0,     // font size - default 0
		 '',    // default font family
		 1,     // margin_left
		 2,     // margin right
		 1,     // margin top
		 1,     // margin bottom
		 1,     // margin header
		 1);    // margin footer;	
		 
		 
		 
$mpdf->SetDisplayMode('fullpage');

$mpdf->list_indent_first_level = 0;	// 1 or 0 - whether to indent the first level of a list

// LOAD a stylesheet
$stylesheet = file_get_contents('mpdfstyletables.css');
$mpdf->WriteHTML($stylesheet,1);	// The parameter 1 tells that this is css/style only and no body/html/text

$mpdf->WriteHTML($content);

$mpdf->Output("Avery_CourtesyCard.pdf","D");  // Use D to output to the browser and force a download. 
echo '<meta http-equiv="refresh" content="0;url=http://www.ExpertsExchange.com/">'; // This does not echo when done

exit;
echo '$content' ;

//echo "Your Courtesy Card has been downloaded.";
echo '<meta http-equiv="refresh" content="0;url=http://www.ExpertsExchange.com/">'; // This does not echo when done
exit;
//==============================================================
//==============================================================
//==============================================================
//echo ("Your Courtesy Card has been downloaded.");
?>Done?

Open in new window

0
Comment
Question by:sasnaktiv
  • 15
  • 7
  • 2
24 Comments
 
LVL 1

Expert Comment

by:ventiro
ID: 38353113
First question. Does the PDF look right? If so, when you print the PDF check that page scaling is set to None in the print screen.
You should also take in account that many printers doesnt allow you to print all the way to the borders of the paper.
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38353935
It does not seem to be a printer issue.
The contents are reduced in the actual PDF.
It shows a wide margin (1.5 inches) at the bottom which never decreases to the usual .5 inch.
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38356379
Actually I just discovered that it's not the PHP to PDF at all.
Instead it is the table itself.
But I can't figure out why the table is reducing the size of its contents.

Any ideas, Guys?
Thanks
Sas
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:ventiro
ID: 38356670
Hi,

HTML tables and mpdf isnt built to this type of fine-grade control on paper. Its more for just getting a quick PDF-version of your webpage.
 I would suggest that you use TCPDF (http://TCPDF.org) instead. With TCPDF you build the layout in te pdf directly and place every object exactly where you want it and you have support for vectorized logotyoes etc.
  // Janne
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38357130
Thanks Ventrio, I'll look into it.
Sas
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38357821
Agree with ventiro.  HTML is a semantic markup language (although many features such as tables can be used to force alignment).  PDF is a document layout language, and these two languages are as different as fish and bicycles.  I have recently begun using TCPDF (after many years using FPDF) and I've found it to be precise in its placement and sizing.  It's a little fiddly to get the exaction positioning correct the first time - you need to build this into the estimate - but once you've got the documents right, they stay right and the output is created in lightning fast times.  Here is a sample script I recently used to create a set of 600 mailing labels.  Admittedly it is a bit of a hack, but I wrote it for my own use, so things like global declarations may be forgiven.

<?php // RAY_good_parklawn_addresses.php

// SPEW OUT INFORMATION FROM THE DATA BASE

// INSERT LIVE DATABASE CREDENTIALS HERE

date_default_timezone_set('America/Chicago');

// CONNECT TO THE DATA BASE SERVER
if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word")) {
	$errmsg	= mysql_errno() . ' ' . mysql_error();
	echo "<br/>! db_connection ";
	echo "<br/> $errmsg <br/>";
}
// SELECT THE DATA BASE
if (!$db_sel = mysql_select_db($db_name, $db_connection)) {
	$errmsg	= mysql_errno() . ' ' . mysql_error();
	echo "<br/>! db_sel ";
	echo "<br/> $errmsg <br/>";
	die('NO DATA BASE?');
}
$sql = "SELECT addr, flag FROM good_parklawn_addresses WHERE flag = 'OK' ";
$res = mysql_query($sql) or die("FAIL: $sql<br/>" . mysql_error());

// SYNTHESIZE THE PDF FILE NAME
$pdf_file_link    = '/RAY_parklawn_labels.pdf';
$pdf_file_name    = getcwd() . $pdf_file_link;





require_once('tcpdf/config/lang/eng.php');
require_once('tcpdf/tcpdf.php');

echo "<br />Starting PDF creation\n";

// EXTEND THE TCPDF CLASS
class PDF extends TCPDF
{
    // NULLIFY AUTOMATIC HEADER AND FOOTER
    public function Header() {}
    public function Footer() {}
}

// INSTANTIATE THE OBJECT
$pdf = new PDF('P', 'mm', 'LETTER', true, 'UTF-8', false);

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(0,0,0,TRUE);

//set auto page breaks
$pdf->SetAutoPageBreak(FALSE);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('times', '', 13);

$pdf->setCellPaddings(0,0,0,0);
$pdf->setCellMargins(0,0,0,0);
$pdf->setFillColor(255,255,255);
$bdr = '1TRBL';
$bdr = 0;

// SIGNAL THAT THE DATA SET IS NOT EXHAUSTED
$running = TRUE;

// VERTICAL ALIGNMENT
$y_axis = array
( 0
, 25
, 51
, 77
, 103
, 128
, 152
, 178
, 203
, 228
)
;

while ($running)
{
    // add a page
    $pdf->AddPage('P', 'LETTER', TRUE);

    // PUT CURSOR AT TOP LEFT
    $pdf->setXY(0,0,TRUE);


    foreach ($y_axis as $y)
    {
        $running = left_label($y);
        $running = center_label($y);
        $running = right_label($y);
    }
}

// WRITE THE PDF FILE TO THE SERVER
echo "<br />Writing PDF\n";
$pdf->Output($pdf_file_name,'F');

// PRESENT A CLICKABLE LINK SO WE CAN D/L AND PRINT THE LABELS
echo "<br /><br /><a target=\"my_PDF\" href=\"$pdf_file_link\"><strong>Print Parklawn Labels</strong></a><br /><br />\n";
die();


function left_label($y)
{
    global $pdf, $res, $bdr;

    $row = mysql_fetch_assoc($res);
    if (!$row) return FALSE;

    $addr = explode(',', $row['addr']);

    // IS THERE A REAL NAME?
    $nom = trim($addr[0]);

    // NO REAL NAME
    if (preg_match('/^\d{4}/', $nom))
    {
        $nom = 'My Parklawn Neighbor';
        $ad1 = trim($addr[0]);
        $ad2 = trim($addr[1]);
    }

    // WITH A REAL NAME
    else
    {
        $nom = trim($addr[0]);
        $ad1 = trim($addr[1]);
        $ad2 = trim($addr[2]);
    }

    // LEFT NAME
    $pdf->Text
    ( 14            // $x,
    , $y+15         // $y,
    , $nom
    , FALSE         // $fstroke = false,
    , FALSE         // $fclip = false,
    , TRUE          // $ffill = true,
    , $bdr          // $border = 0,
    , 2             // $ln = 0, 2=PUT CURSOR BELOW
    , ''            // $align = '', DEFAULT LEFT
    , TRUE          // $fill = false, CELL BACKGROUND
    , ''            // $link = '', NOT A LINK
    , 0             // $stretch = 0, NO TEXT STRETCH
    , FALSE         // $ignore_min_height = false,
    , 'A'           // $calign = 'T', A=FONT TOP INSIDE CELL
    , 'T'           // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
    , TRUE          // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
    )
    ;

    // LEFT ADDRESS STREET
    $pdf->Text
    ( 14            // $x,
    , $y+21         // $y,
    , $ad1
    , FALSE         // $fstroke = false,
    , FALSE         // $fclip = false,
    , TRUE          // $ffill = true,
    , $bdr          // $border = 0,
    , 2             // $ln = 0, 2=PUT CURSOR BELOW
    , ''            // $align = '', DEFAULT LEFT
    , TRUE          // $fill = false, CELL BACKGROUND
    , ''            // $link = '', NOT A LINK
    , 0             // $stretch = 0, NO TEXT STRETCH
    , FALSE         // $ignore_min_height = false,
    , 'A'           // $calign = 'T', A=FONT TOP INSIDE CELL
    , 'T'           // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
    , TRUE          // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
    )
    ;

    // LEFT ADDRESS CITY STATE ZIP
    $pdf->Text
    ( 14            // $x,
    , $y+27         // $y,
    , $ad2
    , FALSE         // $fstroke = false,
    , FALSE         // $fclip = false,
    , TRUE          // $ffill = true,
    , $bdr          // $border = 0,
    , 2             // $ln = 0, 2=PUT CURSOR BELOW
    , ''            // $align = '', DEFAULT LEFT
    , TRUE          // $fill = false, CELL BACKGROUND
    , ''            // $link = '', NOT A LINK
    , 0             // $stretch = 0, NO TEXT STRETCH
    , FALSE         // $ignore_min_height = false,
    , 'A'           // $calign = 'T', A=FONT TOP INSIDE CELL
    , 'T'           // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
    , TRUE          // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
    )
    ;

    return TRUE;
}

function center_label($y)
{
    global $pdf, $res, $bdr;

    $row = mysql_fetch_assoc($res);
    if (!$row) return FALSE;

    $addr = explode(',', $row['addr']);

    // IS THERE A REAL NAME?
    $nom = trim($addr[0]);

    // NO REAL NAME
    if (preg_match('/^\d{4}/', $nom))
    {
        $nom = 'My Parklawn Neighbor';
        $ad1 = trim($addr[0]);
        $ad2 = trim($addr[1]);
    }

    // WITH A REAL NAME
    else
    {
        $nom = trim($addr[0]);
        $ad1 = trim($addr[1]);
        $ad2 = trim($addr[2]);
    }

    // CENTER NAME
    $pdf->Text
    ( 80            // $x,
    , $y+15         // $y,
    , $nom
    , FALSE         // $fstroke = false,
    , FALSE         // $fclip = false,
    , TRUE          // $ffill = true,
    , $bdr          // $border = 0,
    , 2             // $ln = 0, 2=PUT CURSOR BELOW
    , ''            // $align = '', DEFAULT LEFT
    , TRUE          // $fill = false, CELL BACKGROUND
    , ''            // $link = '', NOT A LINK
    , 0             // $stretch = 0, NO TEXT STRETCH
    , FALSE         // $ignore_min_height = false,
    , 'A'           // $calign = 'T', A=FONT TOP INSIDE CELL
    , 'T'           // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
    , TRUE          // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
    )
    ;

    // CENTER ADDDRESS
    $pdf->Text
    ( 80            // $x,
    , $y+21         // $y,
    , $ad1
    , FALSE         // $fstroke = false,
    , FALSE         // $fclip = false,
    , TRUE          // $ffill = true,
    , $bdr          // $border = 0,
    , 2             // $ln = 0, 2=PUT CURSOR BELOW
    , ''            // $align = '', DEFAULT LEFT
    , TRUE          // $fill = false, CELL BACKGROUND
    , ''            // $link = '', NOT A LINK
    , 0             // $stretch = 0, NO TEXT STRETCH
    , FALSE         // $ignore_min_height = false,
    , 'A'           // $calign = 'T', A=FONT TOP INSIDE CELL
    , 'T'           // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
    , TRUE          // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
    )
    ;

    // CENTER CITY-STATE-ZIP
    $pdf->Text
    ( 80            // $x,
    , $y+27         // $y,
    , $ad2
    , FALSE         // $fstroke = false,
    , FALSE         // $fclip = false,
    , TRUE          // $ffill = true,
    , $bdr          // $border = 0,
    , 2             // $ln = 0, 2=PUT CURSOR BELOW
    , ''            // $align = '', DEFAULT LEFT
    , TRUE          // $fill = false, CELL BACKGROUND
    , ''            // $link = '', NOT A LINK
    , 0             // $stretch = 0, NO TEXT STRETCH
    , FALSE         // $ignore_min_height = false,
    , 'A'           // $calign = 'T', A=FONT TOP INSIDE CELL
    , 'T'           // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
    , TRUE          // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
    )
    ;

    return TRUE;
}


function right_label($y)
{
    global $pdf, $res, $bdr;

    $row = mysql_fetch_assoc($res);
    if (!$row) return FALSE;

    $addr = explode(',', $row['addr']);

    // IS THERE A REAL NAME?
    $nom = trim($addr[0]);

    // NO REAL NAME
    if (preg_match('/^\d{4}/', $nom))
    {
        $nom = 'My Parklawn Neighbor';
        $ad1 = trim($addr[0]);
        $ad2 = trim($addr[1]);
    }

    // WITH A REAL NAME
    else
    {
        $nom = trim($addr[0]);
        $ad1 = trim($addr[1]);
        $ad2 = trim($addr[2]);
    }

    // RIGHT NAME
    $pdf->Text
    ( 150           // $x,
    , $y+15         // $y,
    , $nom
    , FALSE         // $fstroke = false,
    , FALSE         // $fclip = false,
    , TRUE          // $ffill = true,
    , $bdr          // $border = 0,
    , 2             // $ln = 0, 2=PUT CURSOR BELOW
    , ''            // $align = '', DEFAULT LEFT
    , TRUE          // $fill = false, CELL BACKGROUND
    , ''            // $link = '', NOT A LINK
    , 0             // $stretch = 0, NO TEXT STRETCH
    , FALSE         // $ignore_min_height = false,
    , 'A'           // $calign = 'T', A=FONT TOP INSIDE CELL
    , 'T'           // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
    , TRUE          // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
    )
    ;

    // RIGHT ADDRESS
    $pdf->Text
    ( 150           // $x,
    , $y+21         // $y,
    , $ad1
    , FALSE         // $fstroke = false,
    , FALSE         // $fclip = false,
    , TRUE          // $ffill = true,
    , $bdr          // $border = 0,
    , 2             // $ln = 0, 2=PUT CURSOR BELOW
    , ''            // $align = '', DEFAULT LEFT
    , TRUE          // $fill = false, CELL BACKGROUND
    , ''            // $link = '', NOT A LINK
    , 0             // $stretch = 0, NO TEXT STRETCH
    , FALSE         // $ignore_min_height = false,
    , 'A'           // $calign = 'T', A=FONT TOP INSIDE CELL
    , 'T'           // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
    , TRUE          // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
    )
    ;

    // RIGHT CITY-STATE-ZIP
    $pdf->Text
    ( 150           // $x,
    , $y+27         // $y,
    , $ad2
    , FALSE         // $fstroke = false,
    , FALSE         // $fclip = false,
    , TRUE          // $ffill = true,
    , $bdr          // $border = 0,
    , 2             // $ln = 0, 2=PUT CURSOR BELOW
    , ''            // $align = '', DEFAULT LEFT
    , TRUE          // $fill = false, CELL BACKGROUND
    , ''            // $link = '', NOT A LINK
    , 0             // $stretch = 0, NO TEXT STRETCH
    , FALSE         // $ignore_min_height = false,
    , 'A'           // $calign = 'T', A=FONT TOP INSIDE CELL
    , 'T'           // $valign = 'M', T=VERTICAL ALIGN INSIDE CELL
    , TRUE          // $rtloff = false TRUE = USE PAGE TOP LEFT CORNER TO ALIGN
    )
    ;

    return TRUE;
}

Open in new window

HTH, ~Ray
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38357922
That's very interesting Ray. Your execution relies on a db connection to glean content.
Mine does not. So just playing with your gives me all kinds of db errors.

I've been trying Ventrio's. My problem there is finding an example that fits or even comes close to my needs. And it's not as simple as replacing  the sample $html content with my own html tables.

I've got to kick the tires on this one a little more.
Unless you guys can guide me on how to use the original code I posted.
Thanks,
Sas
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 38358058
I am pretty sure I cannot guide you on how to use code that did not work for you.  About all I can do is show you some examples that worked for me -- in the form of teaching examples.  You can extrapolate from these or you can show these issues to a professional programmer and ask for assistance.  EE does not pay us, and sometimes the "time is money" concept is worth consideration.  Best of luck with the project, ~Ray
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38371918
Hi,
I've been having some degree of success with TCPDF as you both suggested. But I'm running into one stumbling block. All of the examples default to a A4 page size, and I can't find any place to change that. I suppose I could force the change in the 'tcpdf.php' document, but that doesn't seem to be the most effective/flexible way to indicate the page sizes of Letter & business cards. I've used TCPDF's 'example_006.php' to get started, and that seems to be the proper place to set the page sizes, but I can't figure out where in 'example_006.php' to make the page size. Which line of code in 'example_006.php' sets the page size?
Any suggestions?
Thanks,
Sas
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38379483
Okay, so I solved that problem.
But in some cases TCPDF is rotating my images 180 degrease and disregarding width="100" height="30".

It does not happen all of the time. I'm working with 2 pages. When I use the identical image on the first page, everything functions properly, but that same image on the second page is rotated.

What gives with that?
Got any ideas?
0
 
LVL 1

Expert Comment

by:ventiro
ID: 38381214
Can you post your code so I can regenerate the problem?
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38396039
Sorry I missed your post, Ventrio.
I'm using TCPDF to generate the PDF file but I'm having a problem with images. Some images appear in the PDF properly, but the same images placed elsewhere are rotated and ignore the height specifications.

My html seems correct so I can't understand why this is happening. In the code below I've replaced my image paths & the like with those from TCPDF site.

The misbehaving images are on lines 110 & 86.
The images that render properly are on lines 108 & 78. But also please note that the (alt="$variable") fails to function. If the image path is broken the alt either gives me an error on creation or a broken icon.
Thanks,
Sas


<?php
//============================================================+
// File name   : example_006.php
// Begin       : 2008-03-04
// Last Update : 2010-11-20
//
// Description : Example 006 for TCPDF class
//               WriteHTML and RTL support
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com LTD
//               Manor Coach House, Church Hill
//               Aldershot, Hants, GU12 4RQ
//               UK
//               www.tecnick.com
//               info@tecnick.com
//============================================================+

/**
 * Creates an example PDF TEST document using TCPDF
 * @package com.tecnick.tcpdf
 * @abstract TCPDF - Example: WriteHTML and RTL support
 * @author Nicola Asuni
 * @since 2008-03-04
 */
$accountURL=$_POST['accountURL'];
$fileName=$_POST['fileName'];
$pDate=$_POST['pDate'];
$var1=$_POST['var1'];
$A_phone=$_POST['A_phone'];
$address=$_POST['address'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$WebAddress=$_POST['WebAddress'];
$account_name=$_POST['account_name'];

require_once('../config/lang/eng.php');
require_once('../tcpdf.php');

// create new PDF document
//$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf = new TCPDF('L', 'mm', array(89, 51), true, 'UTF-8', false);  //BUSINESS_CARD_US

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 006');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set auto page breaks
$pdf->SetAutoPageBreak(FALSE, PDF_MARGIN_BOTTOM);

//set some language-dependent strings
$pdf->setLanguageArray($l);

$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// ---------------------------------------------------------

// set font
$pdf->SetFont('dejavusans', '', 7);

// add a page
$pdf->AddPage();

// create some HTML content
$html = '
<table border="0" cellspacing="3" cellpadding="4">
<tr><td bgcolor="#FFFFFF" color="#000000" align="center" width="252"style="font-size:14px;font-family:arial; color:#000000;line-height:4px;">
<center><BR>&nbsp;<BR>
<img src="http://www.tecnick.com/r/'.$accountURL.'/ART_logo/'.$fileName.'" height="26"  border=0 alt="'.$account_name.'"><BR> <!-- THIS IMAGE APPEARS PROPERLY (NO ROTATION) -->
<center>'.$address.'<BR>
<span style="font-size:36px;font-family:arial; color:#840822;line-height:4px;"><center>COURTESY CARD</span><BR>
<span style="font-size:11px;font-family:arial; color:#000000;line-height:4px;"><center>Valid For Barer Use Only</span><BR>
<span style="font-size:28px;font-family:arial; color:#000000;line-height:4px;"><center><B>'.$var1.'</B></span>&nbsp;<BR>
<span style="font-size:18px;font-family:arial; color:#000000;"><center>Expiration Date: '.$pDate.'</span>
</center><BR>&nbsp;<BR>
<div align="right">
<img src="http://www.tecnick.com/pagefiles/tcpdf/tcpdf_logo_88x31.png" height="15" border=0 alt="tecnick.com" > <!-- THIS IMAGE IS ROTATED 180 DEGREESE AND ALIGNS LEFT -->  <!-- ADDITIONALLY ALT DOES NOT FUNCTION WHEN IMAGE IS NOT AVAILABLE -->
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</div>
<img src="http://www.tecnick.com/ART/Transparent_Spacer.png" width="252" height="1" border="0">
</td></tr></table>
';

// output the HTML content
$pdf->writeHTMLCell(0, 0, '0', '0', $html, '', 0, 0, true, 'L', true);

// Start Second Page
$pdf->AddPage();
$html = '		
<table border="0" cellspacing="0" cellpadding="12" width="253" height="164">
<tr><td bgcolor="#FFFFFF" color="#000000" align="center" width="253" height="144" style="font-size:14px;font-family:arial; color:#000000;line-height:4px;">
<center><BR>&nbsp;<BR>
<span style="font-size:26px;font-family:arial; color:#000000;"><center><B>Please Contact Us</B></span>
<BR><div style="font-size:22px; font-family:arial; color:#000000; line-height:5px;">By Phone: '.$A_phone.'
<BR>
Or Online: www.tecnick.com/r/'.$accountURL.'/
<BR>
<img src="http://www.tecnick.com/pagefiles/tcpdf/tcpdf_logo_88x31.png" height="22" border="0" alt="'.$account_name.'"> <!-- THIS IMAGE APPEARS PROPERLY (NO ROTATION) --><!-- ALT DOES NOT FUNCTION WHEN IMAGE IS NOT AVAILABLE -->
<BR>Or Just Stop In<BR></div>
<img src="http://www.tecnick.com/pagefiles/tcpdf/tcpdf_logo_88x31.png" height="5" height="1" border="0"> <!-- THIS IMAGE IS ROTATED 180 DEGREESE AND IGNORES THE HEIGHT="5" -->  <!-- ADDITIONALLY ALT DOES NOT FUNCTION WHEN IMAGE IS NOT AVAILABLE -->
<img src="http://www.tecnick.com/ART/Transparent_Spacer.png" width="252" height="1" border="0">
</td></tr></table>
';

$pdf->writeHTMLCell(0, 0, '0', '0', $html, '', 0, 0, true, 'L', true);

$pdf->SetFillColor(255,255,0);

// reset pointer to the last page
$pdf->lastPage();

// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('BusinessCard.pdf', 'D') ;

//============================================================+
// END OF FILE                                                
//============================================================+
?> 

Open in new window

0
 
LVL 1

Expert Comment

by:ventiro
ID: 38396739
Hello again,
PDF isn't HTML so you should not try to make a PDF-layout with HTML and expect it to be exact.

Instead use the methods in TCPDF to place all your elements exactly where you want them.
chekc the source dosc at http://www.tcpdf.org/doc/classTCPDF.html to see all parameters for each method.

I made a quick and dirty example of your layout without HTML, its not a exact match but I think you get the point and can polish it from that. My result is in the attached PDF.
I have changed the image-paths to local variants and if you want to show ALT-text instead of images use PHPs file_exists function to check if the image is there of not, write a text instead.

$pdf->AddPage();

$pdf->Image($accountURL.'_'.$fileName, 0, 5, 0,9, '','','',true,300,'C');

$pdf->SetFont('dejavusans', 'B', 5);
$pdf->setXY(0,14);
$pdf->MultiCell(89, 5, $address, 0, 'C', 0, 0, '', '', true);

$pdf->SetFont('dejavusans', 'B', 13);
$pdf->SetTextColor(150,20,30);
$pdf->setXY(0,20);
$pdf->MultiCell(89, 5, 'COURTESY CARD ', 0, 'C', 0, 0, '', '', true);

$pdf->SetFont('dejavusans', '', 4);
$pdf->SetTextColor(0,0,0);
$pdf->setXY(0,25);
$pdf->MultiCell(89, 5, 'Valid For Barer Use Only ', 0, 'C', 0, 0, '', '', true);

$pdf->SetFont('dejavusans', 'B', 10);
$pdf->setXY(0,28);
$pdf->MultiCell(89, 5, $var1, 0, 'C', 0, 0, '', '', true);

$pdf->SetFont('dejavusans', 'B', 6);
$pdf->setXY(0,33);
$pdf->MultiCell(89, 5, 'Expiration Date: '.$pDate, 0, 'C', 0, 0, '', '', true);

$pdf->Image('Ventiro_logo_2005_250px.png', 0, 40, 0,5, '','','',true,300,'C');
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('BusinessCard.pdf', 'I') ;

Open in new window

BusinessCard-4.pdf
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38396840
That looks good. Give me some time to kick the tires on this.
Why would TCPDF use HTML in their examples if it's not the right way to go?
Sas
0
 
LVL 1

Expert Comment

by:ventiro
ID: 38396872
Hi,
To make it possible to quickly render a PDF-version of a webpage or to create simple layouts where precision isnt an issue.

 // Janne
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38396894
Yes Janne, precision is one thing, rotating an image when it shouldn't is quite another.
I'm playing with this right now. I'll let you know how well I master it.
Thanks again,
Sas
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38397116
Janne it's working out very nicely. Thank you.
I just can't seem to figure out how to get the $alt= when the image is not available.
How did you do it?
Sas
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38397176
Wait! I'm not sure I was as clear as I could have been. As I look through the tcpdf link you sent I'm noticing that $alt does not necessarily mean what it usually does in HTML.

Here's an example of what I'm trying to accomplish. When the image "LogoNotFound.png" is missing or it's path is wrong I need it to be replaced by text such as "My Company Name".
Usually it's accomplished with the example below:
<img src="http://www.tecnick.com/images/LogoNotFound.png" height="26"  border=0 alt="My Company Name">
0
 
LVL 1

Accepted Solution

by:
ventiro earned 2000 total points
ID: 38397793
Hi,

You should do something like this.

if (file_exists('logotypes/LogoNotFound.png')) {
    pdf->Image('logotypes/LogoNotFound.png', 0, 5, 0,9, '','','',true,300,'C');
} else {
    $pdf->SetFont('dejavusans', 'B', 8);
    $pdf->setXY(0,5);
    $pdf->MultiCell(89, 5, 'My Comnpany', 0, 'C', 0, 0, '', '', true);
}

Open in new window

// Janne
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38399287
Hi Janne,
Thanks for getting back to me.
I understand the logic of what you are doing, and if functions --- sort of.

The thing I'm running into is that the "if (file_exists('logotypes/LogoNotFound.png')) {"
always gives me a negative result even when the file does indeed exist and the path is correct.

I've tried it with a few different images, and it always goes to the "else" statement.
What am I doing wrong?
Sas
0
 
LVL 1

Expert Comment

by:ventiro
ID: 38399322
Hi,
the example works here, so I dont know what goes wrong.

Does the webserver have read-rights to the files?
Is is a local file? (it has to be)
Double-check the path to the image.

 // Janne
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38399540
Yes to everything.
When I don't use the "if (file_exists(' " code it functions properly. The images come up perfectly. It's just that I can't always count on them being there since my client will be responsible for uploading his images onto our server.
Sas
0
 
LVL 1

Author Closing Comment

by:sasnaktiv
ID: 38400883
I think it's only fair that I close this ticket since the original problem was solved and solved gloriously. Then open an new ticket to address this new issue.
Thanks for all the help Janne,
More to come,
Sas
0
 
LVL 1

Author Comment

by:sasnaktiv
ID: 38400892
Sorry I goofed in awarding the points. I chose the wrong answer.
I meant to select the answer from the same Expert Janne Ventrio
(by: ventiroPosted on 2012-09-13 at 13:33:04ID: 38396739)
Sas
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month17 days, 4 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question