PDFファイルのバージョン
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")
得られるPDF出力のPDFバージョンを確認できます。
一方、PDFバージョンタグを例えば1.4から2.0に手動で変更することもできますが、それは単なるタグであり、この方法を使用してPDF自体が何か意味のある形で変更されるわけではありません。

