跳至页脚内容
文字工具

可以将 PDF 添加到 Word 文档中吗(初学者指南)

本指南重点介绍如何使用Microsoft Word的"插入对象"功能将PDF文件插入到Microsoft Word文档中。 此方法在允许直接从Word中访问的同时保留了原始文档格式。 我们将逐步讲解这一过程,讨论其优点和局限性,并讨论特定用例的替代方法。

在文章结尾,我们将简要介绍面向开发者的IronWordIronPDF库,提供编程解决方案。 这些工具提供了与PDF和Word文档相关操作的高级功能。 让我们了解如何将PDF作为嵌入对象添加到Word文档中。

2. 在Word中插入PDF作为对象

要在Word文档中添加PDF作为对象,请按照以下步骤操作:

  1. 打开您的Word文档。
  2. 将光标定位在您想要插入PDF的地方。
  3. 转到功能区上的"插入"选项卡。
  4. 在"文本"组中,点击"对象"。
  5. 在对象对话框中切换到"从文件创建"选项卡。
  6. 点击"浏览"以找到您的PDF文件。
  7. 选择PDF并点击"打开"。
  8. 可以选中"链接到文件"或"作为图标显示"选项。
  9. 点击"确定"将PDF插入到您的文档中。

让我们详细检查每个步骤:

2.1 访问对象插入功能

对象插入功能位于插入选项卡中,其中包含用于向文档添加内容的各种工具。 对象按钮通常位于文本组中,与其他插入选项一起。

您可以将PDF添加到Word文档 (初学者指南): 图1

2.2 从文件创建

对象对话框中的"从文件创建"选项卡允许您插入现有文件。 在这里,您将选择要插入的PDF文件。

您可以将PDF添加到Word文档 (初学者指南): 图2

2.3 文件选择

使用浏览按钮导航您的文件系统并选择所需的PDF。 Word支持多种文件类型,但本指南专注于PDF文件。

您可以将PDF添加到Word文档 (初学者指南): 图3

2.4 插入选项

两个复选框提供了有关如何插入PDF的额外控制:

  • 链接到文件:创建一个指向原始PDF的链接,而不是将其嵌入到文档中。 这使Word文件大小更小,但需要链接的PDF保持在其原始位置。
  • 作为图标显示:显示PDF文档为图标,而不是其第一页。 这对于保持文档布局整洁非常有用。

点击确定后,它将以嵌入对象的形式将PDF插入到Word文档中。

您可以将PDF添加到Word文档 (初学者指南): 图4

还有一种方法是使用Adobe Acrobat将PDF转换为Word,然后将其插入到Word文档中。 通过这种方式,用户将看到内容直接显示。

使用IronPDF和IronWord的高级PDF和Word文档处理

虽然IronPDF和IronWord不直接支持将PDF插入到Word文档中,但它们提供了强大的PDF和Word文档处理功能,在涉及两种格式的工作流中非常有价值。

IronPDF for .NET PDF库

您可以将PDF添加到Word文档 (初学者指南): 图5 - IronPDF:C# PDF库

IronPDF是为.NET开发者设计的PDF库。 它允许用户直接从C#、F#或VB.NET代码创建、编辑和操作PDF。 该库支持从HTML、URL字符串和原始HTML文件渲染PDF。 它还包括密码保护、数字签名、注释和文本提取。 支持多种.NET环境(包括.NET Core、Framework和Standard),IronPDF与Windows、Linux、macOS和像Docker这样的容器化环境兼容。

它还支持PDF/A合规性,使其适合存档和法律使用案例。 高级功能包括HTML/CSS集成、可自定义的页面设置,以及在PDF中嵌入图像和JavaScript等多媒体元素的选项。

using IronPdf;

const string htmlWithJavaScript = @"
<h2>New HTML Content</h2>
<script>
    document.write('<p>This text is generated by JavaScript</p>');
    window.ironpdf.notifyRender();
</script>";

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.EnableJavaScript = true;
// Adjusted the JavaScript wait time
renderer.RenderingOptions.WaitFor.RenderDelay = 150; 

// Renders the HTML as a PDF including the JavaScript-generated content
var pdfWithJavaScript = renderer.RenderHtmlAsPdf(htmlWithJavaScript);

// Saves the generated PDF on disk
pdfWithJavaScript.SaveAs("javascript-in-html-v2.pdf");
using IronPdf;

const string htmlWithJavaScript = @"
<h2>New HTML Content</h2>
<script>
    document.write('<p>This text is generated by JavaScript</p>');
    window.ironpdf.notifyRender();
