pub struct ContentParser { /* private fields */ }Expand description
High-level content stream parser.
Converts tokenized content streams into structured ContentOperation values.
This parser handles the operand stack and operator parsing according to PDF specifications.
§Usage
The parser is typically used through its static methods:
use oxidize_pdf::parser::content::ContentParser;
let content = b"q 1 0 0 1 50 50 cm 100 100 200 150 re S Q";
let operations = ContentParser::parse(content)?;Implementations§
Source§impl ContentParser
impl ContentParser
Sourcepub fn parse(content: &[u8]) -> ParseResult<Vec<ContentOperation>>
pub fn parse(content: &[u8]) -> ParseResult<Vec<ContentOperation>>
Parse a content stream into a vector of operators.
This is a convenience method that creates a parser and processes the entire stream.
§Arguments
content- Raw content stream bytes (may be compressed)
§Returns
A vector of parsed ContentOperation values in the order they appear.
§Errors
Returns an error if:
- Invalid operator syntax is encountered
- Operators have incorrect number/type of operands
- Unknown operators are found
§Example
use oxidize_pdf::parser::content::{ContentParser, ContentOperation};
let content = b"BT /F1 12 Tf 100 200 Td (Hello) Tj ET";
let operations = ContentParser::parse(content)?;
assert_eq!(operations.len(), 5);
assert!(matches!(operations[0], ContentOperation::BeginText));Sourcepub fn parse_strict(content: &[u8]) -> ParseResult<Vec<ContentOperation>>
pub fn parse_strict(content: &[u8]) -> ParseResult<Vec<ContentOperation>>
Parse a content stream without best-effort recovery.
Unlike Self::parse, malformed or unknown operators are returned to
the caller. This is intended for self-contained programs such as Type 3
character procedures, where silently dropping an operation could alter
the rendered glyph.
Sourcepub fn parse_content(content: &[u8]) -> ParseResult<Vec<ContentOperation>>
pub fn parse_content(content: &[u8]) -> ParseResult<Vec<ContentOperation>>
Parse a content stream into a vector of operators.
This method tokenizes the input and converts it to operations. It handles the PDF postfix notation where operands precede operators.