2016-01-21 87 views
0

我是構建PDF使用在pdflib version 8 我想使某些Unicode字符的PDFlib Unicode字符

但他們不顯示。

但是下面的字符顯示

我想知道什麼可能是可能的原因。 而我應該如何顯示上面的字符。

下面是代碼

$p = PDF_new(); 

/* open new PDF file; insert a file name to create the PDF on disk */ 
if (PDF_begin_document($p, "", "") == 0) { 
    die("Error: " . PDF_get_errmsg($p)); 
} 
PDF_set_info($p, "Creator", "Abc"); 
PDF_set_info($p, "Author", "Abc"); 
PDF_set_info($p, "Title", "Test"); 
pdf_set_option($p, "textformat=utf8"); 

PDF_begin_page_ext($p, 595, 842, ""); 
$fontdir = '/usr/share/fonts/truetype/dejavu'; 
pdf_set_parameter($p, "FontOutline", "Dejavu=$fontdir/DejaVuSans.ttf"); 
$font = pdf_load_font($p, "Dejavu", "unicode",""); 

PDF_setfont($p, $font, 24.0); 
PDF_set_text_pos($p, 50, 700); 
pdf_show_xy($p,"dejb €",100,490); 
pdf_show_xy($p,"dejb ",200,490); 
PDF_end_page_ext($p, ""); 

PDF_end_document($p, ""); 

$buf = PDF_get_buffer($p); 
$len = strlen($buf); 

header("Content-type: application/pdf"); 
header("Content-Length: $len"); 
header("Content-Disposition: inline; filename=hello.pdf"); 
print $buf; 

PDF_delete($p); 

輸出

enter image description here

編輯:

使用freesans嘗試字體代替DEJAVU,但在T沒有變化他輸出。

$fontdir = '/usr/share/fonts/truetype/freefont'; 
pdf_set_parameter($p, "FontOutline", "FreeSans=$fontdir/FreeSans.ttf"); 
$font = pdf_load_font($p, "FreeSans", "unicode","") 
+0

嘗試使用freesans而不是dejavusans – donald123

+0

@ donald123沒有它的力量工作。輸出沒有變化。檢查更新後的問題 –

回答

3

您可以通過使用包含所需字形的字體來解決您的問題。當您檢查您的鏈接頁面「數學ITALIC小A」的頁面,您可以看到一個鏈接到「Fonts that support U+1D44E‘:

正如你所看到的,只是幾個字體支持這個雕文,例如’幻覺記憶襯線斜體「。當我使用幻覺記憶襯線斜體(DejaVuSerif-Italic.ttf)從幻覺記憶包我得到的預期輸出:

enter image description here

當然還有其他字體可能支持這個字形,你是不是僅限於DejaVuSans襯線。

只是一個記錄到你的代碼:行:

pdf_set_option($p, "textformat=utf8"); 

需要的PDFlib 9.請使用

PDF_set_parameter($p, "textformat", "utf8"); 

代替。

+0

使用支持的幫助確實解決了問題。然而,我的內容是動態的,需要我每隔幾個字符在'DevajuSerif-Italic'和'DejaVuSerif'之間切換。解決這個問題的一種方法是分割字符串並不斷更改子字符串之間的字體。有沒有優雅的解決方案? –

+0

你可以使用'fallbackfonts'選項。 (請參閱軟件包中的starter_fallback.php示例或http://www.pdflib.com/en/pdflib-cookbook/fonts/starter-fallback/)在這種情況下,您可以指定一種字體,其中也應該搜索缺少的字形。 – Rainer