PDF 文件版本
This article was translated from English: Does it need improvement?
TranslatedView 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");$vbLabelText $csharpLabel
您可以检查生成的 PDF 输出的 PDF 版本。
另一方面,您 也可以 手动在 PDF 中更改版本标签,例如从 1.4 到 2.0,但那只是一个标签,并不会以任何实质性方式改变 PDF 本身。
准备开始了吗?
Nuget 下载 17,012,929 | 版本: 2025.12 刚刚发布






