go - gofpdf - 居中对齐文本之间的粗体文本
问题描述
我想在居中对齐的文本之间呈现文本。这是我尝试过的
html := pdf.HTMLBasicNew()
_, lineHt := pdf.GetFontSize()
html.Write(lineHt, "<center>My name is <b>Bot<b></center>")
但仅My name is
与中心对齐而不是整个文本My name is Bot
如何使用gofpdf 或 go 中的任何其他包来实现这一点?
解决方案
我创建了一个用于生成 pdf 的简单程序并将您的代码片段插入其中,但我没有遇到任何问题,整个文本My name is Bot
都与中心对齐。以下是我编写的代码:
package main
import (
"github.com/jung-kurt/gofpdf"
)
func main() {
pdf := gofpdf.New("P", "mm", "A4", "")
pdf.AddPage()
pdf.SetFont("Courier", "", 16)
html := pdf.HTMLBasicNew()
_, lineHt := pdf.GetFontSize()
html.Write(lineHt, "<center>My name is <b>Bot<b></center>")
err := pdf.OutputFileAndClose("myFile2.pdf")
if err != nil {
panic(err)
}
}
推荐阅读
- python - Python: Add an entry in a file and assign an ID automatically
- javascript - 管理多个 npm 包的全局别名
- flask - 如何处理 Flask 中同时包含动态和静态组件的路由?
- r - ggplot 散点图,随着值变小而变大的点。一定范围内的值都应该具有相同的大小
- php - 针对特定产品类别的 WooCommerce 自定义结帐页面重定向
- php - 如何在 Laravel 中使用 php 包?
- java - Android:使用画布绘制时如何观察视图的布局约束?
- ssh - 在 Coda 中使用 SSH ProxyJump
- flutter - 无法在颤振中使用扩展
- swift - 如何知道您在 Firestore 数据库中有多少个主要集合?