pub struct StructureResult {
pub input_path: Arc<str>,
pub index: usize,
pub layout_elements: Vec<LayoutElement>,
pub tables: Vec<TableResult>,
pub formulas: Vec<FormulaResult>,
pub text_regions: Option<Vec<TextRegion>>,
pub orientation_angle: Option<f32>,
pub region_blocks: Option<Vec<RegionBlock>>,
pub rectified_img: Option<Arc<ImageBuffer<Rgb<u8>, Vec<u8>>>>,
pub page_continuation_flags: Option<PageContinuationFlags>,
}Expand description
Result of document structure analysis.
This struct contains all the results from analyzing a document’s structure, including layout elements, tables, formulas, and OCR results.
§Coordinate System
The coordinate system of bounding boxes depends on which preprocessing was applied:
-
No preprocessing: Boxes are in the original input image’s coordinate system.
-
Orientation correction only (
orientation_angleset,rectified_imgis None): Boxes are transformed back to the original input image’s coordinate system. -
Rectification applied (
rectified_imgis Some): Boxes remain in the rectified image’s coordinate system. Neural network-based rectification (UVDoc) warps cannot be precisely inverted, so userectified_imgfor visualization instead of the original image. -
Both orientation and rectification: Boxes are in the rectified coordinate system (rectification takes precedence since it’s applied after orientation correction).
Fields§
§input_path: Arc<str>Path to the input image file
index: usizeIndex of the image in a batch (0 for single image processing)
layout_elements: Vec<LayoutElement>Detected layout elements (text regions, tables, figures, etc.)
tables: Vec<TableResult>Recognized tables with their structure and content
formulas: Vec<FormulaResult>Recognized mathematical formulas
text_regions: Option<Vec<TextRegion>>OCR text regions (if OCR was integrated)
orientation_angle: Option<f32>Document orientation angle (if orientation correction was used)
region_blocks: Option<Vec<RegionBlock>>Detected region blocks for hierarchical ordering (PP-DocBlockLayout) When present, layout_elements are already sorted by region hierarchy
rectified_img: Option<Arc<ImageBuffer<Rgb<u8>, Vec<u8>>>>Rectified image (if document rectification was used) Note: Bounding boxes are already transformed back to original coordinates for rotation, but for rectification (UVDoc), boxes are in the rectified image’s coordinate system. Use this image for visualization when rectification was applied.
page_continuation_flags: Option<PageContinuationFlags>Page continuation flags for multi-page document processing. This indicates whether this page continues a paragraph from the previous page or continues to the next page, which is crucial for proper markdown concatenation.
Implementations§
Source§impl StructureResult
impl StructureResult
Sourcepub fn new(input_path: impl Into<Arc<str>>, index: usize) -> StructureResult
pub fn new(input_path: impl Into<Arc<str>>, index: usize) -> StructureResult
Creates a new structure result.
Sourcepub fn with_layout_elements(
self,
elements: Vec<LayoutElement>,
) -> StructureResult
pub fn with_layout_elements( self, elements: Vec<LayoutElement>, ) -> StructureResult
Adds layout elements to the result.
Sourcepub fn with_tables(self, tables: Vec<TableResult>) -> StructureResult
pub fn with_tables(self, tables: Vec<TableResult>) -> StructureResult
Adds tables to the result.
Sourcepub fn with_formulas(self, formulas: Vec<FormulaResult>) -> StructureResult
pub fn with_formulas(self, formulas: Vec<FormulaResult>) -> StructureResult
Adds formulas to the result.
Sourcepub fn with_text_regions(self, regions: Vec<TextRegion>) -> StructureResult
pub fn with_text_regions(self, regions: Vec<TextRegion>) -> StructureResult
Adds OCR text regions to the result.
Sourcepub fn with_region_blocks(self, blocks: Vec<RegionBlock>) -> StructureResult
pub fn with_region_blocks(self, blocks: Vec<RegionBlock>) -> StructureResult
Adds region blocks to the result (PP-DocBlockLayout).
Region blocks represent hierarchical groupings of layout elements. When set, layout_elements should already be sorted by region hierarchy.
Sourcepub fn with_page_continuation_flags(
self,
flags: PageContinuationFlags,
) -> StructureResult
pub fn with_page_continuation_flags( self, flags: PageContinuationFlags, ) -> StructureResult
Sets page continuation flags for multi-page document processing.
Sourcepub fn to_markdown(&self) -> String
pub fn to_markdown(&self) -> String
Converts the result to a Markdown string.
Follows PP-StructureV3’s formatting rules:
- DocTitle:
# title - ParagraphTitle: Auto-detect numbering (1.2.3 -> ###)
- Formula:
$$latex$$ - Table: HTML with border
- Images:

