2009-09-14 9 views
13

में मल्टीसेल के साथ लाइन ब्रेक समस्या मैं fpdf के जावा पोर्ट का उपयोग कर रहा हूं। मुझे त्रुटिपूर्ण त्रुटियों का सामना करना पड़ रहा है।एफपीडीएफ

1)। जब मैं एक नई पंक्ति पर पाठ मुद्रित होने पर हर बार मल्टीसेल 2 बार कॉल करता हूं।

MultiCell(0, 1, "abcd", currentBorders, Alignment.LEFT, false); //prints on one line 
MultiCell(0, 1, "efg", currentBorders, Alignment.LEFT, false); //prints on next line 

मैं चाहता हूं कि मल्टीसेल को कॉल के बाद कोई लाइन ब्रेक न हो। मैं यह कैसे कर सकता हूं?

2) यदि मैं निम्नलिखित बात करता हूं तो मेरी स्ट्रिंग का कुछ हिस्सा एक पंक्ति पर मुद्रित हो जाता है और कुछ अगले पर।

MultiCell(getStringWidth(myString), 1, myStringcurrentBorders, Alignment.LEFT, false); 

3) यदि मैं निम्नलिखित बात करता हूं तो लाइन के बाद कई खाली रेखाएं हैं जिन पर MyString मुद्रित है। यह सही ढंग से काम करता है अगर मैं एक 1 उत्तर दूसरा पैरामीटर

MultiCell(0, myFontSize, "123456", currentBorders, Alignment.LEFT, false); 

समस्या क्या है?

+0

कोई जवाब क्यों नहीं दे रहा है? मुझे इसकी आवश्यकता है बुरी तरह – user156073

उत्तर

15

मैं MultiCell लिखने से पहले वर्तमान Y स्थान प्राप्त है और फिर MultiCell पीढ़ी के बाद वापस कि Y स्थिति के लिए "कर्सर" कदम होगा। इस तरह:

$current_y = $pdf->GetY(); 
$current_x = $pdf->GetX(); 

$cell_width = 50; 
MultiCell($cell_width, 1, "abcd", currentBorders, Alignment.LEFT, false); 

$pdf->SetXY($current_x + $cell_width, $current_y); 

$current_x = $pdf->GetX(); 
MultiCell($cell_width, 1, "abcd", currentBorders, Alignment.LEFT, false); 

ऐसा कुछ।

1

मैंने मल्टीसेल विधि को संशोधित किया है, यह उपर्युक्त उत्तर के रूप में कार्य करता है, और आप सेल विधि के समान तरीके से विधि का उपयोग कर सकते हैं।

function MultiCell($w, $h, $txt, $border=0, $ln=0, $align='J', $fill=false) 
{ 
    // Custom Tomaz Ahlin 
    if($ln == 0) { 
     $current_y = $this->GetY(); 
     $current_x = $this->GetX(); 
    } 

    // Output text with automatic or explicit line breaks 
    $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--; 
    $b = 0; 
    if($border) 
    { 
     if($border==1) 
     { 
      $border = 'LTRB'; 
      $b = 'LRT'; 
      $b2 = 'LR'; 
     } 
     else 
     { 
      $b2 = ''; 
      if(strpos($border,'L')!==false) 
       $b2 .= 'L'; 
      if(strpos($border,'R')!==false) 
       $b2 .= 'R'; 
      $b = (strpos($border,'T')!==false) ? $b2.'T' : $b2; 
     } 
    } 
    $sep = -1; 
    $i = 0; 
    $j = 0; 
    $l = 0; 
    $ns = 0; 
    $nl = 1; 
    while($i<$nb) 
    { 
     // Get next character 
     $c = $s[$i]; 
     if($c=="\n") 
     { 
      // Explicit line break 
      if($this->ws>0) 
      { 
       $this->ws = 0; 
       $this->_out('0 Tw'); 
      } 
      $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 
      $i++; 
      $sep = -1; 
      $j = $i; 
      $l = 0; 
      $ns = 0; 
      $nl++; 
      if($border && $nl==2) 
       $b = $b2; 
      continue; 
     } 
     if($c==' ') 
     { 
      $sep = $i; 
      $ls = $l; 
      $ns++; 
     } 
     $l += $cw[$c]; 
     if($l>$wmax) 
     { 
      // Automatic line break 
      if($sep==-1) 
      { 
       if($i==$j) 
        $i++; 
       if($this->ws>0) 
       { 
        $this->ws = 0; 
        $this->_out('0 Tw'); 
       } 
       $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 
      } 
      else 
      { 
       if($align=='J') 
       { 
        $this->ws = ($ns>1) ?  ($wmax-$ls)/1000*$this->FontSize/($ns-1) : 0; 
        $this->_out(sprintf('%.3F Tw',$this->ws*$this->k)); 
       } 
       $this->Cell($w,$h,substr($s,$j,$sep-$j),$b,2,$align,$fill); 
       $i = $sep+1; 
      } 
      $sep = -1; 
      $j = $i; 
      $l = 0; 
      $ns = 0; 
      $nl++; 
      if($border && $nl==2) 
       $b = $b2; 
     } 
     else 
      $i++; 
    } 
    // Last chunk 
    if($this->ws>0) 
    { 
     $this->ws = 0; 
     $this->_out('0 Tw'); 
    } 
    if($border && strpos($border,'B')!==false) 
     $b .= 'B'; 
    $this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill); 
    $this->x = $this->lMargin; 

    // Custom Tomaz Ahlin 
    if($ln == 0) { 
     $this->SetXY($current_x + $w, $current_y); 
    } 
} 
+2

सीधे विधि को संशोधित करना डरावना है। क्या होगा यदि एफपीडीएफ एक कठोर तरीके से अपडेट करता है जो आपके संशोधनों को अमान्य करता है? मैंने पहले उस तरह के परिदृश्य को देखा है। मुझे लगता है कि एक नई विधि बनाना बेहतर है जो इसे सीधे संशोधित करने के बजाय 'मल्टीसेल 'के आसपास लपेटता है। –

3

मैंने MultiAlignCell नामक एक नई विधि बनाई है। यह MultiCell के समान पैरामीटर लेता है लेकिन Cell से ln फ़ील्ड के साथ जोड़ा गया है। आप इसे अपने विस्तारित FPDF कक्षा में जोड़ सकते हैं।

/** 
* MultiCell with alignment as in Cell. 
* @param float $w 
* @param float $h 
* @param string $text 
* @param mixed $border 
* @param int $ln 
* @param string $align 
* @param boolean $fill 
*/ 
private function MultiAlignCell($w,$h,$text,$border=0,$ln=0,$align='L',$fill=false) 
{ 
    // Store reset values for (x,y) positions 
    $x = $this->GetX() + $w; 
    $y = $this->GetY(); 

    // Make a call to FPDF's MultiCell 
    $this->MultiCell($w,$h,$text,$border,$align,$fill); 

    // Reset the line position to the right, like in Cell 
    if($ln==0) 
    { 
     $this->SetXY($x,$y); 
    } 
} 
+0

आप विधि को 'निजी' क्यों घोषित करते हैं? – Andrea

संबंधित मुद्दे