raygeo.formats.pdf.writer
Writing single-image PDF pages.
Writes a one-page PDF that fills the page with an 8-bit grayscale or RGB image, so an application can produce printable documents without a PDF library.
Functions
write_image_page()
write_image_page(
pixels: bytes,
width: int,
height: int,
page_width_pt: float,
page_height_pt: float,
channels: int = 3,
) -> bytes
Write a one-page PDF that fills the page with an image.
pixels is raw 8-bit data, one byte per pixel for grayscale or three for RGB, row-major from the
top-left. The page is written at the given point size and the image is stretched to fill it.
Raises: ValueError — When the channel count or buffer size does
not match the dimensions.
| Parameter | Type | Description |
|---|---|---|
pixels | bytes | Raw pixel data. |
width | int | Image width in pixels. |
height | int | Image height in pixels. |
page_width_pt | float | Page width in PDF points. |
page_height_pt | float | Page height in PDF points. |
channels | int = 3 | Bytes per pixel: 1 for grayscale, 3 for RGB. |
| Returns | bytes | The PDF document's bytes. |
| Complexity | O(n) where n = size of the pixel data |