16

fpdfのJavaポートを使用しています。次のエラーが発生しています。

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

multicell の呼び出しの後に改行がないことを望みます。どうすればできますか?

2)次のことを行うと、文字列の一部が1行に印刷され、次の行に印刷されます。

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

3)次のことを行うと、myStringが出力された行の後に多くの空白行があります。1 ans 秒のパラメーターを 1 つ使用すると正しく動作します

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

何が問題ですか?

4

5 に答える 5

23

Yを書き込む前に現在の位置を取得し、生成後に「カーソル」をその位置にMultiCell戻します。このような:YMultiCell

$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);

そんな感じ。

于 2010-04-22T21:49:24.430 に答える
5

という新しいメソッドを作成しましたMultiAlignCell。と同じパラメータを取りますが、からのフィールドMultiCellが追加されています。拡張クラスに追加できます。lnCellFPDF

/**
* 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);
    }
}
于 2015-05-20T20:02:39.430 に答える
0

私の場合、メソッドを作成しませんでした。X と Y を設定し、行の最後でリセットしました。それも完璧に機能します。

        $pdf->SetFont('times', 'B', 10);
        $x = $pdf->GetX();
        $y = $pdf->GetY();
        $pdf->MultiCell($etiquetas_largura, $etiquetas_altura, $campos[$linha]['B1COD'], 0, 'L', 0, 0, $x, $y, true, 0, false, true, 0);
        $y = $y + 5;
        $pdf->SetFont('times', '', 10);
        $pdf->MultiCell($etiquetas_largura, $etiquetas_altura, $campos[$linha]['B1DESC'], 0, 'L', 0, 0, $x, $y, true, 0, false, true, 0);
        // resete x y
        $pdf->SetXY($x + $etiquetas_largura, $y - 5);
于 2021-03-03T15:45:30.647 に答える