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 operandos decodificados, y le da 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ícelo de vuelta con WritePageContentLayer; el emisor preserva el comportamiento, así que reinsertar 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 solo devuelve False ante daños estructurales graves (una cadena o un diccionario sin cerrar); los operadores desconocidos se toleran y se conservan

CanonicalNumbers controla si los números analizados conservan su texto original (predeterminado, 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 un Parse(Emit) tras activar la marca

Callback exacto de frontera de imagen inline

Establezca OnInlineImageBoundary antes de Parse para reemplazar la captura heurística BI/EI predeterminada con una prueba de frontera de bytes suministrada por el llamador

TPDFInlineBoundaryEvent = function(const Source: AnsiString;
  BIStart: Integer; out AfterEI: Integer): Boolean of object;

BIStart es la posición con base 1 de BI y AfterEI es el primer byte con base 1 después del token EI completo; devuelva False cuando no se pueda probar la frontera, lo que hace que el análisis falle sin recurrir a un delimitador adivinado

El callback nil predeterminado conserva el comportamiento heurístico existente, que es adecuado para flujos ya calificados pero no prueba fronteras arbitrarias de imágenes inline binarias; el aplanado de contenido opcional instala su prueba exacta acotada

Véase también

ParsePageContentLayer, WritePageContentLayer, TPDFContentStateTracker, TraceGraphicsStates, ApplyContentFilterChain