2011-08-06 43 views
0
<?php 
    $pdf = pdf_new(); 

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

    pdf_begin_page($pdf, 595, 842); 

    $arial = pdf_load_font($pdf, "Arial", "host", "embedding=true"); 
    pdf_setfont($pdf, $arial, 10); 

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

    pdf_end_page($pdf); 

    pdf_close($pdf); 
?> 

我在網上找到了這段代碼,只是爲了觀察PDFLib的工作原理。但是,它給了我下面的錯誤:pdf_load_font()函數,致命錯誤

Fatal error: Uncaught exception 'PDFlibException' with message 'Font 'Arial' with encoding 'host': Font file (AFM, PFM, TTF, OTF etc.) or host font not found' in C:\xampp\htdocs\test\pdf.php:8 Stack trace: #0 C:\xampp\htdocs\test\pdf.php(8): pdf_load_font(Resource id #2, 'Arial', 'host', 'embedding=true') #1 {main} thrown in C:\xampp\htdocs\test\pdf.php on line 8

+0

看起來像那個字體沒有安裝。 –

+0

閱讀錯誤信息,它會告訴你問題是什麼。您需要提到的格式之一的字體文件。 – vascowhite

+0

我在我的電腦中安裝了Arial字體。並且它採用TTF格式 –

回答

-1

我覺得PDFlib不看Windows的字體使用默認目錄,這裏是建議:

$fontdir = "C:\WINDOWS\Fonts"; 
pdf_set_parameter($pdf, "FontOutline", "arialMyName=$fontdir\arial.ttf"); 
$arial = PDF_findfont($pdf,"arialMyName","host",0); 

然後,您可以設置字體與pdf_setfont()。