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 中的版本標籤,例如將 1.4 改為 2.0,但這僅僅是一個標籤,使用此方法並不會對 PDF 本身產生任何實質性的改變。
準備開始了嗎?
Nuget 下載 19,014,616 | 版本: 2026.5 just released

