TPDFContentProgram
Edição de fluxos de conteúdo
Descrição
TPDFContentProgram (unidade Lib\PDFlibContentModel.pas) é a lista editável de instruções sobre um fluxo de conteúdo PDF interpretado: cada instrução pareia um operador de conteúdo PDF (ISO 32000-1 Tabela 51) com seus objetos operando decodificados, dando ao código uma visão estruturada de uma camada de página para inspeção e edição
Obtenha um programa com ParsePageContentLayer, edite a lista de instruções e serialize-a de volta com WritePageContentLayer; o emissor preserva o comportamento, então gravar de volta um programa sem modificações renderiza a página exatamente como antes
TraceGraphicsStates, TraceGraphicsStatePairs e GetGraphicsState avaliam o programa através de um TPDFContentStateTracker para reconstruir estados gráficos efetivos
Sintaxe
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;Observações
Parse retorna False apenas em caso de dano estrutural grosseiro (uma string ou dicionário sem terminador); operadores desconhecidos são tolerados e preservados
CanonicalNumbers controla se os números interpretados mantêm seu texto original (o padrão, de modo que reemitir altera apenas os operandos editados) ou são reescritos na precisão fixa de quatro casas decimais do programa; um programa retornado por ParsePageContentLayer já vem interpretado, então torná-lo canônico em números exige Parse(Emit) após definir o flag
Callback de fronteira exata de imagem inline
Defina OnInlineImageBoundary antes de Parse para substituir a captura heurística padrão de BI/EI por uma prova de fronteira de bytes fornecida pelo chamador
TPDFInlineBoundaryEvent = function(const Source: AnsiString;
BIStart: Integer; out AfterEI: Integer): Boolean of object;
BIStart é a posição de base 1 do BI e AfterEI é o primeiro byte de base 1 após o token EI completo; retorne False quando a fronteira não puder ser provada, o que faz o parsing falhar sem recorrer a um delimitador adivinhado
O callback nil padrão preserva o comportamento heurístico existente, adequado para streams já qualificados mas que não prova fronteiras arbitrárias de imagens inline binárias; o flattening de conteúdo opcional instala sua prova exata limitada
Veja também
ParsePageContentLayer, WritePageContentLayer, TPDFContentStateTracker, TraceGraphicsStates, ApplyContentFilterChain