0

I'm having a problem with rendering a string of text that contains half-width kana in a PDF. It considers the half-width kana to be full-width so it turns out something like this:

Half-width kana being considered as full-width

This is my code snippet:

PDF::Cell(15, 6, '商品コード', 1, 0, 'C', 0, '', 0);

I'm also using the cid0jp font provided in TCPDF to display Japanese characters:

PDF::SetFont('cid0jp', 'B', 9);

In the end, I want it to maintain the half-width katakana to fit the cell and remove unnecessary spaces.

TCPDF Library used: https://tcpdf.org/

4

1 回答 1

0

当您使用cid0jp字体时,您会将字体渲染留给 PDF 阅读器,这可能会在不同阅读器和操作系统之间引入渲染差异。间距差异可能非常大,但我不确定这是否是 TCPDF 实现的问题,或者仅仅是依赖阅读器提供字体的结果。

下面,我提供了一个示例,比较 Microsoft Edge 和 Foxit Reader 在cid0jp. 我还在第二行包含了全角版本。Edge 在半角的间距上比 Foxit 更近一些。Google Drive 的 PDF 预览与 Foxit 所做的相同,只是在半角周围增加了间距。

由于您正在使用的空间非常紧凑,因此可能值得将特定字体嵌入到文档中。在我的测试中,就渲染而言,这要可靠得多。(我还在下面包含了该测试的屏幕截图。如果您不希望每个文件中包含整个字体,请确保启用子集。)

以防万一您可能不知道该怎么做:

$embfont = TCPDF_FONTS::addTTFfont('/Path/to/font.ttf', 'TrueTypeUnicode', '', 32);
$pdf->setFont($embfont, '', '9');
$pdf->Cell(15,6,'商品コード',1,0,'C',0,'',0);

cid0jp 的示例:

cid0jp 渲染差异示例

嵌入字体的示例:

(不可否认,这种字体在小尺寸时不是很好。)

嵌入字体的示例

于 2018-09-18T05:19:48.110 回答