Loaded Document Sanitization

SanitiseLoadedDocument applies a selected security policy to the complete loaded object graph and prepares a compact full rewrite

Profiles

ProfileRemoved content
spJavaScriptOnlyDocument JavaScript name trees and JavaScript actions
spActiveContentJavaScript plus launch, remote navigation, URI, submission, import, multimedia, rendition, XFA, and related active-content entries
spUntrustedDocumentAll active content plus embedded files, associated files, file-attachment annotations, rich-media payload structures, and unknown action types found in action-bearing slots
spRichMediaOnlyRich-media annotations and their detached payload streams
spRedactionCleanupRedact and file-attachment annotations, document information, metadata, associated and embedded files, and every object made unreachable by those removals

Declaration

function SanitiseLoadedDocument(Profile: THPDFSanitiseProfile;
  out Report: THPDFSanitiseReport): Boolean; overload;
function SanitiseLoadedDocument(
  out Report: THPDFSanitiseReport): Boolean; overload;
function ScrubLoadedRedactionRemnants(
  out Report: THPDFSanitiseReport): Boolean;

The overload without a profile uses spUntrustedDocument

Result report

THPDFSanitiseReport counts removed actions, JavaScript entries, embedded files, risky annotations, XFA entries, payload streams, detached references, unreachable objects, metadata entries, Redact annotations, discarded prior-revision bytes, and visited objects

Changed indicates whether the object graph changed, while LimitExceeded and InvalidObjectGraph explain a rejected preflight

Safety and performance

Example

var
  Report: THPDFSanitiseReport;
begin
  PDF.LoadFromFile('untrusted.pdf');
  if not PDF.SanitiseLoadedDocument(spUntrustedDocument, Report) then
    raise Exception.Create('Document sanitisation was rejected');
  PDF.SaveLoadedDocument('sanitised.pdf');
end;

Usage notes

Related APIs