raygeo.importing
Format-independent import pipeline.
The format readers answer what a file draws. This module turns that answer into the facts an application needs to place the content in a document: the source page size and coordinate system, the layers, and one layout item per resulting workpiece. The result contains plain geometry, rectangles and affine matrices; the embedding application creates its own document objects from them.
Warnings and errors are notices with a stable code, so the embedding application can translate them.
ImportManifest
The result of the scan phase.
errors
errors: list[ImportNotice]
Problems that may prevent a complete import.
has_z_variation
has_z_variation: bool
Whether the file's geometry spans several Z levels.
is_unitless
is_unitless: bool
Whether the file does not state a unit.
layers
layers: list[LayerInfo]
Layers the file contains.
natural_size_mm
natural_size_mm: Optional[tuple[float, float]]
Document size in millimetres, if the format defines one.
title
title: Optional[str]
Document title.
warnings
warnings: list[ImportNotice]
Non-critical issues found while scanning.
ImportMode
How a source is turned into vectors.
Values:
PASSTHROUGH— Use the geometry stored in the file.TRACE— Trace a raster representation of the file.
ImportNotice
A warning or error raised while importing.
code
code: str
Lower-case identifier of the notice, such as "no_pages", for applications that translate it
themselves.
detail
detail: Optional[str]
What the notice refers to, if anything.
message
message: str
The notice as an English sentence.
ImportResult
The complete result of an import.
errors
errors: list[ImportNotice]
Problems that prevented a complete import.
layout
layout: list[LayoutItem]
One entry per workpiece to create.
manifest
manifest: ImportManifest
File metadata and layer discovery.
parsed
parsed: Optional[ParsedDocument]
Geometric facts, or None when parsing failed.
vectorized
vectorized: Optional[VectorizedDocument]
Vectorized geometry, or None when vectorization failed.
warnings
warnings: list[ImportNotice]
Non-critical issues.
ImportSpec
Options controlling how a file is imported.
active_layer_ids
active_layer_ids: Optional[list[str]]
Restrict the import to these source layer ids.
group_imported_layers
group_imported_layers: bool
Wrap the imported items in one group.
layer_import_mode
layer_import_mode: LayerImportMode
How source layers are mapped into the document.
mode
mode: ImportMode
Whether to use stored vectors or trace a raster.
ppi
ppi: float
Pixels per inch used for raster-derived sources.
trace_auto_threshold
trace_auto_threshold: bool
Derive the trace threshold from the image's histogram.
trace_invert
trace_invert: bool
Trace light content instead of dark content.
trace_threshold
trace_threshold: float
Trace threshold in the 0..1 range.
LayerGeometry
The geometry of one layer, in native coordinates.
color
color: Optional[str]
Display colour as a hex string, if known.
content_bounds
content_bounds: tuple[float, float, float, float]
Bounding rectangle as (x, y, width, height).
layer_id
layer_id: str
The layer's identifier.
name
name: str
The layer's display name.
LayerImportMode
How source layers map to the embedding application's documents.
Values:
FLATTEN— Merge everything into one item.MAP_TO_EXISTING— Merge source layers into the existing content.NEW_WORKFLOWS— Give each source layer its own document layer.
LayerInfo
A layer discovered during the scan phase.
color
color: Optional[tuple[float, float, float]]
Display colour in the 0..1 range, if the file states one.
default_active
default_active: bool
Whether the layer is visible by default.
feature_count
feature_count: Optional[int]
Number of geometric features on the layer, if known.
id
id: str
The layer's identifier within the file.
name
name: str
The layer's display name.
LayoutItem
One item to turn into a workpiece.
color
color: Optional[str]
Display colour as a hex string, if known.
crop_window
crop_window: tuple[float, float, float, float]
The part of the source the item uses, in native coordinates.
geometry
geometry: Optional[geo.Geometry]
Explicit geometry for the item, or None to use the layer's.
group_id
group_id: Optional[str]
Group identifier, if the item is part of a group.
group_name
group_name: Optional[str]
Group display name.
layer_id
layer_id: Optional[str]
The layer the item belongs to, if any.
layer_name
layer_name: Optional[str]
The layer's display name.
normalization_matrix
normalization_matrix: geo.Matrix
Transform from native coordinates to normalized (0..1, Y-up).
world_matrix
world_matrix: geo.Matrix
Transform from normalized (0..1, Y-up) to world millimetres.
ParsedDocument
The result of the parse phase.
background_world_transform
background_world_transform: geo.Matrix
Transform placing a background image in the world frame.
document_bounds
document_bounds: tuple[float, float, float, float]
The document's bounds as (x, y, width, height).
geometry_is_relative_to_bounds
geometry_is_relative_to_bounds: bool
Whether geometry is relative to its content bounds.
is_cropped_to_content
is_cropped_to_content: bool
Whether the bounds are already cropped to the content.
is_y_down
is_y_down: bool
Whether the native Y axis points down.
layers
layers: list[LayerGeometry]
One entry per layer.
native_unit_to_mm
native_unit_to_mm: float
Multiplier converting native units to millimetres.
untrimmed_document_bounds
untrimmed_document_bounds: Optional[tuple[float, float, float, float]]
Bounds of the original page before trimming, if any.
world_frame_of_reference
world_frame_of_reference: tuple[float, float, float, float]
The document's frame in world coordinates.
VectorizedDocument
The result of the vectorize phase.
geometries_by_layer
geometries_by_layer: list[tuple[str, geo.Geometry]]
One geometry per layer, keyed by layer id.
Functions
import_pdf()
import_pdf(
data: bytes,
spec: importing.ImportSpec | None = None,
) -> importing.ImportResult
Import a PDF through the generic pipeline.
Only the passthrough mode is implemented. The result always carries the scan manifest, even when parsing fails. PDF trace vectorization belongs to the raster pipeline and is not part of the format reader.
| Parameter | Type | Description |
|---|---|---|
data | bytes | The PDF file's bytes. |
spec | importing.ImportSpec | None = None | Import options. Defaults to passthrough with no layer filter. |
| Returns | importing.ImportResult | Manifest, parsed facts, vectorized geometry and layout items. |
| Complexity | O(n) where n = size of the page's content streams |