Versões em PDF
Como faço para alterar a versão em PDF?
A etiqueta da versão em PDF é definida de acordo com os recursos utilizados ao criar um PDF.
Por exemplo:
- Um PDF básico, sem o uso de recursos avançados, provavelmente terá 1,4.
- A adição de um recurso avançado, como camadas, significa que a tag de versão é atualizada para 1.7.
- Remover camadas do PDF alteraria a etiqueta de versão de volta para 1.4.
As ferramentas de criação de PDF sempre tentarão usar a versão mais antiga do PDF por motivos de compatibilidade.
No entanto, um truque que pode ser usado para mudar a versão de um arquivo PDF de 1.4 para 1.7 via IronPDF é usando a combinação do método estático PdfDocument.Merge() e o método PdfDocument.RemovePage(). O trecho de código abaixo demonstra como isso pode ser feito:
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")
Você pode verificar a versão em PDF do arquivo PDF resultante.
Por outro lado, você também pode alterar manualmente a tag da versão do PDF, digamos, de 1.4 para 2.0, mas é apenas uma tag e não alterará o PDF em si de forma significativa usando esse método.

