2009-06-15 6 views
0

を与える:PDFlibは、私はPHPにPDFlibのサポートを取得しようとしているが、最終的にはPDFlibをインストールする方法を考え出すした後、私はこのエラーを取得するキャッチされない例外エラー

Fatal error: Uncaught exception 'PDFlibException' with message 'Function must not be called in 'object' scope' 

php.net上の例のコードを使用する:

<?php 
// create handle for new PDF document 
$pdf = pdf_new(); 
// open a file 
pdf_open_file($pdf, "test.pdf"); 
// start a new page (A4) 
pdf_begin_page($pdf, 595, 842); 
// get and use a font object 
$arial = pdf_findfont($pdf, "Arial", "host", 1); pdf_setfont($pdf, $arial, 10); 
// print text 
pdf_show_xy($pdf, "There are more things in heaven and earth, Horatio,",50, 750); 
pdf_show_xy($pdf, "than are dreamt of in your philosophy", 50,730); 
// end page 
pdf_end_page($pdf); 
// close and save file 
pdf_close($pdf); 
?> 

これを引き起こす可能性のある人はいますか?私は周りのグーグルを試みたが、私は解決策を見つけることができませんでした。

答えて

1

使用しているPDFLibのバージョンは何ですか?それが6.0以上なら、このコードを試してみてください。

<?php 
// create handle for new PDF document 
$pdf = PDF_new(); 
// open a file 
PDF_begin_document($pdf, "test.pdf"); 
// start a new page (A4) 
PDF_begin_page_ext($pdf, 595, 842); 
// get and use a font object 
$arial = PDF_load_font($pdf, "Arial", "host", 1); pdf_setfont($pdf, $arial, 10); 
// print text 
PDF_show_xy($pdf, "There are more things in heaven and earth, Horatio,",50, 750); 
PDF_show_xy($pdf, "than are dreamt of in your philosophy", 50,730); 
// end page 
PDF_end_page_exit($pdf); 
// close and save file 
PDF_end_document($pdf); 
?> 

機能pdf_open_file, pdf_begin_page, pdf_findfont, and pdf_closeすべて廃止されました。

0

「ハード」で非常にいい方法ではありません。あなたのコードをどこかでグローバルスコープに移動してみてください。

0

ファイルを作成するパスを確認してください。

pdf_open_file($pdf, "test.pdf"); 

パスが適切でエラーがなくなるようにしてください。

0

通過する現在地の許可を確認してください。私は同じことをすることで修正されます。書き込み許可が必要です。

chmod 0777 -R <PATH> 

-Rは再帰的

パスは確かにあなたは$のPDFで

pdf_open_file($pdf, "test.pdf"); 

に格納されています。

関連する問題