Click to See Complete Forum and Search --> : Isnīt That Possible To Do?!!!! Pdf


rogernem
March 9th, 2005, 09:06 AM
Hey there. Ive been trying to generate a pdf file to create stickers (6180 - sticker pattern)
I managed to have 3 stickers per line with 10 lines per page giving a total of 30 stickers per page.

ex.
-------------
| 1 | 2 | 3 |
-------------
| 4 | 5 | 6 |
-------------
| 7 | 8 | 9 |
etc

Here comes the HUGE problem:

$a="valor1";
$b="Valor2";
$pdf->Cell(70.3, 26.5, $a , 1, 0, 'C');


Iīd like to have in this cell 5 itens, one bellow the other (at the moment there are only one - $a)
Iīve tryied to use <br> ($a."<br>".$b) but $b did not go under $a, instead the pdf generated something
like this: "valor1<br>valor2"
It doesnt work with $pdf->Ln(); because it will just jump a line AFTER the whole cellīs been generated.

Iīd like to improve itens 1 and 2 commented in the code:
//* ITEN 1 - WHAT IīD LIKE TO DO
//* ITEN 2 - IMPROVE: There must be a better way to have a break after 3 cellīs been generated


How can I do that ???
Iīve been using fpdf: URL: fdpf (http://www.fpdf.org)

Bellow is my code.


<?

//DB MYSQL
$server = "localhost";
$user = "root";
$pass = "";
$bd = "pdf";
//TITLE
$tit = "STICKERS";
//FPDF LIBRARY
$end_fpdf = "../fpdf";
//NUMBER OF RESULTS PER PAGE
$per_page = 30;
//WHERE PDF WILL BE SAVED
$end_final = "gera.pdf";
//F-> TO SAVE THE PDF
$tipo_pdf = "F";

//CONECTION
$conn = mysql_connect($server, $user, $pass);
$db = mysql_select_db($bd, $conn);
$sql = mysql_query("SELECT A.ID, A.NOME, A.ASSUNTO FROM colunistas A", $conn);
$row = mysql_num_rows($sql);

//SEE IF THERE IS ANY RECORD
if(!$row) { echo "There are no records"; die; }

//CALCULATES HOW MANY PAGES WILL BE NECESSARY
$pages = ceil($row/$per_page);

//PDF
define("FPDF_FONTPATH", "$end_fpdf/font/");
require_once("$end_fpdf/fpdf.php");
$pdf = new FPDF('P','mm','Letter');

$pdf->SetTopMargin(7.1);
$pdf->SetLeftMargin(0);
$pdf->SetRightMargin(0);

//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 > $row) $end = $row;

$pdf->Open();
$pdf->AddPage();
$pdf->SetFont("Arial", "B", 10);

//SHOW RECORDS
for($i=$beginning; $i<$end; $i++) {

//* ITEN 1 - WHAT IīD LIKE TO DO
//$a =mysql_result($sql, $i, "ID") ;
$a="Valor1"; $b="Valor2";
$pdf->Cell(70.3, 26.5, ($i+1)." ".$a."<br>".$b , 1, 0, 'C');

//* ITEN 2 - IMPROVE: There must be a better way to have a break after 3 cellīs been generated
$ia=$i;
$id=$ia+3;
if( $ia==2 || $ia==5 || $ia==8 || $ia==11 || $ia==14 || $ia==17 || $ia==20 || $ia==23 || $ia==26 || $ia==29 ||
$ia==35 || $ia==38 || $ia==41 || $ia==44 || $ia==47 || $ia==50 || $ia==53 || $ia==56 || $ia==59 ||
$ia==65 || $ia==68 || $ia==71 || $ia==74 || $ia==77 || $ia==80 || $ia==83 || $ia==86 || $ia==89 ||
$ia==95 || $ia==98 || $ia==101 || $ia==104 || $ia==107 || $ia==110 || $ia==113 || $ia==116 || $ia==119 ||
$ia==125 || $ia==128 || $ia==131 || $ia==134 || $ia==137 || $ia==140 || $ia==143 || $ia==146 || $ia==149 ||
$ia==155 || $ia==158 || $ia==161 || $ia==164 || $ia==167 || $ia==170 || $ia==173 || $ia==176 || $ia==179
){

$pdf->ln();
}
//ITEN 2 ENDS

$actual_line++;
$pdf->SetAutoPageBreak('on','0.2');

}//END FOR(RECORDS - i)
}//END FOR(pages - x)

//PDF OUTPUT
$pdf->Output("$end_final", "$tipo_pdf");
?>



See the generated pdf attached to understand it better.
GERA.PDF (http://www.rads.com.br/downloads/gera.pdf)

Help me pleaseeeee. Iīve been looking for that for days but it seems that it doenst exist !
Thanks so much.
Roger.

blueday54555
March 9th, 2005, 10:06 AM
<br> will not work it is an html tag and has nothing to do with pdf :)

replace this lines in your code


$a="Valor1"; $b="Valor2";
$pdf->Cell(70.3, 26.5, ($i+1)." ".$a."<br>".$b , 1, 0, 'C');

with this

$a="Valor1"; $b="Valor2";
$pdf->Cell(70.3,26.5,($i+1)." ".$a,1,1,'C');
$pdf->Cell(70.3,26.5,$b,1,1,'C');

this should work


and here is a simple example
<?php
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);

$pdf->Cell(40,10,'Hello!',0,1,'L');
$pdf->Cell(40,10,'How are you ?',0,1,'L');

$pdf->Output();
?>

