pdflib 某些 unicode 字符不呈现

pdflib certain unicode characters not rendering

我需要使用 pdflib version 8 编写 pdf, 我需要在其中打印某些 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);

输出

编辑:

尝试使用 freesans 字体而不是 dejavu,但输出没有变化。

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

您可以使用包含所需字形的字体来解决您的问题。当您检查 linked 页面 "MATHEMATICAL ITALIC SMALL A" 的页面时,您可以看到 link 到“Fonts that support U+1D44E”:

如您所见,只有少数字体支持此字形,例如“DejaVu Serif Italic”。当我使用 DejaVu 包中的 DejaVu Serif Italic (DejaVuSerif-Italic.ttf) 时,我得到了预期的输出:

当然其他字体也可能支持这种字形,您不限于 DejaVuSans Serif。

只是对您的代码的一个注释:行:

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

需要 PDFlib 9。请使用

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

相反。