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");
$vbLabelText   $csharpLabel

您可以查看產生的 PDF 輸出的 PDF 版本。

另一方面,您也可以手動變更 PDF 中的 PDF 版本標籤,例如從 1.4 變更為 2.0,但這只是一個標籤,使用此方法不會以任何有意義的方式變更 PDF 本身。

柯蒂斯·週
技術撰稿人

Curtis Chau擁有卡爾頓大學電腦科學學士學位,專長於前端開發,精通Node.js、TypeScript、JavaScript和React。他熱衷於打造直覺美觀的使用者介面,喜歡使用現代框架,並擅長撰寫結構清晰、視覺效果出色的使用者手冊。

除了開發工作之外,柯蒂斯對物聯網 (IoT) 也抱有濃厚的興趣,致力於探索硬體和軟體整合的創新方法。閒暇時,他喜歡玩遊戲和製作 Discord 機器人,將他對科技的熱愛與創造力結合。

準備好開始了嗎?
Nuget 下載 17,012,929 | 版本: 2025.12 剛剛發布