如何在Ruby on Rails生成PDF文件中用大虾在一行中设置两种不同的字体样式?

发布于 2024-10-06 12:46:02 字数 192 浏览 0 评论 0原文

我有以下代码:


    pdf = Prawn::Document.new
    pdf.text "Hello", :size => 22
    pdf.text "wold", :size => 12

但此代码显示两行。 我希望将两个文本元素放在一行中,并具有相应的不同字体大小。

I have the following code:


    pdf = Prawn::Document.new
    pdf.text "Hello", :size => 22
    pdf.text "wold", :size => 12

But this code displays two lines.
I want to have the two text elements in one single line with the different font sizes as corresponding.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冰魂雪魄 2024-10-13 12:46:02

我不确定支持哪些标签,但这可能可以解决问题。

require 'prawn/format'
text "<font size=\"22\">Hello</font> <font size=\"12\">world</font>", inline_format => true

我在此处找到了这个答案。

I'm not sure which tags are supported, but this might do the trick.

require 'prawn/format'
text "<font size=\"22\">Hello</font> <font size=\"12\">world</font>", inline_format => true

I found this answer here.

烟火散人牵绊 2024-10-13 12:46:02

这是一个旧的方法,但现在您可以这样使用 formatted_text 方法:

    formatted_text [ 
                     { text: "Hello", size: 22 },
                     { text: "world", size: 12 }
                   ]

手册中的更多信息: http:// prawnpdf.org/manual.pdf

This is an old one, but now you can use the formatted_text method that way :

    formatted_text [ 
                     { text: "Hello", size: 22 },
                     { text: "world", size: 12 }
                   ]

more info in the manual : http://prawnpdf.org/manual.pdf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文