raygeo.formats.pdf.content
Extracting the painted geometry of a PDF page.
The page content stream is interpreted directly: paths, dash patterns, form XObjects and optional-content groups are extracted, and text is converted to glyph outlines. Images, fills and stroke widths are ignored. Coordinates are in PDF points, Y-up, in the frame of the page as it is displayed: its crop box and rotation are applied, and content outside the page is not returned.
PageRead
A page read that keeps the placement of its forms.
forms
forms: list[PdfFormNode]
One entry per form XObject the page paints, in painting order, nested as in the content streams.
output
output: PdfPage
The same result read_page_geometry() returns, with every form merged into the layers.
own_layers
own_layers: list[tuple[Optional[str], geo.Geometry]]
The geometry the page draws outside every form, as (layer_name, geometry) pairs in painting order.
PdfFormNode
One form XObject a page paints, with the structure it contains.
children
children: list[PdfFormNode]
The forms the form paints, in painting order.
layers
layers: list[tuple[Optional[str], geo.Geometry]]
The geometry the form draws itself, as (layer_name, geometry) pairs in painting order. What the
forms it paints draw is reported in children instead.
name
name: str
The name the form is known by in its resource dictionary.
transform
transform: geo.Matrix
The transform placing the form in page coordinates, composed with the forms that paint it.
PdfIssue
Content the reader skipped or approximated.
code
code: str
Lower-case identifier of the issue, such as "dotted_lines", for applications that translate it
themselves.
detail
detail: Optional[str]
What the issue refers to, such as a font name.
message
message: str
The issue as an English sentence.
PdfPage
The geometry one PDF page paints.
height_pt
height_pt: float
Page height in PDF points, as displayed.
issues
issues: list[PdfIssue]
Content the reader skipped or approximated.
layers
layers: list[tuple[Optional[str], geo.Geometry]]
One geometry per optional-content layer, in painting order, as (layer_name, geometry) pairs.
layer_name is None for content outside any optional-content group.
width_pt
width_pt: float
Page width in PDF points, as displayed.
Functions
read_page_geometry()
read_page_geometry(
data: bytes,
page_index: int = 0,
) -> formats.pdf.content.PdfPage
Extract the painted path geometry of one PDF page.
Coordinates are in PDF points, Y-up, in the frame of the page as it is displayed: its crop box and rotation are applied, and content outside the page is not returned. Text is converted to glyph outlines; images, fills and stroke widths are ignored.
Raises: ValueError — When the document needs a password, is damaged,
or the page does not exist.
| Parameter | Type | Description |
|---|---|---|
data | bytes | The PDF file's bytes. |
page_index | int = 0 | Zero-based page index. Defaults to the first page. |
| Returns | formats.pdf.content.PdfPage | Page size, one geometry per optional-content layer, and notes about skipped or incomplete content. |
| Complexity | O(n) where n = size of the page's content streams |
read_page_geometry_with_forms()
read_page_geometry_with_forms(
data: bytes,
page_index: int = 0,
) -> formats.pdf.content.PageRead
Extract a PDF page's geometry, keeping the placement of its forms.
The returned output is the same result read_page_geometry() returns, with every form XObject
merged into the layers. forms holds one entry per form the page paints, nested as in the content
streams, each with the geometry the form draws itself and the forms it paints. own_layers holds
the geometry the page draws outside every form, so the two together cover the page without overlap.
A form that is painted recursively or nested too deeply yields an entry without layers and children;
the reason is in the page's issues.
Raises: ValueError — When the document needs a password, is damaged,
or the page does not exist.
| Parameter | Type | Description |
|---|---|---|
data | bytes | The PDF file's bytes. |
page_index | int = 0 | Zero-based page index. Defaults to the first page. |
| Returns | formats.pdf.content.PageRead | The flattened page, the nested forms and the content outside the forms. |
| Complexity | O(n) where n = size of the page's content streams |

A form that draws a frame and places two drawn forms