虾和文本格式

发布于 2024-10-03 15:56:41 字数 354 浏览 0 评论 0原文

Prawn/prawnto 是生成 pdf 文件的好东西。但我无法完全按原样呈现格式化文本。 Prawn 正在渲染所有 html 标签

。作为字符串。下面是我编写的代码

pdf.text "#{@product.name}", :size => 20、:样式=> :粗体
pdf.text "Ashis Rai"

并希望看到结果,

Nokia N97  
Ashis Rai

但我得到的最终结果如下

诺基亚 N97
阿希斯·雷

Prawn/prawnto is cool stuff to generate pdf file. But I am not able to render formatted text exactly as they are. Prawn is rendering all the html tags <b>, <i>, <p> as string. Below is the code i have written

pdf.text "#{@product.name}", :size => 20, :style => :bold
pdf.text "<b>Ashis Rai<b>"

and want to see the result as

Nokia N97  
Ashis Rai

but I am getting final result as below

Nokia N97
<b>Ashis Rai<b>

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

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

发布评论

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

评论(2

待天淡蓝洁白时 2024-10-10 15:56:41

pdf.text 方法将渲染它传递的内容。要使文本加粗,您需要使用

pdf.text, :font_style => :bold

获取文档的一个好方法是运行
gem 服务器

然后将浏览器指向 http://localhost:8808/doc_root/prawn-core-0.8.4/rdoc/Prawn/Text.html

这将为您提供有关方法和一些选项的更多详细信息。

The pdf.text method will render what it is passed. To make the text bold you need to use

pdf.text, :font_style => :bold

A good way to get the docs is to run
gem server

Then point your browser to http://localhost:8808/doc_root/prawn-core-0.8.4/rdoc/Prawn/Text.html

This will give you more details on the methods and some of the options.

我偏爱纯白色 2024-10-10 15:56:41

下面有一个选项允许我们的格式化文本在 pdf 文件中呈现

:inline_format => true

您可以查看 如何对 Rails 中 Prawnto 生成的 PDF 进行内联格式化(粗体和下划线)? by @Angela

There is a below option that allows our formatted text to be render in pdf file

:inline_format => true

You can look over How can I do inline formatting (bold and underline) for PDF generated by Prawnto in Rails? by @Angela

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