Wersje plików PDF
Jak zmienić wersję PDF?
Znacznik wersji PDF jest ustawiany zgodnie z funkcjami użytymi podczas tworzenia PDF-a.
Na przykład:
- Podstawowy PDF bez zaawansowanych funkcji prawdopodobnie będzie mieć wersję 1.4
- Dodanie zaawansowanej funkcji, takiej jak warstwy, oznacza aktualizację znacznika wersji do 1.7
- Usunięcie warstw z PDF-a zmieni znacznik wersji z powrotem na 1.4
Narzędzia do tworzenia PDF zawsze będą starały się używać najniższej wersji PDF ze względów zgodności.
Jednak hackiem, który można wykorzystać do zmiany wersji pliku PDF z 1.4 na 1.7 za pomocą IronPDF, jest użycie kombinacji statycznej metody PdfDocument.Merge() i metody PdfDocument.RemovePage(). Poniższy fragment kodu pokazuje, jak to można zrobić:
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")
Możesz sprawdzić wersję PDF wynikowego wyjścia PDF.
Z drugiej strony, możesz również ręcznie zmienić znacznik wersji PDF, powiedzmy z 1.4 na 2.0, ale to tylko znacznik i nie zmieni to samego PDF-a w jakikolwiek znaczący sposób za pomocą tej metody.

