简体   繁体   English

PHP TCPDF-半角假名被认为是全角

[英]PHP TCPDF - Half-width kana is being considered as Full-width

I'm having a problem with rendering a string of text that contains half-width kana in a PDF. 我在用PDF呈现包含半角假名的文本字符串时遇到问题。 It considers the half-width kana to be full-width so it turns out something like this: 它认为半角假名是全角假名,因此结果是这样的:

半角假名被认为是全角

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: 我还使用TCPDF中提供的cid0jp字体显示日语字符:

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/ 使用的TCPDF库: https : //tcpdf.org/

When you use the cid0jp font you're leaving the font rendering up to the PDF reader which can introduce differences in rendering between different readers and operating systems. 当您使用cid0jp字体时, cid0jp字体渲染留给PDF阅读器使用,这可能会导致不同阅读器和操作系统之间的渲染差异。 The spacing differences can be pretty major, but I'm not sure if that's an issue with TCPDF's implementation or just a consequence of relying on the reader to provide the font. 间距差异可能非常大,但是我不确定这是TCPDF的实现问题还是仅依靠读者提供字体的结果。

Below, I've included an example comparing Microsoft Edge and Foxit Reader rendering of that text in cid0jp . 下面,我提供了一个示例,比较了cid0jp中该文本的Microsoft Edge和Foxit Reader呈现。 I also included the full-width versions on the second line. 我还在第二行中包含了全角版本。 Edge came a little closer on the spacing for half-widths than Foxit. Edge的半角间距比Foxit靠得更近。 Google Drive's PDF preview did the same thing as Foxit did with the additional spacing around the half-widths. Google云端硬盘的PDF预览与Foxit的功能相同,只是在半角宽度周围增加了间距。

Since the space you're working with there is so tight, it might be worth embedding a specific font into the document. 由于您要处理的空间太紧,可能值得在文档中嵌入特定字体。 In my tests that was a lot more reliable as far as rendering went. 在我的测试中,就渲染而言,这要可靠得多。 (I've also included screenshots of that test below. Make sure subsetting is on if you don't want the entire font included in each file.) (我还在下面提供了该测试的屏幕截图。如果您不希望每个文件中都包含整个字体,请确保启用了子设置。)

Just in case you might not know how to do that: 以防万一您可能不知道该怎么做:

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

Examples with cid0jp: cid0jp的示例:

cid0jp渲染差异示例

Examples with embedded font: 嵌入字体的示例:

(Admittedly, this font isn't very good at small sizes.) (诚​​然,这种字体在小尺寸字体上不是很好。)

嵌入字体的例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM