IronPDF for Python 文档 入门 IronPDF for Python - 在 Python 脚本中创建、编辑和阅读 PDF。 Curtis Chau 已更新:七月 22, 2025 下载 IronPDF pip 下载 免费试用 法学硕士副本 法学硕士副本 将页面复制为 Markdown 格式,用于 LLMs 在 ChatGPT 中打开 向 ChatGPT 咨询此页面 在双子座打开 向 Gemini 询问此页面 在双子座打开 向 Gemini 询问此页面 打开困惑 向 Perplexity 询问有关此页面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 复制链接 电子邮件文章 This article was translated from English: Does it need improvement? Translated View the article in English IronPDF for Python介绍 IronPDF for Python 是由 Iron Software 开发的一个功能强大的库,它为软件工程师提供了在 Python 3 项目中创建、编辑和提取 PDF 内容的功能。 IronPDF for Python是在IronPDF for .NET的成功和流行基础上构建的。 IronPDF for Python 的主要功能: 从 HTML、URL、JavaScript、CSS 和各种图像格式生成 PDF 为 PDF 添加页眉/页脚、签名、附件、密码和安全性 通过全面的多线程和异步支持优化性能 浏览我们的网站,了解 50 多种功能的综合列表,并访问大量代码示例 使用 IronPDF for Python 前提条件 要使用 Python 的 IronPDF,请确保计算机上安装了以下前置软件: .NET 6.0 SDK :IronPDF for Python 依赖于 IronPDF for .NET 库,特别是 .NET 6.0 作为其底层技术。 因此,要使用 IronPDF for Python,您的计算机上必须安装.NET 6.0 SDK 。 Python :从 Python 官方网站下载并安装最新版本的 Python 3.x:https://www.python.org/downloads/。 在安装过程中,确保选择将 Python 添加到系统 PATH 的选项,以便可以从命令行访问它。 Pip:从 Python 3.4 开始,Pip 通常与 Python 安装捆绑。 29. 然而,根据您的 Python 安装,您可能需要检查 pip 是否已安装或单独安装它。 IronPDF 库:可以通过 pip 添加 IronPDF 库。使用下面的命令通过 pip 安装 IronPDF: pip install ironpdf 提示要安装特定版本的 IronPdf,请使用以下语法:"==2023.x.x"。 例如,您可以运行命令 "pip install ironpdf==2023.x.x". 请注意在某些系统中,Python 2.x 可能仍是默认版本。 在这种情况下,您可能需要明确使用 pip3 命令,而不是 pip 命令,以确保您使用的是 Python 3. 潜在的安装问题 对于以下任一问题,请参考故障排除文章进行解决: 由于操作系统错误,无法安装软件包。 -未能找到 IronPdf.Slim.dll 开始编写 Python 代码 使用以下语句导入生成和处理 PDF 文档所需的必要模块。 请确保在 Python 脚本的开头导入它们。 # Import necessary components from the IronPDF library from ironpdf import * # Import necessary components from the IronPDF library from ironpdf import * PYTHON 应用许可证密钥 接下来,通过将许可证密钥分配给License对象的LicenseKey属性,将有效的许可证密钥或试用密钥应用于 IronPDF。 在导入语句之后、使用任何 IronPDF 方法之前,添加以下代码: # Apply the license key for IronPDF License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01" # Apply the license key for IronPDF License.LicenseKey = "IRONPDF-MYLICENSE-KEY-1EF01" PYTHON 请注意确保在调用任何 IronPDF 方法之前执行所有设置、日志记录和许可操作。 将 HTML 渲染为 PDF 使用RenderHtmlAsPdf方法将 HTML 字符串转换为 PDF 文档。 以下代码将简单的 HTML 字符串转换为 PDF 文档: from ironpdf import * # Instantiate ChromePdfRenderer renderer = ChromePdfRenderer() # Create a PDF from an HTML string pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>") # Save the generated PDF to a file pdf.SaveAs("html_to_pdf.pdf") from ironpdf import * # Instantiate ChromePdfRenderer renderer = ChromePdfRenderer() # Create a PDF from an HTML string pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>") # Save the generated PDF to a file pdf.SaveAs("html_to_pdf.pdf") PYTHON 将URL转换为PDF 使用RenderUrlAsPdf方法将 URL 或本地文件路径转换为 PDF 文档。 下面是一个例子: from ironpdf import * # Instantiate ChromePdfRenderer renderer = ChromePdfRenderer() # Create a PDF from a URL or local file path pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/") # Save the generated PDF to a file pdf.SaveAs("url_to_pdf.pdf") from ironpdf import * # Instantiate ChromePdfRenderer renderer = ChromePdfRenderer() # Create a PDF from a URL or local file path pdf = renderer.RenderUrlAsPdf("https://ironpdf.com/") # Save the generated PDF to a file pdf.SaveAs("url_to_pdf.pdf") PYTHON 日志记录 要启用日志记录,请使用以下代码片段: # Enable debugging for logging Logger.EnableDebugging = True # Specify the log file path Logger.LogFilePath = "Default.log" # Set the logging mode to log all activities Logger.LoggingMode = Logger.LoggingModes.All # Enable debugging for logging Logger.EnableDebugging = True # Specify the log file path Logger.LogFilePath = "Default.log" # Set the logging mode to log all activities Logger.LoggingMode = Logger.LoggingModes.All PYTHON 可用的许可和支持 购买许可证即可在实际项目中使用。 这里还提供 30 天试用许可证。 如需查看完整的代码示例、教程、许可信息和文档,请访问: IronPDF for Python 。 如需更多支持或有任何疑问,请联系我们的团队。 Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 准备开始了吗? Version: 2025.9 刚刚发布 免费 pip 安装 查看许可证