Versions de fichiers PDF
Comment changer la version du PDF ?
La balise de version PDF est définie en fonction des fonctionnalités utilisées lors de la création d'un PDF.
Par exemple :
- Un PDF de base sans fonctionnalités avancées utilisées sera probablement de version 1.4
- L'ajout d'une fonctionnalité avancée, comme des calques, signifie que la balise de version passe à 1.7
- Supprimer des calques du PDF changerait la balise de version à nouveau à 1.4
Les outils de création de PDF essaieront toujours d'utiliser la version PDF la plus basse pour des raisons de compatibilité.
Cependant, une astuce qui peut être utilisée pour changer la version d'un fichier PDF de 1.4 à 1.7 via IronPDF consiste à utiliser la combinaison de la méthode statique PdfDocument.Merge() et de la méthode PdfDocument.RemovePage(). L'extrait de code ci-dessous montre comment cela peut être fait :
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")
Vous pouvez vérifier la version PDF du résultat en sortie PDF.
D'autre part, vous pouvez aussi changer la balise de version PDF manuellement dans un PDF, par exemple de 1.4 à 2.0, mais ce n'est qu'une balise et cela ne changera pas le PDF lui-même de manière significative en utilisant cette méthode.

