使用带有 unicode 的 xhtml2pdf 时遇到问题
我一直在尝试转换希伯来语 html 文件但没有成功;无论我尝试哪种编码,希伯来语字符在输出 PDF 中都会显示为黑色矩形。
我尝试了 pisa 发行版中包含的一些 unicode 测试文件: pisa-3.0.33\test\test-unicode-all.html
和 \test-bi Direction-text.html
。我在使用和不使用 --encoding utf-8
的情况下从命令行运行了 xhtml2pdf。结果相同:没有一个非拉丁字符能够通过。
这是字体问题*吗?如果 unicode 测试文件适合您,您是否做了任何设置?
*FWIW,至少其中一些语言(包括希伯来语)应该与 Arial 兼容。
编辑:或者,如果有人设置了 pisa 并且可以尝试转换上面的 unicode 测试文件,我将非常感激。
I've been trying to convert Hebrew html files without success; the Hebrew characters show up in the output PDF as black rectangles regardless of any encoding I tried.
I tried some unicode test files included in the pisa distribution: pisa-3.0.33\test\test-unicode-all.html
and \test-bidirectional-text.html
. I ran xhtml2pdf from the command line both with and without --encoding utf-8
. Same result: none of the non-Latin characters made it through.
Is this a fonts problem*? If the unicode test file works for you, was there anything you did to set it up?
*FWIW, at least some of these languages, including Hebrew, should work with Arial.
EDIT: Alternatively, if someone has pisa set up and could try converting the unicode test file above, I would be very grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将以下代码插入 html 帮助我
使用 url 而不是“verdana.ttf”,您应该在操作系统中输入字体的绝对路径
Inserting following code into html helped me
in url instead of "verdana.ttf" you should put absolute path to font in your os
如果将来有人像我一样尝试弄清楚如何正确使用 xhtml2pdf 创建包含希伯来语的 PDF 文件,这对我有用:
第一件事:将字体设置包括为@eviltrue 在我的 HTML 中进行了描述。这可以是任何字体,只要它支持希伯来语字符即可,否则输入 HTML 中的任何希伯来语字符都会在 PDF 中简单地显示为黑色矩形。
在撰写此答案时,虽然可以在 xhtml2pdf 中将希伯来语字符输出到 PDF,但希伯来语字符以相反的顺序输出,即
שלום כתה א
将是
א התйכ םולש
。此时我被困住了,但后来我偶然发现了这个SO答案:
https://stackoverflow.com/a/15449145/1918837
安装
python-bidi
后包,这里是一个完整解决方案的示例(在 python 应用程序中使用):bidi 算法的好处是,您可以在同一行中混合使用 RTL 和 LTR 语言(如上面的 HTML 示例),并且仍然可以使用格式正确的结果。
编辑:
现在最好的方法肯定是使用 wkhtmltopdf
If anyone in the future tries, like me, to figure out how to PROPERLY create a PDF file that contains Hebrew using xhtml2pdf, here's what worked for me:
First thing: including the fonts settings as described here by @eviltrue in my HTML. This can be any font as long as it supports Hebrew characters, otherwise any Hebrew characters in the input HTML would simply appear as black rectangles in the PDF.
At the time of writing this answer, while it is possible to output Hebrew characters to PDF in xhtml2pdf, Hebrew characters are outputted in revers order, i.e.
שלום כיתה א
would be
א התיכ םולש
.At this point I was stuck, but then I stumbled upon this SO asnwer:
https://stackoverflow.com/a/15449145/1918837
After installing the
python-bidi
package, here is an example of a complete solution (used in a python app):The nice thing about the bidi algorithm is that you can have mixed RTL and LTR languages in the same line (like in the HTML example above) and still have a correctly formatted result.
EDIT:
The best way to go now is definitely using wkhtmltopdf
现在 xhtml2pdf 支持
查看文档,只需将其添加到您的 html 中:
It is now supported by xhtml2pdf
see documentation, just add this to your html: