How to Save and Edit PDF Revision History in C#

In this tutorial, we explore how to save and edit PDF revision history using Iron PDF in a C# console application. We begin by ensuring Iron PDF is installed via the NuGet package manager and setting up the IronPDF license. The tutorial guides you through importing a PDF file and enabling change tracking, allowing any modifications to be recorded. We demonstrate signing the PDF with a digital signature from a PFX file to maintain document integrity and authenticity. Next, we save changes as a new revision, enabling version tracking. The revision count property is checked to display the total number of saved revisions. We also illustrate how to roll back to a previous revision, ensuring flexibility in document management. The tutorial concludes with a successful execution of the project, showcasing the revised PDF files with digital signatures. For those interested in experiencing Iron PDF's capabilities, a trial is available for download. This tutorial serves as a practical guide for efficiently managing PDF revisions, ensuring secure and authentic documentation.

using System;
using IronPdf;

class Program
{
    static void Main()
    {
        // Set your IronPDF license key here
        // IronPdf.License.LicenseKey = "your_license_key";

        // Load an existing PDF document
        var pdfDocument = PdfDocument.FromFile("YourPDFDocument.pdf");

        // Enable change tracking for the PDF document
        pdfDocument.EnableChangeTracking();

        // Import a digital signature from a PFX file
        // Replace "YourPfxFile.pfx" and "your_password" with the correct values
        var signature = new PdfSignature("YourPfxFile.pfx", "your_password");

        // Sign the PDF to ensure its integrity and authenticity
        pdfDocument.Signature = signature;

        // Make a modification and save as a new revision
        // Add a new page for demonstration
        var newPage = pdfDocument.AddPage();
        newPage.HtmlContent = "<h1>New Revision Content</h1>";
        pdfDocument.SaveAs("RevisedPDFDocument.pdf");

        // Display the current revision count
        var revisionCount = pdfDocument.RevisionCount;
        Console.WriteLine($"Total number of saved revisions: {revisionCount}");

        // Roll back to the previous revision if needed
        pdfDocument.RollbackTo(revisionCount - 1);
        pdfDocument.SaveAs("RolledBackPDFDocument.pdf");

        Console.WriteLine("PDF revision operation is successful.");
    }
}
using System;
using IronPdf;

class Program
{
    static void Main()
    {
        // Set your IronPDF license key here
        // IronPdf.License.LicenseKey = "your_license_key";

        // Load an existing PDF document
        var pdfDocument = PdfDocument.FromFile("YourPDFDocument.pdf");

        // Enable change tracking for the PDF document
        pdfDocument.EnableChangeTracking();

        // Import a digital signature from a PFX file
        // Replace "YourPfxFile.pfx" and "your_password" with the correct values
        var signature = new PdfSignature("YourPfxFile.pfx", "your_password");

        // Sign the PDF to ensure its integrity and authenticity
        pdfDocument.Signature = signature;

        // Make a modification and save as a new revision
        // Add a new page for demonstration
        var newPage = pdfDocument.AddPage();
        newPage.HtmlContent = "<h1>New Revision Content</h1>";
        pdfDocument.SaveAs("RevisedPDFDocument.pdf");

        // Display the current revision count
        var revisionCount = pdfDocument.RevisionCount;
        Console.WriteLine($"Total number of saved revisions: {revisionCount}");

        // Roll back to the previous revision if needed
        pdfDocument.RollbackTo(revisionCount - 1);
        pdfDocument.SaveAs("RolledBackPDFDocument.pdf");

        Console.WriteLine("PDF revision operation is successful.");
    }
}
Imports System
Imports IronPdf

Friend Class Program
	Shared Sub Main()
		' Set your IronPDF license key here
		' IronPdf.License.LicenseKey = "your_license_key";

		' Load an existing PDF document
		Dim pdfDocument = PdfDocument.FromFile("YourPDFDocument.pdf")

		' Enable change tracking for the PDF document
		pdfDocument.EnableChangeTracking()

		' Import a digital signature from a PFX file
		' Replace "YourPfxFile.pfx" and "your_password" with the correct values
		Dim signature = New PdfSignature("YourPfxFile.pfx", "your_password")

		' Sign the PDF to ensure its integrity and authenticity
		pdfDocument.Signature = signature

		' Make a modification and save as a new revision
		' Add a new page for demonstration
		Dim newPage = pdfDocument.AddPage()
		newPage.HtmlContent = "<h1>New Revision Content</h1>"
		pdfDocument.SaveAs("RevisedPDFDocument.pdf")

		' Display the current revision count
		Dim revisionCount = pdfDocument.RevisionCount
		Console.WriteLine($"Total number of saved revisions: {revisionCount}")

		' Roll back to the previous revision if needed
		pdfDocument.RollbackTo(revisionCount - 1)
		pdfDocument.SaveAs("RolledBackPDFDocument.pdf")

		Console.WriteLine("PDF revision operation is successful.")
	End Sub
End Class
$vbLabelText   $csharpLabel

Further Reading: How to Save & Edit PDF Revision History

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.
< PREVIOUS
How to Rotate Text in PDFs Using C#
NEXT >
How to Convert Razor to PDF in Blazor Server Using C#