结合WordCreator
WordCreator毛病多多,但也有一个优点,混排不同格式的文本和图片很方便。
WordCreator有个方法ToRtfText,可以将其内容输出为RTF格式的文本,这样PDFCreator遇到一些麻烦的时候,可以考虑用WordCreator帮帮忙。
示例
同样以同一段落中,有多种不同颜色的文本为例,用WordCreator辅助实现的参考代码为:
'用WordCreator生成内容
Dim
wdc
As
New
WordCreator()
wdc.AddPicture(getimage("options.png"))
wdc.Add(
New
Word.Objects.RtfString(
"Foxtable,"))
Dim
rtr
As
New
Word.Objects.RtfString(
"Foxtable,")
rtr.ForeColor = Color.Brown
wdc.Add(rtr)
rtr =
New
Word.Objects.RtfString(
"Foxtable。")
rtr.ForeColor = Color.Green
wdc.Add(rtr)
Dim
rtf
As
String
= wdc.ToRtfText()
'获取rtf文本
Dim
file
As
String
=
"c:\temp\test.pdf"
Dim
fnt
As
New
Font("宋体",
12)
Dim
pdc
As
New
PDFCreator()
Dim
rect
As
RectangleF = pdc.PageRectangle()
rect.Inflate( - 72, - 72)
pdc.DrawStringRtf(rtf, fnt, Brushes.Black, rect)
'用DrawStringRtf方法绘制
pdc.Save(file)
Process.Start(file)
生成的文档为:
提示:
PDFCreator本就是一个小工具,难以完美渲染RTF文档,所以建议只有确实用PDFCReator难以实现的格式问题,才考虑用WordCreator辅助。