PDF File Versions

This article was translated from English: Does it need improvement?
Translated
View the article in English

如何更改 PDF 版本?

PDF 版本标签根据您创建 PDF 时使用的功能设置。

例如:

  • 使用基本 PDF 没有使用高级功能时,可能是 1.4
  • 添加一个高级功能,例如图层,意味着版本标签更新为 1.7
  • 从 PDF 中移除图层将使版本标签改回 1.4

PDF 创建工具总是尝试使用最低的 PDF 版本以确保兼容性。

然而,一个可以用于通过 IronPDF 将 PDF 文件版本从 1.4 更改为 1.7 的技巧是使用 PdfDocument.Merge() 静态方法和 PdfDocument.RemovePage() 方法的结合。 下面的代码片段演示了如何做到这一点:

using IronPdf;

var renderer = new ChromePdfRenderer();

// Render the initial PDF that needs its version changed.
var pdf1 = renderer.RenderHtmlAsPdf("<h1>Hello, this is the required PDF</h1>");

// Render a mock PDF to use with the Merge() method.
var pdf2 = renderer.RenderHtmlAsPdf("<h1>This is a mock PDF</h1>");

// Merge the two PDFs. This will update the version to 1.7 if new features from pdf2 are used.
var pdf3 = PdfDocument.Merge(pdf1, pdf2);

// Remove the page from the mock PDF, keeping only the original content.
var pdf4 = pdf3.RemovePage(1);

// Save the resulting PDF document. It should have a version updated to 1.7.
pdf4.SaveAs("anothermerged.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();

// Render the initial PDF that needs its version changed.
var pdf1 = renderer.RenderHtmlAsPdf("<h1>Hello, this is the required PDF</h1>");

// Render a mock PDF to use with the Merge() method.
var pdf2 = renderer.RenderHtmlAsPdf("<h1>This is a mock PDF</h1>");

// Merge the two PDFs. This will update the version to 1.7 if new features from pdf2 are used.
var pdf3 = PdfDocument.Merge(pdf1, pdf2);

// Remove the page from the mock PDF, keeping only the original content.
var pdf4 = pdf3.RemovePage(1);

// Save the resulting PDF document. It should have a version updated to 1.7.
pdf4.SaveAs("anothermerged.pdf");
Imports IronPdf

Private renderer = New ChromePdfRenderer()

' Render the initial PDF that needs its version changed.
Private pdf1 = renderer.RenderHtmlAsPdf("<h1>Hello, this is the required PDF</h1>")

' Render a mock PDF to use with the Merge() method.
Private pdf2 = renderer.RenderHtmlAsPdf("<h1>This is a mock PDF</h1>")

' Merge the two PDFs. This will update the version to 1.7 if new features from pdf2 are used.
Private pdf3 = PdfDocument.Merge(pdf1, pdf2)

' Remove the page from the mock PDF, keeping only the original content.
Private pdf4 = pdf3.RemovePage(1)

' Save the resulting PDF document. It should have a version updated to 1.7.
pdf4.SaveAs("anothermerged.pdf")
$vbLabelText   $csharpLabel

您可以检查生成的 PDF 输出的 PDF 版本。

另一方面,您 也可以 手动在 PDF 中更改版本标签,例如从 1.4 到 2.0,但那只是一个标签,并不会以任何实质性方式改变 PDF 本身。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 16,154,058 | 版本: 2025.11 刚刚发布