白を意味するテキストは白としてSetTextColorを使用し、オレンジはオレンジを使用するようにします。FPDF:セル内でテキストの色を変更しますか?
$pdf->SetTextColor(255,255,255);
$pdf->Cell(50,0,'WHITE ORANGE ORANGE WHITE',0,1,'C');
オレンジ色のテキストカラーを使用するには、どのように 'ORANGE'ワードに影響を与えますか?
白を意味するテキストは白としてSetTextColorを使用し、オレンジはオレンジを使用するようにします。FPDF:セル内でテキストの色を変更しますか?
$pdf->SetTextColor(255,255,255);
$pdf->Cell(50,0,'WHITE ORANGE ORANGE WHITE',0,1,'C');
オレンジ色のテキストカラーを使用するには、どのように 'ORANGE'ワードに影響を与えますか?
回答#1:できません。定義上のセルは、フォントと色が統一されています。 getStringWidthを使って単語の幅を測定し、それを一連のセルで行うことができます。
回答#2:寄付されたスクリプトの多くは、組み込み関数のバリエーションを構築することに基づいています。結局のところ、あなたはすべてのFPDFのためのPHPコードがあります。フレーズの配列と別の配列、または2つまたは3つの属性を取る独自のCell_plus関数を作成することができます。その後、追加のスクリプトとしてそれを提供するかもしれません。
少しトリックが可能です。私はちょうどそれはこのように、2個の細胞、他の上で1つの印刷を作っ:
//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);
}
と同じオレンジ色のために行くように関数を定義することができ、その代わりに 関数を呼び出しました。
TIP:のgetX()とのgetYを(使用し、適切にそれを配置する)
あなたのソリューションは私にとってはうまくいかないようです...この例のように、getX()とgetY()を使用して、中心にあるラインのどこかに単語の色を付けるにはどうすればよいですか? – user1111929
あなたはセル方式を使用する必要がない場合は、代わりに、Writeメソッドを使用することができます。
$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 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, '');
大丈夫です。ご心配いただきありがとうございます。 –
このリンクは手がかりを与えられませんか? http://stackoverflow.com/questions/3477372/make-text-wrap-in-a-cell-with-fpdf – hmatar
しかし、私はまだそれを1行にとどめたいので、これで混乱しています。私は、テキストの色のみの視覚的な違いを見ています。たぶん私は何かを間違えた。 –