Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    printing mailing label without blank line

    i have a problem.i want to print mailing label using pdf.


    PHP Code:

    $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:

    PHP Code:

            $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?


  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    PHP Code:
    $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.

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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, they saved me so much hassle.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •