TPDFContentProgram
Edición de flujos de contenido
Descripción
TPDFContentProgram (unidad Lib\PDFlibContentModel.pas) es la lista de instrucciones editable sobre un flujo de contenido PDF analizado: cada instrucción empareja un operador de contenido PDF (ISO 32000-1, tabla 51) con sus objetos operando descodificados, dando al código una vista estructurada de una capa de página para inspección y edición
Obtenga un programa con ParsePageContentLayer, edite la lista de instrucciones y serialícela de vuelta con WritePageContentLayer; el emisor conserva el comportamiento, así que escribir de vuelta un programa sin modificar renderiza la página exactamente igual que antes
TraceGraphicsStates, TraceGraphicsStatePairs y GetGraphicsState evalúan el programa mediante un TPDFContentStateTracker para reconstruir los estados gráficos efectivos
Sintaxis
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;Observaciones
Parse devuelve False solo ante daños estructurales graves (una cadena o un diccionario sin terminar); los operadores desconocidos se toleran y se conservan
CanonicalNumbers controla si los números analizados conservan su texto fuente (por defecto, de modo que reemitir solo cambia los operandos editados) o se reescriben con la precisión fija de cuatro decimales del programa; un programa devuelto por ParsePageContentLayer ya está analizado, así que pasarlo a números canónicos requiere Parse(Emit) tras establecer el indicador
Callback exacto de límites de imágenes en línea
Asigne OnInlineImageBoundary antes de Parse para sustituir la captura heurística BI/EI por defecto por una prueba de límites de bytes aportada por el llamador
TPDFInlineBoundaryEvent = function(const Source: AnsiString;
BIStart: Integer; out AfterEI: Integer): Boolean of object;
BIStart es la posición de base 1 de BI y AfterEI es el primer byte de base 1 tras el token EI completo; devuelva False cuando no pueda probarse el límite, lo que hace fallar el análisis sin recurrir a un delimitador adivinado
El callback nil por defecto conserva el comportamiento heurístico existente, adecuado para flujos ya calificados pero que no prueba límites arbitrarios de imágenes en línea binarias; el aplanado de contenido opcional instala su prueba exacta acotada
Véase también
ParsePageContentLayer, WritePageContentLayer, TPDFContentStateTracker, TraceGraphicsStates, ApplyContentFilterChain