IRONSOFTWAREHOME
RTF 转为 PDF
from ironpdf import *

# Instantiate Renderer
renderer = ChromePdfRenderer()

# Either load your RTF file directly
pdf_from_rtf_file = renderer.RenderRtfFileAsPdf("/files/doc.rtf")

# Or instead, load it as a string
pdf_from_rtf_string = renderer.RenderRtfStringAsPdf(r"{\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}}{\colortbl;\red0\green0\blue0;}\cf0This is some \b bold \b0 and \i italic \i0 text.}")

# Save your PDF
pdf_from_rtf_file.SaveAs("pdf_from_rtf_file.pdf")
pdf_from_rtf_string.SaveAs("pdf_from_rtf_string.pdf")
pip install ironpdf
RTF 转为 PDF

RTF 转为 PDF

IronPDF for Python可以将富文本格式(RTF)文档直接从文件路径或内存中的RTF字符串转换为PDF。

开始

根据您的输入源使用ChromePdfRenderer并调用两种方法之一:

  • PdfDocument。
  • PdfDocument。

两种方法都生成一个可以保存、合并、修改或进一步使用IronPDF的完整编辑API的PdfDocument对象。

理解代码

  • RenderRtfFileAsPdf:从磁盘读取RTF文件并将其内容(包括字体、粗体、斜体和颜色格式)转换为精确的PDF表示。
  • RenderRtfStringAsPdf:允许RTF内容直接作为Python字符串传递,省去了首先将临时文件写入磁盘的步骤。
  • PdfDocument写入指定的输出路径。

RTF字符串格式

RTF字符串使用类似{\rtf1\ansi ... }的标记语法。 粗体文本用\b ... \b0 and italic with \i ... \i0包裹。 标准字体和颜色表声明必须存在以确保正确渲染。

了解更多关于使用IronPDF for Python生成PDF的信息!

准备开始了吗?

版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥。

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

OR
bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥。
无需信用卡或创建账户
Python 模块下载 PDF
using pip 安装

版本: 2026.9

  1. 下载 并安装 Python 3.7+。
  2. 如果尚未安装,请从 pypi.org 安装 pip。
  3. 在终端中执行上述命令。
Python PDF 模块
下载 模块

版本: 2026.9

手动安装到您的项目中

  1. 下载软件包
  2. 在终端中运行此命令
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

$999 起