PDF格式、字间距
我正在用 PHP 实现一个 pdf 生成器 我的字间距有问题,该选项不起作用,或者我没有正确使用字间距参数。 我需要这个选项来使文本对齐。 字符间距参数工作正常。 这就是我渲染文本的方式:
BT
/F1 12 Tf
0 829 Td
5 Tw
(Hello world) Tj
ET
字间距参数为粗体。 我做错了什么?
I'm implementing a pdf generator in PHP
I have problem with word spacing, the option doesn't work or i'm not using word spacing parameter properly.
I need this option to render text justified.
The character spacing parameter works properly.
This is how I'm rendering text:
BT
/F1 12 Tf
0 829 Td
5 Tw
(Hello world) Tj
ET
Word spacing parameter is bold.
What i'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 BrianS 提到的,根据 PDF 规范。这解释了我在许多个月前必须处理的文本布局错误之一。你每天都会学到新东西。
还有另一种可能。字间距仅适用于 ASCII 0x20 (dec 32)。如果您使用不间断空格、制表符或其他任何内容而不是 ASCII 空格,则它将不起作用。查看上面的文本,事实并非如此,但您的实际 PDF 输出可能会有所不同。
As BrianS mentioned, Tw isn't applied to multi-byte fonts according to the PDF Spec. That explains one of the text layout bugs I had to deal with Many Moons Ago. Ya learn something new every day.
There's another possibility. Word spacing is only applied to ASCII 0x20 (dec 32). If you're using a non-breaking space, tab, or whatever, instead of The ASCII Space, it won't work. Looking at the above text, that's not it, but your actual PDF output could differ.
感谢您的回答。是的,我使用的是 unicode 字体。我和 TJ 接线员处理。现在我的文本输出如下所示:
[(Hello) -320 (world) -320] TJ
Btw 我必须改进我的文本对齐算法,因为文本右对齐不在一个级别上。
我编写自己的库,因为现有的库没有我需要的工具,并且所有代码都在一个类中 - 我将对象和对象元素拆分为不同的类,例如 Zend_Pdf
thanks for your answers. yes i was using unicode font. i deal with it with TJ operator. now my text output looks like that:
[(Hello) -320 (world) -320] TJ
Btw i must improve my text justify algoritm because text right align is not on one level.
And i write my own library because existing ones do not have a tools which i need and all code is in one class - i split objects and objects elements into differend classes like Zend_Pdf