python - Write formatted rtf files to change the font but keep colors and bullet points - Stack Overflow

I have a series of rtf files that I want to adjust the formatting of. The files use a variety of fonts,

I have a series of rtf files that I want to adjust the formatting of. The files use a variety of fonts, text sizes, and formatting. I want to standardize them to use 12 pt bold Arial font with no italics and 0pt line spacing. I do want to keep the existing colors and bullet points though. The files have to be .rtf because they're used in a program that requires that format.

Most of my searches have pointed me to PyRTF3. However, I have been unable to find any kind of documentation on it. I'm not really sure how to approach it.

I've tried using striprtf, but the problem is that it removes the formatting like colors and bullet points, which I need to keep. I got close by combining it with this solution, but the files have a watermark and again, no colors or bullet points.

from striprtf.striprtf import rtf_to_text
import aspose.words as aw


rtfPath = "path/to/file.rtf"
rtfLines = []
with open(rtfPath, "r") as file:
    for line in file:
        rtfLines.append(rtf_to_text(line))

newdoc = aw.Document()
builder = aw.DocumentBuilder(newdoc)
font = builder.font
font.bold = True
font.name = "Arial"
font.size = 12

paragraphFormat = builder.paragraph_format
paragraphFormat.alignment = aw.ParagraphAlignment.JUSTIFY
paragraphFormat.keep_together = True
for line in rtfLines:
    builder.writeln(line.rstrip("\n"))
newdoc.save(rtfPath)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742329087a4423344.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信