2012-01-16 102 views

回答

0

注:閱讀下面

羅斯麥克萊倫的回答據我記得你不能用香草FPDF做。您可以將其擴展爲具有可爲您返回此值的方法,或者將寬度存儲爲fpdf對象的公共屬性。

+1

下面的答案應該是接受的答案。 – 2014-07-18 11:12:17

+1

是的,它應該.. – Mchl 2014-07-19 23:28:59

+0

寬度:$ this-> w height:$ this-> h – 2017-09-01 05:49:12

42

需要自己做這個,所以只是檢查最新版本的FPDF,它看起來像寬度&高度已經可以作爲公共屬性。因此,爲尋找同樣的信息:

$pdf = new FPDF(); 
$pdf->addPage("P", "A4"); 

$pdf -> w; // Width of Current Page 
$pdf -> h; // Height of Current Page 

$pdf -> Line(0, 0, $pdf -> w, $pdf -> h); 
$pdf -> Line($pdf -> w, 0, 0, $pdf -> h); 

$pdf->Output('mypdf.pdf', 'I'); 
+2

這是正確的答案,雖然這不是在文檔頁面上。 – 2014-01-13 16:43:27

+0

您必須在當前的FPDF版本中將公開更改爲公開。 – 2016-03-08 07:36:59

+5

GetPageWidth()現在可用 – hendr1x 2016-05-10 13:17:08

3

包住有人需要得到寬度考慮利潤考慮......

class FPDF_EXTEND extends FPDF 
{ 

    public function pageWidth() 
    { 
     $width = $this->w; 
     $leftMargin = $this->lMargin; 
     $rightMargin = $this->rMargin; 
     return $width-$rightMargin-$leftMargin; 
    } 

} 
2

更新:2017年11月

Nowadasy,你可以簡單地調用GetPageWidthGetPageHeight方法。

$pdf = new FPDF(); 
$pdf->addPage("P", "A4"); 

$pdf->GetPageWidth(); // Width of Current Page 
$pdf->GetPageHeight(); // Height of Current Page 
+0

GetPageWidth返回什麼度量?像素?毫米?釐米? – Broshi 2018-01-23 20:08:29

+0

毫米,釐米,英尺或英寸。默認情況下,它是毫米。你可以在創建'FPDF'時改變它來指定另一個測量。 – 2018-01-24 07:49:32

相關問題