Improving PDFs with Incremental Updates in C# and .NET

SautinSoft.Pdf allows users to modify PDF documents. Users do not have to wait for the entire file (which may contain hundreds of pages or more) to be rewritten each time changes to the document are saved.

The PDF format allows changes to be made to a file while leaving the original data intact. The appendices added when the file is incrementally updated will only contain the objects that were actually added or changed.

Since the original content of the document remains in the file, it is possible to undo saved changes by deleting one or more addenda. The ability to recover the exact contents of an original document is critical when digitally signing a PDF file with multiple signatures.

For more information about PDF incremental update in SautinSoft.Pdf, see File Structure help page.

The following example shows how to load a PDF document, add pages containing text, and save the changes using the incremental update feature.

Полный код

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

Option Infer On

Imports System
Imports System.IO
Imports SautinSoft
Imports SautinSoft.Pdf
Imports SautinSoft.Pdf.Content

Namespace Sample
	Friend 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>
		Shared Sub Main(ByVal args() As String)
			' Before starting this example, please get a free 100-day trial key:
			' https://sautinsoft.com/start-for-free/

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

			Dim pdfFile As String = Path.GetFullPath("..\..\..\simple text.pdf")
			' Load a PDF document from a file.
			Using document = PdfDocument.Load(pdfFile)
				' Add a page.
				Dim page = document.Pages.Add()

				' Write a text.
				Using formattedText = New PdfFormattedText()
					formattedText.Append("Hello World again!")

					page.Content.DrawText(formattedText, New PdfPoint(100, 700))
				End Using

				' Save all the changes made to the current PDF document using an incremental update.
				document.Save()
				System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pdfFile) With {.UseShellExecute = True})
			End Using
		End Sub
	End Class
End Namespace

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.