TPDFContentProgram
Modifica dei flussi di contenuto
Descrizione
TPDFContentProgram (unità Lib\PDFlibContentModel.pas) è l'elenco modificabile delle istruzioni di un flusso di contenuto PDF analizzato: ogni istruzione abbina un operatore del contenuto PDF (ISO 32000-1 Table 51) ai suoi oggetti operando decodificati, e dà al codice una vista strutturata di un layer di pagina per ispezione e modifica
Si ottiene un programma con ParsePageContentLayer, si modifica l'elenco delle istruzioni e lo si riserializza con WritePageContentLayer; l'emitter preserva il comportamento, quindi riscrivere un programma non modificato renderizza la pagina esattamente come prima
TraceGraphicsStates, TraceGraphicsStatePairs e GetGraphicsState valutano il programma attraverso un TPDFContentStateTracker per ricostruire gli stati grafici effettivi
Sintassi
Delphi
TPDFContentProgram = Class
Public
Constructor Create;
Destructor Destroy; Override;
Procedure Clear;
Function Parse(Const Source: AnsiString): Boolean;
Function Emit: AnsiString;
Function EmitRange(FirstInstruction, LastInstruction: Integer): AnsiString;
Function Count: Integer;
Procedure Delete(Index: Integer);
Function DeleteRange(FirstInstruction, LastInstruction: Integer): Boolean;
Function WrapRangeWithMatrix(FirstInstruction, LastInstruction: Integer;
M11, M12, M21, M22, MDX, MDY: Double): Boolean;
Function InsertFromSource(Index: Integer; Const Source: AnsiString): Integer;
Function SetOperand(Index, OperandIndex: Integer; Const Source: AnsiString): Boolean;
Function ReplaceInlineImage(Index: Integer; Const ResourceName: AnsiString): Boolean;
Function OperandText(Index, OperandIndex: Integer): AnsiString;
Function InstructionGroup(Index: Integer): TPDFOpGroup;
Function FindNextOp(StartIndex: Integer; Op: TPDFContentOperator): Integer;
Function FindNextGroup(StartIndex: Integer; Group: TPDFOpGroup): Integer;
Function LiftPath(StartIndex: Integer): TPDFPath;
Function GetTextRuns: TPDFTextRunArray;
Function FindInstructionsInRect(Left, Top, Right, Bottom: Double;
Out Ranges: Array Of TPDFInstructionRange; IncludeText: Boolean = True): Integer;
Function EnumImagePlacements: TPDFImagePlacementArray;
Function TraceGraphicsStates(Tracker: TPDFContentStateTracker;
AfterInstruction: Boolean): TPDFContentGraphicsStateArray;
Function TraceGraphicsStatePairs(Tracker: TPDFContentStateTracker;
Out BeforeStates, AfterStates: TPDFContentGraphicsStateArray): Integer;
Function GetGraphicsState(InstructionIndex: Integer; AfterInstruction: Boolean;
Out State: TPDFContentGraphicsState): Boolean;
Function ReplaceTextRun(InstructionIndex: Integer; Const NewText: AnsiString): Boolean;
Function ReplaceTextStringRange(InstructionIndex, OperandIndex, ArrayElementIndex,
ByteOffset, ByteLength: Integer; Const NewText: AnsiString): Boolean;
Function SetMarkedContentTextProperty(InstructionIndex: Integer;
Const PropertyName: AnsiString; Const PropertyValue: WideString): Boolean;
Function SetMarkedContentPropertySource(InstructionIndex: Integer;
Const PropertyName, PropertyValueSource: AnsiString): Boolean;
Function DeleteMarkedContentProperty(InstructionIndex: Integer;
Const PropertyName: AnsiString): Boolean;
Function SetMarkedContentPropertyResource(InstructionIndex: Integer;
Const ResourceName: AnsiString): Boolean;
Function ClearMarkedContentProperties(InstructionIndex: Integer): Boolean;
Function LowerPath(Path: TPDFPath): Boolean;
Property Item[Index: Integer]: TPDFContentInstruction; Default;
Property CanonicalNumbers: Boolean;
End;Note
Parse restituisce False solo in caso di gravi danni strutturali (una stringa o un dizionario non terminato); gli operatori sconosciuti vengono tollerati e conservati
CanonicalNumbers controlla se i numeri analizzati conservano il testo sorgente (predefinito, così la riserializzazione cambia solo gli operandi modificati) oppure vengono riscritti con la precisione fissa a quattro decimali del programma; un programma restituito da ParsePageContentLayer è già analizzato, quindi per passare ai numeri canonici occorre Parse(Emit) dopo aver impostato il flag
Callback per il confine esatto delle immagini inline
Impostare OnInlineImageBoundary prima di Parse per sostituire la cattura euristica predefinita di BI/EI con una prova del confine in byte fornita dal chiamante
TPDFInlineBoundaryEvent = function(const Source: AnsiString;
BIStart: Integer; out AfterEI: Integer): Boolean of object;
BIStart è la posizione a base 1 di BI e AfterEI è il primo byte a base 1 dopo il token EI completo; restituire False quando il confine non può essere provato, il che fa fallire il parsing senza ripiegare su un delimitatore indovinato
Il callback nil predefinito conserva il comportamento euristico esistente, adatto a flussi già qualificati ma che non prova confini arbitrari di immagini inline binarie; l'appiattimento del contenuto opzionale installa la propria prova esatta e limitata
Vedere anche
ParsePageContentLayer, WritePageContentLayer, TPDFContentStateTracker, TraceGraphicsStates, ApplyContentFilterChain