Improving PDFs with Incremental Updates in C# and .NET

Incremental updates in PDF allow you to add or change the contents of a document, leaving the original data intact. This is achieved by adding new objects to the end of the file that contain only modified or added data. This approach allows you to quickly and efficiently make changes to a PDF document without overwriting the entire file, which significantly speeds up the process and reduces the file size.

Since the original contents of the document remain in the file, saved changes can be undone by deleting one or more additions. The ability to restore the exact contents of the original document is crucial when digitally signing a PDF file with multiple signatures.

Let's look at an example of how incremental updates can be used to edit a PDF document using the SautinSoft.Pdf.NET library.

  1. Add SautinSoft.PDF from NuGet.
  2. Load the PDF document.
  3. Add a page and content.
  4. Save the changes made to the current PDF document using a gradual update.
  5. Save the document.

Output result:

Complete code

using System;
using System.IO;
using SautinSoft;
using SautinSoft.Pdf;
using SautinSoft.Pdf.Content;

namespace Sample
{
    class Sample
    {
        /// <summary>
        /// Edit PDF files using incremental updates.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/pdf/help/net/developer-guide/incremental-update.php
        /// </remarks>
        static void Main(string[] args)
        {
            // Before starting this example, please get a free 100-day trial key:
            // https://sautinsoft.com/start-for-free/

            // Apply the key here:
            // PdfDocument.SetLicense("...");

            string pdfFile = Path.GetFullPath(@"..\..\..\simple text.pdf");
            // Load a PDF document from a file.
            using (var document = PdfDocument.Load(pdfFile))
            {
                // Add a page.
                var page = document.Pages.Add();

                // Write a text.
                using (var formattedText = new PdfFormattedText())
                {
                    formattedText.Append("Hello World again!");

                    page.Content.DrawText(formattedText, new PdfPoint(100, 700));
                }

                // Save all the changes made to the current PDF document using an incremental update.
                document.Save();
            }
        }
    }
}

Download


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.