2013-01-14 21 views
5

मुझे यह चाहिए कि सफेद कहने वाला पाठ सेटटेक्स्टकोलर को सफेद के रूप में और संतरे का उपयोग करने के लिए नारंगी का उपयोग करेगा।एफपीडीएफ: सेल के अंदर टेक्स्ट रंग बदलें?

$pdf->SetTextColor(255,255,255); 
$pdf->Cell(50,0,'WHITE ORANGE ORANGE WHITE',0,1,'C'); 

मैं नारंगी पाठ रंग का उपयोग करने के लिए 'ORANGE' शब्दों को कैसे प्रभावित करूं?

+1

ठीक है। आपके प्रश्न के लिए धन्यवाद। –

+0

क्या यह लिंक एक सुराग नहीं दे सकता है? http://stackoverflow.com/questions/3477372/make-text-wrap-in-a-cell-with-fpdf – hmatar

+0

लेकिन मैं इस से उलझन में हूं क्योंकि मैं अभी भी इसे एक पंक्ति पर रहना चाहता हूं। मैं केवल पाठ रंग के लिए एक दृश्य अंतर बनाने के लिए देख रहा हूँ। शायद मैं कुछ गलत पढ़ा। –

उत्तर

0

उत्तर # 1: आप नहीं कर सकते। परिभाषा के अनुसार एक सेल फ़ॉन्ट और रंग में समान है। आप GetStringWidth के साथ शब्दों की चौड़ाई को माप सकते हैं और इसे सेल की श्रृंखला में कर सकते हैं।

उत्तर # 2: योगदान की गई कई स्क्रिप्ट अंतर्निहित कार्यों के रूपों के निर्माण पर आधारित हैं। आखिरकार, आपके पास एफपीडीएफ के सभी के लिए PHP कोड है। आप अपना स्वयं का सेल_प्लस फ़ंक्शन बना सकते हैं जो वाक्यांशों की एक सरणी और अन्य सरणी या दो या तीन गुणों को लेता है। फिर शायद इसे एक अतिरिक्त स्क्रिप्ट के रूप में योगदान दें।

4

यह एक छोटी सी चाल के साथ संभव है। मैं सिर्फ यह 2 कोशिकाओं, एक दूसरे के ऊपर मुद्रण, इस तरह बनाया:

//Setting the text color to black 
$pdf->SetTextColor(0,0,0); 

//Printing my cell  
$pdf->SetFont('Arial','B'); 
$pdf->Cell(55,5,"Black Text ",1,0,'C'); 
$pdf->SetXY($coordXbase,$coordY); 

//Setting the text color to red 
$pdf->SetTextColor(194,8,8); 

//Printing another cell, over the other 
$pdf->SetFont('Arial','B'); 
//Give some space from the left border, and print the red text after the black text that is in the cell behind this one. 
$pdf->Cell(55,5,"      Red Text",0,0,'C'); 
$pdf->SetXY($coordXbase,$coordY); 

//Setting the text color back to back, in the next cells. 
$pdf->SetTextColor(0,0,0); 

परिणाम था इस:

Multicollor cell result

के रूप में मैं एक छोटे से भीड़ थी, मैं बनाने के लिए समय नहीं था इसके साथ मदद करने के लिए कुछ फ़ंक्शन, लेकिन यह एक अच्छा प्रारंभिक बिंदु विचार होगा :)

पीएस: बताएं कि क्या आपको लोगों को एक आसान तरीका मिल रहा है।

4

मुझे उस कार्यक्षमता की भी आवश्यकता है। इस समारोह मैं एक साधारण रंग का स्ट्रिंग करने के लिए लिखा है:

function cellMultiColor($stringParts) { 
    $currentPointerPosition = 0; 
    foreach ($stringParts as $part) { 
     // Set the pointer to the end of the previous string part 
     $this->_pdf->SetX($currentPointerPosition); 

     // Get the color from the string part 
     $this->_pdf->SetTextColor($part['color'][0], $part['color'][1], $part['color'][2]); 

     $this->_pdf->Cell($this->_pdf->GetStringWidth($part['text']), 10, $part['text']); 

     // Update the pointer to the end of the current string part 
     $currentPointerPosition += $this->_pdf->GetStringWidth($part['text']); 
    } 

और आप इस तरह इसका इस्तेमाल:

cellMultiColor([ 
    [ 
     'text' => 'Colored string example: ', 
     'color' => [0, 0, 0], 
    ], 
    [ 
     'text' => 'red', 
     'color' => [255, 0, 0], 
    ], 
    [ 
     'text' => ', ', 
     'color' => [0, 0, 0], 
    ], 
    [ 
     'text' => 'blue', 
     'color' => [0, 0, 255], 
    ], 
]); 
1

मैं एक ऐसी ही बात करना था। रंग के बजाय मुझे फ़ॉन्ट का आकार बदलना पड़ा। मेरे सेल में मैं बजाय तो समारोह कहा जाता है, आपके मामले में आप इस

$pdf->Cell(50,0,white($pdf,'White').orange($pdf,'orange'),0,1,'C'); 

करते हैं और के रूप में

function white($pdf,$val){ 
       $pdf->SetTextColor(255,255,255); 
       return $pdf->Text(0,0,$val); 
       } 

समारोह को परिभाषित करने और एक ही नारंगी के लिए चला जाता है कर सकते हैं।

सुझाव: स्थिति यह ठीक से getX() और Gety() का उपयोग

+0

आपका समाधान मेरे लिए काम नहीं करता है ...आप getX() और getY() को एक केंद्र रेखा में किसी शब्द को रंग देने के लिए कैसे उपयोग करेंगे, उदाहरण के रूप में? – user1111929

1

यदि आप सेल पद्धति का उपयोग करने की जरूरत नहीं है, आप के बजाय लिखें विधि इस्तेमाल कर सकते हैं:

$pdf->SetFont('Arial','b',12); 
$pdf->SetTextColor(153,0,153); 
$pdf->Write(7,'Text in color, '); 
$pdf->SetFont('Arial','',12); 
$pdf->SetTextColor(0,0,0); 
$pdf->Write(7,'and text in black all in the same line')); 
$pdf->Ln(7); 
0

आप writeHTML विधि (tcpdf ver 6.2) का उपयोग कर सकते हैं जैसे

$html = 'Simple text <span style="color: rgb(255,66,14);">Orange</span> simple <span style="color: rgb(12,128,128);">Turquoise</span>'; 
$this->writeHTML($html, true, false, true, false, ''); 
संबंधित मुद्दे