PDF檔案版本

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 中的 PDF 版本標籤,例如從 1.4 變更為 2.0,但這只是一個標籤,使用此方法不會以任何有意義的方式變更 PDF 本身。

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。

準備好開始了嗎?
Nuget 下載 16,493,056 | Version: 2025.11 剛發表