Skip to main content Skip to footer

What's New in Document Solutions for PDF .NET v9

v9.1 - May 5, 2026

Document Solutions for PDF .NET (DsPdf .NET) v9.1 expands support for interactive PDF workflows with improvements to document-level JavaScripts and AcroForm field calculation order. These updates help developers build more capable PDF forms by making it easier to organize shared JavaScript logic at the document level and define calculation behavior more explicitly.

Together, these enhancements improve compatibility with standard PDF form behavior and give developers more control over how form logic is stored and managed. While v9.1 adds support for defining these scripts and calculation settings, it does not add support for executing document-level JavaScript in DsPdf .NET, DsPdfViewer, or DsPdfJS in this release.

Document-Level JavaScripts

DsPdf .NET v9.1 adds support for document-level JavaScripts, a standard PDF feature that allows reusable JavaScript functions to be stored at the document level and called from other JavaScript actions. This is especially useful in interactive forms, where shared validation or calculation logic can be defined once and reused across multiple fields or buttons.

The main API addition is GcPdfDocument.JavaScripts, a dictionary whose key is a unique script name and whose value is an ActionJavaScript object containing the associated script. This makes it easier to organize document-wide scripts in a way that aligns with the PDF specification and common Acrobat workflows.

var doc = new GcPdfDocument();
var p = doc.NewPage();
var fldA = AddTextField(p, "fldA", "fldA (should be less than 10)", 10, 10, 50);
fldA.Value = 5;
var fldB = AddTextField(p, "fldB", "fldB (should be greater than 1)", 10, 35, 50);
fldB.Value = 2;
var fldSum = AddTextField(p, "fldSum", "Sum of fldA and fldB", 10, 70, 50);
var btn = new PushButtonField();
doc.AcroForm.Fields.Add(btn);
btn.Widget.Page = p;
btn.Widget.Rect = new RectangleF(30, 120, 100, 30);
btn.Widget.ButtonAppearance.Caption = "Check & Calculate";
btn.Widget.Events.MouseDown = new ActionJavaScript("checkCalculate()");
string s =
"function checkCalculate()\r\n" +
"{\r\n" +
"    var fldA = this.getField('fldA');\r\n" +
"    var fldB = this.getField('fldB');\r\n" +
"    var fldSum = this.getField('fldSum');\r\n" +
"\r\n" +
"    var a = Number(fldA.value);\r\n" +
"    if (a >= 10)\r\n" +
"    {\r\n" +
"        app.alert('Invalid fldA.');\r\n" +
"        return false;\r\n" +
"    }\r\n" +
"\r\n" +
"    var b = Number(fldB.value);\r\n" +
"    if (b <= 1)\r\n" +
"    {\r\n" +
"        app.alert('Invalid fldB.');\r\n" +
"        return false;\r\n" +
"    }\r\n" +
"\r\n" +
"    fldSum.value = a + b;\r\n" +
"}\r\n";
doc.JavaScripts.Add("checkCalculate", new ActionJavaScript(s));
doc.Save("doc.pdf");

Help | Demo

Field Calculation Order Improvements

DsPdf .NET v9.1 also improves support for AcroForm field calculation order, making it easier to define which fields should be recalculated and in what sequence. Previously, this behavior depended on each field’s CalculationIndex, which was less intuitive and did not always reflect the intended PDF behavior when a field should be excluded from recalculation.

To simplify this, DsPdf .NET now adds the AcroForm.CalculationOrder property, which exposes the calculation order directly as an array of fields. Setting this property updates the corresponding field calculation indexes automatically. This provides a more straightforward way to manage the PDF /CO entry and makes form calculation behavior easier to inspect and control.

// This sample loads a document where the "fldSum" field is listed in AcroForm.CalculationOrder
// and replaces it with the "fldMin" field.
var doc = new GcPdfDocument();
var fs = new FileStream("DOC_7290.pdf", FileMode.Open);
doc.Load(fs);
var cf = doc.AcroForm.CalculationOrder;
Console.WriteLine(cf.Length.ToString());
Console.WriteLine(cf[0].Name);
doc.AcroForm.CalculationOrder = new Field[] { doc.AcroForm.Fields["fldMin"] };
doc.Save("doc.pdf");

Help | Demo

With support for document-level JavaScripts and a more user-friendly calculation order model, DsPdf v9.1 makes it easier to build and manage interactive PDF forms with behavior that more closely matches the PDF specification.


v9 - January 6, 2026

New Document Optimization API (Optimize)

The v9.0 release introduces a highly requested enhancement for PDF size reduction and cleanup: a new, unified Optimize() method on the GcPdfDocument class. This API brings together several existing optimization capabilities, such as image deduplication, font handling, stream compression, and object stream usage, into a single, customizable entry point. Developers can now compress and streamline PDFs with one call, significantly improving workflow efficiency and output file size.

Why a Unified Optimize Method?

DsPdf has long included multiple APIs for reducing document size, but developers often needed to combine them manually depending on the scenario. The new optimization pipeline simplifies this process by:

  • Consolidating compression and cleanup operations
  • Providing a single OptimizeDocumentOptions object to configure behaviors
  • Ensuring that optimization and saving happen together (required for options like PdfStreamHandling)
  • Making it easier to script automated processing and bulk PDF optimization workflows

This makes the new Optimize() method ideal for applications involving archiving, uploading, client-side delivery, and server-side document pipelines.

Optimize a PDF in One Line

The DsPdf v9.0 API adds two new overloads:

public void Optimize(Stream stream, OptimizeDocumentOptions options)
public void Optimize(string fileName, OptimizeDocumentOptions options)

Each performs all configured optimizations and then saves the result, ensuring optimizations that affect PDF structure take effect only on save.

Highly Configurable Optimization Options

The new OptimizeDocumentOptions class gives full control over how aggressive or conservative the optimization should be. Developers can fine-tune:

Compression & Stream Behavior
  • CompressionLevel – Overrides the document’s default compression.
  • PdfStreamHandling – Controls how existing streams are rewritten (especially useful for previously loaded PDFs).
  • UseObjectStreams – Enables single or multiple object streams to reduce size significantly.
Font Optimization
  • OptimizeFontsOptions – Shrink embedded fonts and remove unused glyphs.
  • RemoveEmbeddedFonts – Strip all embedded fonts for maximum size reduction (use with caution, as appearance may change).
Image Optimization
  • RemoveDuplicateImages – Consolidates identical image streams to reduce file size.
Document Cleanup
  • DiscardEmbeddedPageThumbnails
  • DiscardOutlines
  • DiscardSubmitImportResetActions
  • DiscardJavaScriptActions
  • DiscardEmbeddedFiles
One-Click Maximum Compression

For scenarios where smallest size is the only priority, such as archival or bandwidth-restricted environments, the SetForMinimumSize() method enables every aggressive optimization, including those not recommended for general use.

Example: Reduce PDF Size While Keeping Content Sharp

var doc = new GcPdfDocument();
using var stream = new FileStream("test.pdf", FileMode.Open);
doc.Load(stream);

var options = new OptimizeDocumentOptions
{
    DiscardEmbeddedPageThumbnails = true
};

doc.Optimize("optimized.pdf", options);

With the new Optimize() method, DsPdf v9.0 makes high-quality, automated PDF optimization easier and more powerful than ever.

Help | Demo