...

View Full Version : printing mailing label without blank line



firestar_lene
05-10-2004, 11:07 AM
i have a problem.i want to print mailing label using pdf.





$pdf->Add_PDF_Label(sprintf("%s\n%s\n%s\n%s\n%s %s\n%s %s", "".ucwords($realname)."", "".ucwords($address1)."", "".ucwords($address2)."", "".ucwords($address3)."", "$postcode", "".ucwords($city)."", "".ucwords($state)."", "".strtoupper($country).""));


if one the data is empty,i dont want to leave a blank like,like as below:


name
address1

address3


assume there is no data for address2,it will leave a blank space there.i dont want this to happen.i want to put something like this as below:




$pdf->Add_PDF_Label(sprintf("%s if(!empty($address1))\n%s if(!empty($address2)){\n%s}if(!empty($address3)){\n%s}if(!empty($postcode) or !empty($city)){\n%s %s}if(!empty($state) or !empty($country)){\n%s %s}", "".ucwords($realname)."", "".ucwords($address1)."", "".ucwords($address2)."", "".ucwords($address3)."", "$postcode", "".ucwords($city)."", "".ucwords($state)."", "".strtoupper($country).""));



but it display error when i put the condition(if statement) inside the sprintf..how to put the condition inside?

:(

sad69
05-11-2004, 01:09 AM
I don't know much about sprintf.. but looking briefly at php.net, it looks like it just returns a string. So I'm wondering if you even need to use sprintf and if you can just create a string and pass it to Add_PDF_Label:


$pdf_label = "";
if(!empty($realname))
$pdf_label .= "".ucwords($realname)."\n";
if(!empty($address1))
$pdf_label .= "".ucwords($address1)."\n";
if(!empty($address2))
$pdf_label .= "".ucwords($address2)."\n";
if(!empty($address3))
$pdf_label .= "".ucwords($address3)."\n";
if(!empty($postcode) || !empty($city))
$pdf_label .= "$postcode ".ucwords($city)."\n"
if(!empty($state) || !empty($country))
$pdf_label .= "".ucwords($state)." ".strtoupper($country)."";

$pdf->Add_PDF_Label($pdf_label);


That should do it... let me know how that works out for you.

Sadiq.

TheWhiteSeal
05-13-2008, 01:29 PM
On the subject of printing mailing labels labels I would have to admit that I never really had much luck with my label printer. I spent all my time messing around with the printer and it still never printed any decent looking labels. In the end I decided to give up on the whole DIY approach and I found a british labels company to print my mailing labels (http://www.selfadhesivelabels.com/products.html), they saved me so much hassle.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum