March 16th, 2005, 11:01 PM
#1
Set Label Properties - PDF Why is this so hard?!!!
I´ve got the following code:
PHP Code:
<?php
require( 'fpdf.php' );
$pdf =new FPDF ();
$pdf -> AddPage ();
$pdf -> SetFont ( 'Arial' , 'B' , 16 );
$a = 1000 ;
$b = 2000 ;
$c = 3000 ;
$y = 10 ;
for( $l = 0 ; $l < 10 ; $l ++)
{
$pdf -> MultiCell ( 60 , 10 , $a . "\n" . $b , 1 , 'C' );
$pdf -> SetXY ( 70 , $y );
$pdf -> MultiCell ( 60 , 10 , $a . "\n" . $b , 1 , 'C' );
$pdf -> SetXY ( 130 , $y );
$pdf -> MultiCell ( 60 , 10 , $a . "\n" . $b , 1 , 'C' );
$y = $y + 20 ;
}
$pdf -> Output ();
?>
What I need is to generate 30 labels per page (10 rows / 3 columns)
which is already happening and set the labels properties to:
=============================================
Top margin = 1,27cm
side margins = 0,48cm
lable height = 2,54cm
lable width = 6,67cm
Letter (8 1/2 x 11 in)
=============================================
This is not set yet.
How can I do that with my example??!!
Thank you!!
March 17th, 2005, 04:51 AM
#2
Re: Set Label Properties - PDF Why is this so hard?!!!
didn't test it but have you tried something like that already ?
Code:
<?php
require('fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$a = 1000;
$b = 2000;
$y=12.7;
for($l=0;$l<10;$l++)
{
$pdf->SetXY(4.8,$y);
$pdf->MultiCell(66.7, 12.7, $a."\n".$b , 1,'C');
$pdf->SetXY(4.8+66.7,$y);
$pdf->MultiCell(66.7, 12.7, $a."\n".$b , 1,'C');
$pdf->SetXY(4.8+66.7+66.7,$y);
$pdf->MultiCell(66.7, 12.7, $a."\n".$b , 1,'C');
$y=$y+25.4;
}
$pdf->Output();
?>
Last edited by blueday54555; March 17th, 2005 at 06:37 AM .
March 17th, 2005, 07:00 AM
#3
Re: Set Label Properties - PDF Why is this so hard?!!!
Friend,
we need to do some little adjustments:
1) in your code as I´ve asked b4 its set do create up to 30 labels/page but this:
"for($l=0;$l<10;$l++)"
needed to be something like this:
$sql = "SELECT * from table";
$res = mysql_array($sql, $conn);
$tot = mysql_num_rows($res);
for($l=0;$l<$tot;$l++){
2) Another problem: When we use $a."\n".$b it puts $b a lot lower that it should be. Thats a problem cause I need to have 5 rows in each label and with that the labels height is way bigger than it should be (2,54cm)
$a = 1000;
$b = 2000;
$c = 3000;
$d = 4000;
$e = 5000;
$pdf->MultiCell(66.7, 12.7, $a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'C');
3) $pdf->Output(); returns a lot of things written in the browser so
i´ve been using like this $pdf->Output("new2.pdf","F");
why is that?
Here is the code
============================
PHP Code:
<?php
require( '../fpdf/fpdf.php' );
define ( "FPDF_FONTPATH" , "../fpdf/font/" );
$pdf =new FPDF ();
$pdf -> AddPage ();
$pdf -> SetFont ( 'Times' , '' , 5 );
$a = 1000 ;
$b = 2000 ;
$c = 3000 ;
$d = 4000 ;
$e = 5000 ;
$y = 12.7 ;
for( $l = 0 ; $l < 10 ; $l ++)
{
$pdf -> SetXY ( 4.8 , $y );
$pdf -> MultiCell ( 66.7 , 12.7 , $a . "\n" . $b . "\n" . $c . "\n" . $d . "\n" . $e , 1 , 'C' );
$pdf -> SetXY ( 4.8 + 66.7 , $y );
$pdf -> MultiCell ( 66.7 , 12.7 , $a . "\n" . $b . "\n" . $c . "\n" . $d . "\n" . $e , 1 , 'C' );
$pdf -> SetXY ( 4.8 + 66.7 + 66.7 , $y );
$pdf -> MultiCell ( 66.7 , 12.7 , $a . "\n" . $b . "\n" . $c . "\n" . $d . "\n" . $e , 1 , 'C' );
$y = $y + 25.4 ;
}
$pdf -> Output ( "new2.pdf" , "F" );
?>
I´ve enclosed the pdf file so you can see what have been happening
Would be very happy if you help me one more time like you´ve been doing
Thanks a lot!
Attached Files
March 17th, 2005, 07:18 AM
#4
Re: Set Label Properties - PDF Why is this so hard?!!!
ALMOST THERE:
Friend, I did the following:
PHP Code:
<?php
require( '../fpdf/fpdf.php' );
define ( "FPDF_FONTPATH" , "../fpdf/font/" );
//NUMBER OF RESULTS PER PAGE
$per_page = 30 ;
//TOTAL FROM SQL
$tot = 60 ;
//CALCULATES HOW MANY PAGES WILL BE NECESSARY
$pages = ceil ( $tot / $per_page );
$pdf =new FPDF ();
//START VARS
$actual_line = 0 ;
$beginning = 0 ;
//PAGES
for( $x = 1 ; $x <= $pages ; $x ++) {
//VERIFY
$beginning = $actual_line ;
$end = $actual_line + $per_page ;
if( $end > $tot ) $end = $tot ;
$pdf -> AddPage ();
$pdf -> SetFont ( 'Times' , '' , 5 );
//LIST RECORDS
for( $i = $beginning ; $i < $end ; $i ++) {
$a = 1000 ;
$b = 2000 ;
$c = 3000 ;
$d = 4000 ;
$e = 5000 ;
$y = 12.7 ;
for( $l = 0 ; $l < 10 ; $l ++)
{
$pdf -> SetXY ( 4.8 , $y );
$pdf -> MultiCell ( 66.7 , 12.7 , $a . "\n" . $b , 1 , 'C' );
$pdf -> SetXY ( 4.8 + 66.7 , $y );
$pdf -> MultiCell ( 66.7 , 12.7 , $a . "\n" . $b , 1 , 'C' );
$pdf -> SetXY ( 4.8 + 66.7 + 66.7 , $y );
$pdf -> MultiCell ( 66.7 , 12.7 , $a . "\n" . $b , 1 , 'C' );
$y = $y + 25.4 ;
}
$actual_line ++;
$pdf -> SetAutoPageBreak ( 'on' , '1' );
} //CLOSES FOR(RECORDS - i)
} //CLOSES FOR(PAGES - x)
$pdf -> Output ( "new2.pdf" , "F" );
?>
Take a look at the pdf file now.
Now what we need to do is the "/n" . We need to find a better way to put everything under each other
Thanks
We´re almost there !!!
Attached Files
Last edited by rogernem; March 17th, 2005 at 07:20 AM .
March 17th, 2005, 07:21 AM
#5
Re: Set Label Properties - PDF Why is this so hard?!!!
to 1. does this mean that you read the number of lables from the DB ?
to 2. take this :
Code:
<?php
require('fpdf.php');
define("FPDF_FONTPATH", "../fpdf/font/");
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Times','',5);
$a = 1000;
$b = 2000;
$c = 3000;
$d = 4000;
$e = 5000;
$y=12.7;
for($l=0;$l<10;$l++)
{
$pdf->SetXY(4.8,$y);
$pdf->MultiCell(66.7, 5.08, $a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'C');
$pdf->SetXY(4.8+66.7,$y);
$pdf->MultiCell(66.7, 5.08, $a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'C');
$pdf->SetXY(4.8+66.7+66.7,$y);
$pdf->MultiCell(66.7, 5.08, $a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'C');
$y=$y+25.4;
}
$pdf->Output();
?>
to 3. clear the cache of your browser and reload the page again
this should work.
Last edited by blueday54555; March 17th, 2005 at 07:25 AM .
March 17th, 2005, 09:39 AM
#6
Re: Set Label Properties - PDF Why is this so hard?!!!
Friend,
just read my last post "ALMOST THERE:" and see the pdf attached too so u can understand
That one you answered I´d corrected
Thanks
March 17th, 2005, 09:44 AM
#7
Re: Set Label Properties - PDF Why is this so hard?!!!
That one you answered I´d corrected
In the pdf I see only two rows of text and not the 5 you wanted
Now what we need to do is the "\n" . We need to find a better way to put everything under each other
why you want to replace /n ?
you have only to change 12.7 into 5.08 like in my last post !
Last edited by blueday54555; March 17th, 2005 at 09:48 AM .
March 17th, 2005, 11:51 AM
#8
Re: Set Label Properties - PDF Why is this so hard?!!!
In the pdf I see only two rows of text and not the 5 you wanted
Thats right..cause if i put 5 it will mess everything
thats why we need to correct it
Ill try to use 5.08 instead of 12.7
and ill let u know
thanks
March 17th, 2005, 11:54 AM
#9
Re: Set Label Properties - PDF Why is this so hard?!!!
PERFECT FOR THIS EXAMPLE !!!!
Now its working in terms.
I did this:
$pdf=new FPDF("P","mm","Letter"); to make sure when I print everything will fit on its place but the last labels went down to the other page. See the pdf attached please.
Another thing:
$pdf->Output();
This is not working still...it just prints a lot of things in the browser..like this:
%PDF-1.3 3 0 obj <> endobj 4 0 obj <> stream xœ*ܽn,;vÐü>…BO"÷¯ZJ°ƒI}Áp`ر_ß2ªXä&7‹+¤*½?bêC18u×*ã]>Ÿ¯ÿùëï>þù_¯ÏÏËåãÏ|üËŸ¿®÷ϯëÇ÷åùùýóñßÛòõsý|ü|ü×Ç¿}tÿû*rûüú.ëÿÛÿrìhFü*^/÷Ïëã÷¯ÏëÏÇŸÿø§ëårùÛÇŸÿ¬gØqœáõú¼
Thanks.
Attached Files
Last edited by rogernem; March 17th, 2005 at 12:21 PM .
March 17th, 2005, 12:56 PM
#10
Re: Set Label Properties - PDF Why is this so hard?!!!
GOT IT TO WORK
Look what I did man:
PHP Code:
<?php
require( '../fpdf/fpdf.php' );
define ( "FPDF_FONTPATH" , "../fpdf/font/" );
//NUMBER OF RESULTS PER PAGE
$per_page = 30 ;
//TOTAL FROM SQL
$tot = 60 ;
//CALCULATES HOW MANY PAGES WILL BE NECESSARY
$pages = ceil ( $tot / $per_page );
//$pdf=new FPDF();
$pdf =new FPDF ( "P" , "mm" , "Letter" );
//START VARS
$actual_line = 0 ;
$beginning = 0 ;
//PAGES
for( $x = 1 ; $x <= $pages ; $x ++) {
//VERIFY
$beginning = $actual_line ;
$end = $actual_line + $per_page ;
if( $end > $tot ) $end = $tot ;
$pdf -> AddPage ();
$pdf -> SetFont ( 'Times' , '' , 5 );
//LIST RECORDS
for( $i = $beginning ; $i < $end ; $i ++) {
$a = 1000 ;
$b = 2000 ;
$c = 3000 ;
$d = 4000 ;
$e = 5000 ;
$y = 12.7 ; //top margin = 1,27cm
for( $l = 0 ; $l < 10 ; $l ++) //makes 10 lines
{
//3 labels per line
//x = 0,48cm - left margin
//label width= 6,67cm
//label height = 2,54cm / 4 = 0,508cm
//spaces among labels 0,31cm -> div by 2 = 0,155cm
$pdf -> SetXY ( 4.8 , $y );
$pdf -> MultiCell ( 66.7 + 1.55 , 5.08 , $a . "\n" . $b . "\n" . $c . "\n" . $d . "\n" . $e , 1 , 'C' );
$pdf -> SetXY ( 4.8 + 66.7 + 1.55 , $y );
$pdf -> MultiCell ( 66.7 + 3.1 , 5.08 , $a . "\n" . $b . "\n" . $c . "\n" . $d . "\n" . $e , 1 , 'C' );
$pdf -> SetXY ( 4.8 + 68.25 + 69.8 , $y );
$pdf -> MultiCell ( 66.7 + 1.55 , 5.08 , $a . "\n" . $b . "\n" . $c . "\n" . $d . "\n" . $e , 1 , 'C' );
$y = $y + 25.4 ; //adds label actual position.
$pdf -> SetAutoPageBreak ( 'on' , '12.7' );
}
$actual_line ++;
} //CLOSES FOR(RECORDS - i)
} //CLOSES FOR(PAGES - x)
$pdf -> Output ( "new2.pdf" , "F" );
//$pdf->Output();
?>
Just the $pdf->Output(); is not working still
See the final file man.
I´ll try to print and see if everything fits.
Ill let u kniow
Thanks a lot for now
Attached Files
Last edited by rogernem; March 17th, 2005 at 01:03 PM .
March 17th, 2005, 01:40 PM
#11
Re: Set Label Properties - PDF Why is this so hard?!!!
CRAZY THING
I printed but the margins were not right neither the labels height and width
Label
- missing 0,14cm - height
- width = 6,4cm
Right margin = 1,2cm
Left margin = 0,8cm
When I open the pdf, as you can see, everything seems to be perfect
so why is all that happening???
Can you try to print it there too so you can check it out please?
Ive printed in the label (6180) paper.
Thanks.
March 17th, 2005, 02:00 PM
#12
Re: Set Label Properties - PDF Why is this so hard?!!!
here is what i did:
PHP Code:
$pdf -> SetXY ( 4.8 , $y );
$pdf -> MultiCell ( 68 , 5.36 , $a . "\n" . $b . "\n" . $c . "\n" . $d . "\n" . $e , 1 , 'C' );
$pdf -> SetXY ( 4.8 + 68 , $y );
$pdf -> MultiCell ( 71 , 5.36 , $a . "\n" . $b . "\n" . $c . "\n" . $d . "\n" . $e , 1 , 'C' );
$pdf -> SetXY ( 4.8 + 68 + 71 , $y );
$pdf -> MultiCell ( 68 , 5.36 , $a . "\n" . $b . "\n" . $c . "\n" . $d . "\n" . $e , 1 , 'C' );
$y = $y + 26.8 ;
But the last row goes to the other line and the measurements are all wrong
See the file please: http://www.rads.com.br/downloads/new2.pdf
Suggestions?!!
Thanks.
March 18th, 2005, 03:57 AM
#13
Re: Set Label Properties - PDF Why is this so hard?!!!
Code:
$pdf->SetXY(4.8,$y);
$pdf->MultiCell(68, 5.36 ,$a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'C');
$pdf->SetXY(4.8+68,$y);
$pdf->MultiCell(71, 5.36 ,$a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'C');
$pdf->SetXY(4.8+68+71,$y);
$pdf->MultiCell(68, 5.36 ,$a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'C');
$y=$y+26.8;
Why you use 68 than 71 and than 68 again as width of the labels?
shouldn't it be 66.7?
You use Letter as format
$pdf=new FPDF("P","mm","Letter");
is it the right format for you? (215.9mm/279.4mm)
Last edited by blueday54555; March 18th, 2005 at 04:06 AM .
March 20th, 2005, 01:25 PM
#14
HELPPPPP !!!! Label - PDF Measures all wrong ! Why is this so hard?!!!
It really should be 66.7 but when I try to print with that size the labels I get are all wrong so here is what I did:
Im using 68 - 71 - 68 because there is a space between the labels of 0,31cm. I divided that by 2 = 0,15 then added it in the 1st label and the last one. The 2nd label I added the 2 0,15cm left = 0,31 so I have 68 - 71 - 68
I wanted to get a larger label too..
But the thing is:
I have already done this : $pdf=new FPDF("P","mm","Letter");
I keep getting thw wrong measurements
Have you tried to print the last pdf I had here to see if the measures match?
I´d appreciate if you did that.
This thing I need to do due tomorrow and Im desperate.
I can´t get it to WORK !!!
Last edited by rogernem; March 20th, 2005 at 01:27 PM .
March 21st, 2005, 03:21 AM
#15
Re: Set Label Properties - PDF Why is this so hard?!!!
the space between the labels you have to put in the 2. and 3. SetXY e.g.
$pdf->SetXY(4.8+the witdh of the 1.lable+space)
$pdf->SetXY(4.8+the width of the 1.lable+the width of the 2.lable+space+space) !!
MultiCell accepts witdh and height as parameters and not X and Y coordinates!!
In your code the second lable would be wider then the other two lables.
Code:
$pdf->MultiCell(68, 5.36 ,$a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'C');
$pdf->MultiCell(71, 5.36 ,$a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'C');
$pdf->MultiCell(68, 5.36 ,$a."\n".$b."\n".$c."\n".$d."\n".$e , 1,'C');
At the moment I have no possibillity to print out and check.
But have you checked your printer settings? Are you using a sheet with the
right measures?
Last edited by blueday54555; March 21st, 2005 at 03:23 AM .
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width