PDFix SDK  9.0.0
Loading...
Searching...
No Matches
PsCommand Struct Referenceabstract

PsCommand class. More...

#include <pdfix.h>

Public Member Functions

virtual bool LoadParamsFromStream (PsStream *params, PsDataFormat format)=0
 Load command parameters from a JSON or XML stream.
virtual bool Reset ()=0
 Reset the command state.
virtual bool SaveOutputToStream (PsStream *stream, PsDataFormat format, PdfSaveFlags flags)=0
 Save command execution output to a stream.
virtual bool SaveActionsToStream (PsStream *stream, PsDataFormat format, PdfSaveFlags flags)=0
 Save all base action definitions into a stream.
virtual int GetNumCustomActions ()=0
 Get the number of embedded custom actions.
virtual bool SaveCustomActionToStream (int index, PsStream *stream, PsDataFormat format, PdfSaveFlags flags)=0
 Save an embedded custom action into a stream.
virtual bool SetSelection (PdfSelection *selection)=0
 Set the selection used for command execution.
virtual bool Run ()=0
 Execute the command.

Detailed Description

PsCommand class.

A PsCommand represents an executable action within the PDFix SDK command engine.

The command encapsulates a configurable processing unit that can be parameterized, executed, and queried for structured output. Commands may operate on the entire document or on a specific selection of objects.

A typical command lifecycle consists of the following steps:

  1. Load configuration parameters (JSON or XML).
  2. Optionally set a document selection.
  3. Execute the command.
  4. Retrieve structured execution output.
  5. Optionally reset the command for reuse.

Commands are stateful. After execution, the command retains its output data until Reset() is called.

Member Function Documentation

◆ GetNumCustomActions()

virtual int PsCommand::GetNumCustomActions ( )
pure virtual

Get the number of embedded custom actions.

Returns the number of custom action presets embedded in the PDFix SDK.

Custom actions are predefined JSON command configurations such as make_accessible*, fix_indesign, or quick_fix. These presets are distributed with the SDK and originate from the public repository:

https://github.com/pdfix/pdfix_sdk_batch_actions

Each custom action can be retrieved using PsCommand::SaveCustomActionToStream().

Returns
The number of embedded custom actions.

◆ LoadParamsFromStream()

virtual bool PsCommand::LoadParamsFromStream ( PsStream * params,
PsDataFormat format )
pure virtual

Load command parameters from a JSON or XML stream.

Parses and validates the command configuration from the specified stream.

This method loads the command definition, including action sequence, parameters, and settings required for execution.

The command must be configured using this method before calling Run(). If the input data cannot be parsed or validation fails, the method returns false.

Parameters
paramsInput stream containing the command configuration.
formatInput format (JSON or XML).
Returns
true if the parameters were loaded successfully, false otherwise.

◆ Reset()

virtual bool PsCommand::Reset ( )
pure virtual

Reset the command state.

Clears the currently loaded parameters, selection, and execution results.

After calling Reset(), the command returns to its initial unconfigured state and can be configured again using LoadParamsFromStream().

Returns
true on success, false otherwise.

◆ Run()

virtual bool PsCommand::Run ( )
pure virtual

Execute the command.

Executes the command using the currently loaded parameters and optional selection.

If execution fails, the method returns false. Detailed execution results, warnings, and error information can be retrieved using SaveOutputToStream().

The command state and execution results remain available until Reset() is called.

Returns
true if the command completed successfully, false otherwise.

◆ SaveActionsToStream()

virtual bool PsCommand::SaveActionsToStream ( PsStream * stream,
PsDataFormat format,
PdfSaveFlags flags )
pure virtual

Save all base action definitions into a stream.

Serializes all built-in PDFix action definitions into the specified stream.

The output corresponds to the internal equivalent of the pdf_action.json definition file that describes all base actions available in the PDFix SDK (e.g. rename_tags, set_tag_id, fix_parent_tree, etc.).

Developers can parse the exported JSON or XML to discover available actions, their parameters, and supported configuration options.

Parameters
streamOutput stream to write the serialized action definitions to.
formatOutput format (JSON or XML).
flagsSerialization options.
Returns
true on success, false otherwise.

◆ SaveCustomActionToStream()

virtual bool PsCommand::SaveCustomActionToStream ( int index,
PsStream * stream,
PsDataFormat format,
PdfSaveFlags flags )
pure virtual

Save an embedded custom action into a stream.

Serializes a predefined custom action preset into the specified stream.

The exported data corresponds to one JSON preset from the embedded custom actions collection (for example make_accessible.json or fix_indesign.json*).

Applications can parse the exported JSON to inspect the workflow or execute the action using PsCommand.

Parameters
indexIndex of the custom action. The total number of actions can be obtained using PsCommand::GetNumCustomActions().
streamOutput stream to write the serialized preset to.
formatOutput format (JSON or XML).
flagsSerialization options.
Returns
true on success, false otherwise.

◆ SaveOutputToStream()

virtual bool PsCommand::SaveOutputToStream ( PsStream * stream,
PsDataFormat format,
PdfSaveFlags flags )
pure virtual

Save command execution output to a stream.

Serializes the structured execution result of the most recent Run() call into the specified stream.

The output may include overall command status, per-action execution results, warnings, and error details.

This method is typically used after Run() to retrieve a machine-readable execution report.

Parameters
streamOutput stream to write the execution result to.
formatOutput format (JSON or XML).
flagsSerialization options.
Returns
true on success, false otherwise.

◆ SetSelection()

virtual bool PsCommand::SetSelection ( PdfSelection * selection)
pure virtual

Set the selection used for command execution.

Defines the document objects that the command should operate on.

If nullptr is specified, the command is executed on the entire document.

Call this method before Run() when selection-scoped execution is required.

Parameters
selectionSelection containing the target objects, or nullptr.
Returns
true on success, false otherwise.