Note: Low-confidence text elements that overlap with table regions are filtered out to avoid duplicate content from table OCR.
Sourcepub fn calculate_continuation_flags(&self) -> PageContinuationFlags
pub fn calculate_continuation_flags(&self) -> PageContinuationFlags
Calculates the page continuation flags for this result.
This follows PaddleX’s get_seg_flag logic to determine whether
the page starts/ends in the middle of a semantic paragraph.
Returns (paragraph_start, paragraph_end) where:
paragraph_start: false means page continues from previousparagraph_end: false means content continues to next page
Sourcepub fn to_html(&self) -> String
pub fn to_html(&self) -> String
Converts the result to an HTML string.
Follows PP-StructureV3’s formatting rules with semantic HTML tags.
Sourcepub fn to_json_value(&self) -> Result<Value, Error>
pub fn to_json_value(&self) -> Result<Value, Error>
Converts the result to a JSON Value.
Sourcepub fn save_results(
&self,
output_dir: impl AsRef<Path>,
to_json: bool,
to_html: bool,
) -> Result<(), Error>
pub fn save_results( &self, output_dir: impl AsRef<Path>, to_json: bool, to_html: bool, ) -> Result<(), Error>
Saves the analysis results to the specified directory.
This generates:
*_res.json: The full structured result*_res.html: An HTML representation
Note: Markdown export with image extraction should use the example utilities
(examples/utils/markdown.rs) instead, as that requires I/O operations
that belong in the application layer. Use StructureResult::to_markdown()
for pure markdown generation without side effects.
§Arguments
output_dir- Directory to save the output filesto_json- If true, save a JSON representationto_html- If true, save an HTML representation
Trait Implementations§
Source§impl Clone for StructureResult
impl Clone for StructureResult
Source§fn clone(&self) -> StructureResult
fn clone(&self) -> StructureResult
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StructureResult
impl Debug for StructureResult
Source§impl<'de> Deserialize<'de> for StructureResult
impl<'de> Deserialize<'de> for StructureResult
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<StructureResult, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<StructureResult, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for StructureResult
impl Serialize for StructureResult
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Source§impl StructureResultExt for StructureResult
impl StructureResultExt for StructureResult
Source§fn to_concatenated_markdown(results: &[StructureResult]) -> String
fn to_concatenated_markdown(results: &[StructureResult]) -> String
Source§fn save_multi_page_results(
results: &[StructureResult],
output_dir: impl AsRef<Path>,
base_name: &str,
to_json: bool,
to_markdown: bool,
to_html: bool,
) -> Result<(), Error>where
StructureResult: Sized,
fn save_multi_page_results(
results: &[StructureResult],
output_dir: impl AsRef<Path>,
base_name: &str,
to_json: bool,
to_markdown: bool,
to_html: bool,
) -> Result<(), Error>where
StructureResult: Sized,
Auto Trait Implementations§
impl Freeze for StructureResult
impl RefUnwindSafe for StructureResult
impl Send for StructureResult
impl Sync for StructureResult
impl Unpin for StructureResult
impl UnwindSafe for StructureResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.