【发布时间】:2020-07-06 14:54:48
【问题描述】:
我尝试使用 AliasNbPage() 来获取 pdf 的总页数。我确实调用了“{nb}”来获取总页数,但它没有给出输出数字而不是 {nb}。还有另一种方法可以获得总页数吗?
$tot = strval(explode('/', strval($this->pdf->PageNo().'/{nb}'))[1]);
$this->pdf->SetX(44);
$this->pdf->Cell(40,5,": ".$tot.' Pages',0,1);
//while i'm tried to convert the number to the text, it doesn't show.
$this->pdf->Cell(40,5,": ".numb_to_text(intval($tot)).' Pages',0,1);
function init_number($nilai) {
$nilai = abs($nilai);
$huruf = array("", "satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh", "sebelas");
$temp = "";
if ($nilai < 12) {
$temp = " ". $huruf[$nilai];
} else if ($nilai <20) {
$temp = $this->init_number($nilai - 10). " belas";
} else if ($nilai < 100) {
$temp = $this->init_number($nilai/10)." puluh". $this->init_number($nilai % 10);
} else if ($nilai < 200) {
$temp = " seratus" . $this->init_number($nilai - 100);
} else if ($nilai < 1000) {
$temp = $this->init_number($nilai/100) . " ratus" . $this->init_number($nilai % 100);
} else if ($nilai < 2000) {
$temp = " seribu" . $this->init_number($nilai - 1000);
} else if ($nilai < 1000000) {
$temp = $this->init_number($nilai/1000) . " ribu" . $this->init_number($nilai % 1000);
} else if ($nilai < 1000000000) {
$temp = $this->init_number($nilai/1000000) . " juta" . $this->init_number($nilai % 1000000);
} else if ($nilai < 1000000000000) {
$temp = $this->init_number($nilai/1000000000) . " milyar" . $this->init_number(fmod($nilai,1000000000));
} else if ($nilai < 1000000000000000) {
$temp = $this->init_number($nilai/1000000000000) . " trilyun" . $this->init_number(fmod($nilai,1000000000000));
}
return $temp;
}
function numb_to_text($nilai) {
$nilai = (int) $nilai;
if($nilai<0) {
$hasil = "minus ". trim($this->init_number($nilai));
} else {
$hasil = trim($this->init_number($nilai));
}
return $hasil;
}
【问题讨论】:
-
请向我们展示您的代码。
-
AliasNbPage返回的别名将替换为文档关闭时的实际页数。见FPDF documentation -
我尝试过这样做。 $tot = strval(explode('/', strval($this->pdf->PageNo().'/{nb}'))[1]);回声($tot);输出:2 当我输入我的函数以获取返回转换为文本时,它不会出现。我的函数将数字转换为文本没有问题,例如:conv(1) 输出:一个。