rogernem
March 10th, 2005, 12:12 PM
Sorry, but that didnt work
it breaked the cell, not the line and iīd like to have a line break INSIDE the cell

iīve tryied:

$pdf->Cell(70.3, 26.5, $a."\n".$b , 1, 0, 'C');
$pdf->Cell(70.3, 26.5, $a."\n\r".$b , 1, 0, 'C');

those did not work either

any other sugestions??
tkzs

blueday54555
March 11th, 2005, 06:25 AM
ahhh sh... you are right what you need is this MultiCell and not Cell.
This should be the right code for your purpose:
$pdf->MultiCell(100, 10, $a."\n".$b , 1,'C');

rogernem
March 12th, 2005, 03:00 PM
That worked but it broke the cells because of this:


if( $ia==2 || $ia==5 || $ia==8 || $ia==11 || $ia==14 || $ia==17 || $ia==20 || $ia==23 || $ia==26 || $ia==29 ||
$ia==35 || $ia==38 || $ia==41 || $ia==44 || $ia==47 || $ia==50 || $ia==53 || $ia==56 || $ia==59 ||
$ia==65 || $ia==68 || $ia==71 || $ia==74 || $ia==77 || $ia==80 || $ia==83 || $ia==86 || $ia==89 ||
$ia==95 || $ia==98 || $ia==101 || $ia==104 || $ia==107 || $ia==110 || $ia==113 || $ia==116 || $ia==119 ||
$ia==125 || $ia==128 || $ia==131 || $ia==134 || $ia==137 || $ia==140 || $ia==143 || $ia==146 || $ia==149 ||
$ia==155 || $ia==158 || $ia==161 || $ia==164 || $ia==167 || $ia==170 || $ia==173 || $ia==176 || $ia==179
){

$pdf->ln();

}



I have that cause iīve been trying to break the line for every 3 cells that is been created.

Look the attached file so you can see what happened please.
Can you help me to correct that now?!
Thanks

blueday54555
March 14th, 2005, 03:48 AM
what you need is SetXY I think.
e.g.
<?php
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);

$a = 1000;
$b = 2000;
$c = 3000;

$pdf->MultiCell(60, 10, $a."\n".$b , 1,'C');
$pdf->SetXY(70,10);
$pdf->MultiCell(60, 10, $a."\n".$b , 1,'C');
$pdf->SetXY(130,10);
$pdf->MultiCell(60, 10, $a."\n".$b , 1,'C');

$pdf->Output();
?>

rogernem
March 15th, 2005, 02:38 PM
Very good !!
But i need to have up to 10 rows per page.
How can I do that??

If i do

for($i=0;$i<10;$i++){
$pdf->MultiCell(60, 5, $a1."\n".$a2."\n".$a3."\n".$a4."\n".$a5 , 1,'C');
$pdf->SetXY(70,10);
$pdf->MultiCell(60, 5, $b1."\n".$b2."\n".$b3."\n".$b4."\n".$b5 , 1,'C');
$pdf->SetXY(130,10);
$pdf->MultiCell(60, 5, $c1."\n".$c2."\n".$c3."\n".$c4."\n".$c5 , 1,'C');
}

it will put the cells over the first ones generated

Thank u!

blueday54555
March 16th, 2005, 04:36 AM
it will put the cells over the first ones generated

it's putting over because you don't change the y value in SetXY

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

rogernem
March 16th, 2005, 07:03 AM
It REALLY worked !!!!
Thatīs great !!!
I had this post cause Iīve been trying to make some stickers
(30 per page - Total of 10 rows with 3 stickers per row)

There are the metrics for a 6180 label type:
==============================
Top margin = 1,27cm
side margins = 0,48cm
lable height = 2,54cm
lable width = 6,67cm
Letter (8 1/2 x 11 in)
===============================

How can I set now all the margins and the height and width so I īd have that?


Iīve got this from a pdf label class:


size="letter";
orientation="portrait";

// set defaults for the margins
// top and left margins are set to writing point (FYI: exact label edge is 1/2 inch = 36)
// bottom and right are adjusted to allow the write point to move freely (this is touchy)
margin_t=$this->u2px(2/3); // 2/3 of an inch
margin_b=$this->u2px(1/3);
margin_l=$this->u2px(3/8);
margin_r=$this->u2px(2/9);

// set the labels width & height
$this->label['width']=$this->u2px(2.75); //width of label = 2 3/4 inches
$this->label['height']=$this->u2px(1); //height of label = 1 inch
// set number of lables per row
$this->label['per_row']=3;
// set size of text for label
$this->label['textsize']=10;

function u2px ($value=0,$unit="in") {
// function returns converted value from any unit to pdf screen units
// requires: $value - the value to be converted
// $unit - the unit that the $value is measured in
$fuzz=0.00000001; // facilitates rounding
switch ($unit) {
case "in": // english inches
$newvalue=round($value*72+$fuzz);
return($newvalue);
break;
case "cm": // metric centimeters
$newvalue=round($value*28.3465+$fuzz);
return($newvalue);
break;
case "mm": // metric millimeters
$newvalue=round($value*2.83465+$fuzz);
return($newvalue);
break;
} // end switch
} //end u2px



Thanks once again
You have been very helpfull !!

blueday54555
March 16th, 2005, 09:38 AM
check out the functions

SetMargins
SetLeftMargin
SetRightMargin
SetTopMargin

here:
http://www.fpdf.org/en/doc/index.php

rogernem
March 16th, 2005, 10:53 PM
Iīve tryied that already...didnt work
Could you give me again an example?!
Perhaps using the same one you had b4
Thank you.