</script>";

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.EnableJavaScript = true;
// Adjusted the JavaScript wait time
renderer.RenderingOptions.WaitFor.RenderDelay = 150; 

// Renders the HTML as a PDF including the JavaScript-generated content
var pdfWithJavaScript = renderer.RenderHtmlAsPdf(htmlWithJavaScript);

// Saves the generated PDF on disk
pdfWithJavaScript.SaveAs("javascript-in-html-v2.pdf");
Imports IronPdf

Private Const htmlWithJavaScript As String = "
<h2>New HTML Content</h2>
<script>
    document.write('<p>This text is generated by JavaScript</p>');
    window.ironpdf.notifyRender();
</script>"

Private renderer = New ChromePdfRenderer()
renderer.RenderingOptions.EnableJavaScript = True
' Adjusted the JavaScript wait time
renderer.RenderingOptions.WaitFor.RenderDelay = 150

' Renders the HTML as a PDF including the JavaScript-generated content
Dim pdfWithJavaScript = renderer.RenderHtmlAsPdf(htmlWithJavaScript)

' Saves the generated PDF on disk
pdfWithJavaScript.SaveAs("javascript-in-html-v2.pdf")
$vbLabelText   $csharpLabel

IronWord .NET Word库

您可以将PDF添加到Word文档 (初学者指南): 图6

IronWord是Iron Software套件中的另一个库,专注于处理Microsoft Word文档(DOCX)。 它提供了一个简单的API,以编程方式使用.NET语言创建、读取和编辑Word文档。 与IronPDF一样,IronWord与其他库无缝集成,提供了一系列文档操作功能,如修改DOCX文件中的文本、表格和图像。

库可以生成动态报告、合并文档或将DOCX文件转换为其他格式。 它还支持文档格式、模板创建和数据绑定,使其非常适合需要自动化或自定义Word文档的应用程序。

using IronWord;
using IronWord.Models;

// Creates a text object to be inserted into a Word document
Text textRun = new Text("Sample text");

// Creates a paragraph object to hold the text
Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);

// Initializes a new Word document with the paragraph
WordDocument doc = new WordDocument(paragraph);

// Saves the Word document to disk
doc.SaveAs("Sample Doc.docx");
using IronWord;
using IronWord.Models;

// Creates a text object to be inserted into a Word document
Text textRun = new Text("Sample text");

// Creates a paragraph object to hold the text
Paragraph paragraph = new Paragraph();
paragraph.AddChild(textRun);

// Initializes a new Word document with the paragraph
WordDocument doc = new WordDocument(paragraph);

// Saves the Word document to disk
doc.SaveAs("Sample Doc.docx");
Imports IronWord
Imports IronWord.Models

' Creates a text object to be inserted into a Word document
Private textRun As New Text("Sample text")

' Creates a paragraph object to hold the text
Private paragraph As New Paragraph()
paragraph.AddChild(textRun)

' Initializes a new Word document with the paragraph
Dim doc As New WordDocument(paragraph)

' Saves the Word document to disk
doc.SaveAs("Sample Doc.docx")
$vbLabelText   $csharpLabel

结论

您可以将PDF添加到Word文档 (初学者指南): 图7

将PDF作为嵌入对象添加到Word文档中,允许您在保持原始文档格式的同时在Word DOC中插入PDF。 这种方法可以帮助您在不使用Word转换器的情况下将整个PDF添加至Word格式。 插入的PDF内容保持其源文件格式,这意味着它不会在Word文档中转换为可编辑文本。

对于那些需要更高级文档处理功能的人,IronPDF和IronWord提供了强大的解决方案。 这些库允许开发人员以编程方式操作PDF内容和Word格式文档,并提供了远远超过简单PDF插入到Word文件的灵活性。

IronPDF和IronWord都提供免费试用,让用户在购买前探索其功能。 这些强大工具的许可费从$799开始,为需要基本PDF插入之外高级文档处理功能的企业和开发者提供了一种具有成本效益的解决方案。

Jordi Bardia
软件工程师
Jordi 最擅长 Python、C# 和 C++,当他不在 Iron Software 利用这些技能时,他就在游戏编程。分享产品测试、产品开发和研究的责任,Jordi 在持续的产品改进中增加了巨大的价值。多样的经验使他面临挑战并保持投入,他表示这是在 Iron Software 工作的最喜欢的方面之一。Jordi 在佛罗里达州迈阿密长大,并在佛罗里达大学学习计算机科学和统计学。