흰색을 말하는 텍스트가 흰색으로 SetTextColor를 사용하고 주황색을 사용하도록 텍스트를 원합니다.FPDF : 셀 내부에서 텍스트 색을 변경 하시겠습니까?
$pdf->SetTextColor(255,255,255);
$pdf->Cell(50,0,'WHITE ORANGE ORANGE WHITE',0,1,'C');
주황색 텍스트 색상을 사용하려면 '주황색'단어에 어떻게 영향을 줍니까?
흰색을 말하는 텍스트가 흰색으로 SetTextColor를 사용하고 주황색을 사용하도록 텍스트를 원합니다.FPDF : 셀 내부에서 텍스트 색을 변경 하시겠습니까?
$pdf->SetTextColor(255,255,255);
$pdf->Cell(50,0,'WHITE ORANGE ORANGE WHITE',0,1,'C');
주황색 텍스트 색상을 사용하려면 '주황색'단어에 어떻게 영향을 줍니까?
답변 # 1 : 할 수 없습니다. 정의에 의한 셀은 폰트와 색상이 균일합니다. getStringWidth를 사용하여 단어 너비를 측정하고 일련의 셀에서 수행 할 수 있습니다.
답변 # 2 : 많은 기여 스크립트는 기본 제공 함수의 변형을 기반으로합니다. 결국 모든 FPDF에 PHP 코드가 있습니다. 구문의 배열과 다른 배열 또는 두 개 또는 세 개의 특성을 사용하는 자체 Cell_plus 함수를 만들 수 있습니다. 그런 다음 추가 스크립트로 제공하십시오.
약간의 트릭이 가능합니다. 난 그냥 같이, 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);
결과였다이 : 나는 조금 돌진했다, 나는이 만들 시간이 없었
일부 기능이 도움이,하지만이 좋은 출발점 아이디어 :
PS 것 : 너희들이 더 쉬운 방법을 찾을 경우 알려주십시오.
그 기능도 필요했습니다. 이것은 간단한 색 문자열을 위해 작성된 함수 I입니다 :
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],
],
]);
나는 비슷한 일을했다. 색상 대신 글꼴 크기를 변경해야했습니다. 내 셀 나는 귀하의 경우이
$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()를 사용하여 가운데 선의 어딘가에서 단어의 색을 지정하는 방법은 무엇입니까? – user1111929
, 대신 쓰기 방법을 사용할 수 있습니다 제대로 getX()와 getY()()를 사용 위치합니다 :
$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);
당신 마찬가지로 writeHTML
메소드 (tcpdf 버전 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, '');
오케이. 걱정 해 주셔서 감사합니다. –
이 링크는 실마리를 줄 수 없습니까? http://stackoverflow.com/questions/3477372/make-text-wrap-in-a-cell-with-fpdf – hmatar
하지만 나는 여전히 한 줄에 머물고 싶습니다. 나는 텍스트 색상에 대해서만 시각적 인 차이를 만들고 싶습니다. 어쩌면 내가 잘못 읽었을지도 몰라. –