Click to See Complete Forum and Search --> : Set Label Properties - PDF Why is this so hard?!!!


rogernem
March 16th, 2005, 10:01 PM
Ive got the following 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!!

blueday54555
March 17th, 2005, 03:51 AM
didn't test it but have you tried something like that already ?


<?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();
?>

rogernem
March 17th, 2005, 06:00 AM
Friend,
we need to do some little adjustments:


1) in your code as Ive 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
ive been using like this $pdf->Output("new2.pdf","F");
why is that?



Here is the 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");

?>




Ive enclosed the pdf file so you can see what have been happening
Would be very happy if you help me one more time like youve been doing
Thanks a lot!

rogernem
March 17th, 2005, 06:18 AM
ALMOST THERE:

Friend, I did the following:


<?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
Were almost there !!!

blueday54555
March 17th, 2005, 06:21 AM
to 1. does this mean that you read the number of lables from the DB ?

to 2. take this :

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

rogernem
March 17th, 2005, 08:39 AM
Friend,
just read my last post "ALMOST THERE:" and see the pdf attached too so u can understand
That one you answered Id corrected

Thanks

blueday54555
March 17th, 2005, 08:44 AM
That one you answered Id 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 otherwhy you want to replace /n ?
you have only to change 12.7 into 5.08 like in my last post !

rogernem
March 17th, 2005, 10:51 AM
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

rogernem
March 17th, 2005, 10:54 AM
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"ZJI}p`ر_2X&7+?bC18u]>>_|˟ϯs||ǿ}tr.rhF^/ǟrǟgq


Thanks.

rogernem
March 17th, 2005, 11:56 AM
GOT IT TO WORK
Look what I did man:


<?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.
Ill try to print and see if everything fits.
Ill let u kniow
Thanks a lot for now

rogernem
March 17th, 2005, 12:40 PM
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.

rogernem
March 17th, 2005, 01:00 PM
here is what i did:


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

blueday54555
March 18th, 2005, 02:57 AM
$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)

rogernem
March 20th, 2005, 12:25 PM
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?

Id appreciate if you did that.
This thing I need to do due tomorrow and Im desperate.
I cant get it to WORK !!!

blueday54555
March 21st, 2005, 02:21 AM
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.
$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?

rogernem
March 23rd, 2005, 07:29 PM
im using the sheet im supposed to (Letter - 6180) and it still prints wrong
I thought it could be the paper margins..but i dont know where i can change that...
u have any ideas?
tkz

blueday54555
March 24th, 2005, 03:00 AM
Did you tried to change some settings in the printer setup?
Which application do you use to print the pdf?

rogernem
March 24th, 2005, 10:56 AM
Yes, i did.
I asked the printer to print in letter
what do u mean by which application i use to print my pdf?
I just hit the print buttom that is there.

blueday54555
March 29th, 2005, 01:46 AM
what do u mean by which application i use to print my pdf?
now, your php file is creating a pdf file do you open it with adobe acrobat reader
or .............. ?

rogernem
March 30th, 2005, 01:01 PM
Yes,
i have it openned in acrobat reader
then i hit the print buttom
and when its done the page is all wrong
nothing fits in the label

have any ideia why?