css - How to print on a specific paper -


i'm having problems printing text on a4 paper has 24 labels.

basically, in every row there 3 labels in comes name, surname , adress of person , label used mails ( it's sticky label sticked on mail).

70*36mm cell

so paper. characteristics:

  1. there 10 rows.
  2. the first , last row smallest , have height:0.5mm;.
  3. in first , last row there no cells.
  4. all rest rows have height:36mm;.
  5. all cells have width:70mm; , height:36mm;.
  6. in every cell comes text text-align:center; , vertical-align:middle;.

i'm using normalize.css css reset.

css

html,body,table{   width: 100%;   height: 100%; }  .first, .last{   width: 100%;   height: 5mm; }  .row{   width: 100%;   height: 36mm; }  .cell{   width: 70mm;   height: 36mm;   text-align: center;   vertical-align: middle; } 

i'm using chrome , turned off margins on printing.

but still, last 2 rows printed on next page. need 10 rows on same page , position fixed ( doesn't shift ) in case if there multiple pages.

how fix/achieve ? or there simpler solution ?

here example of code.

i've used fpdf class create pdf labels.

require_once abspath . '/path/to/fpdf.php';   class pdf_mc_table extends fpdf{     var $widths;     var $aligns;      function setwidths($w){         //set array of column widths         $this->widths=$w;     }        function setaligns($a){         //set array of column alignments         $this->aligns=$a;     }        function row($data){         //calculate height of row         $nb=0;         for($i=0;$i<count($data);$i++)             $nb=max($nb,$this->nblines($this->widths[$i],$data[$i]));         $h = 36;// again trial , error until fnd desired height of label         //issue page break first if needed         $this->checkpagebreak($h);         //draw cells of row         for($i=0;$i<count($data);$i++){             $w=$this->widths[$i];             $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'l';             //save current position             $x=$this->getx();             $y=$this->gety();             //draw border. reset parameters of function below desire.             $this->rect($x,$y,$w,$h);             //print text. reset parameters of function below desire. changing values resize boxs.             $this->multicell($w,3,$data[$i],0,$a);             //put position right of cell. reset parameters of function below desire. changing $x , $y shift cells.             $this->setxy($x+$w,$y);         }         //go next line         $this->ln($h+3);     }      function checkpagebreak($h){         //if height h cause overflow, add new page         if($this->gety()+$h>$this->pagebreaktrigger)             $this->addpage($this->curorientation);     }      function nblines($w,$txt){           //computes number of lines multicell of width w take         $cw=&$this->currentfont['cw'];         if($w==0)             $w=$this->w-$this->rmargin-$this->x;         $wmax=($w-2*$this->cmargin)*1000/$this->fontsize;         $s=str_replace("\r",'',$txt);         $nb=strlen($s);         if($nb>0 , $s[$nb-1]=="\n")             $nb--;         $sep=-1;         $i=0;         $j=0;         $l=0;         $nl=1;         while($i<$nb){             $c=$s[$i];             if($c=="\n"){                 $i++;                 $sep=-1;                 $j=$i;                 $l=0;                 $nl++;                 continue;             }             if($c==' ')                 $sep=$i;             $l+=$cw[$c];             if($l>$wmax){                 if($sep==-1){                     if($i==$j)                         $i++;                 }                 else                     $i=$sep+1;                 $sep=-1;                 $j=$i;                 $l=0;                 $nl++;             }             else                 $i++;         }         return $nl;     } }  $pdf=new pdf_mc_table(); $pdf->setmargins(4, 2); $pdf->addpage(); $pdf->setfont('arial','',8); // displays empty row in top $pdf->setrightmargin(2); $pdf->setleftmargin(4); $pdf->cell(0,10,'',1); $pdf->ln(10);  $pdf->setwidths(array(50,50,50));// these widths of cells. trial , error process. increase values until find suitable ones.  $count = 0;   $lables = array(); // labels array  $l = array(); $j = 0;  // used foreach breaking plain array 2dimentional array- array of arrays consisting 3 labels in each.  foreach($lables $i=>$lbl  ){     $l[$j][] = $lbl;      if($i%3==2){$j++;} // $i=0,1,2 > $j=0; $i=3,4,5 > $j=2 etc break main labels array 2d array. } // displays empty row in bottom. $pdf->ln(1);     $pdf->cell(0,10,'',1);  $pdf->output(); 

for further information class , methods please refer http://www.fpdf.org/ @ best need understand 3 methods- multicell(), cell() , rect() methods. there pretty nice explanation of these methods examples in site.

here i've posted solution , i've changed code based on problem. of things self explanatory. if need further assist please feel free comment. thanks.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -