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 本身。
準備好開始了嗎?
Nuget 下載 18,560,885 | 版本: 2026.4 剛剛發布

