Loaded Document Sanitisation

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
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

Declaration

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

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, and visited objects

Changed indicates whether the object graph changed, whilst 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