Zum Hauptinhalt springen

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.
ParameterTypeDescription
pixelsbytesRaw pixel data.
widthintImage width in pixels.
heightintImage height in pixels.
page_width_ptfloatPage width in PDF points.
page_height_ptfloatPage height in PDF points.
channelsint = 3Bytes per pixel: 1 for grayscale, 3 for RGB.
ReturnsbytesThe PDF document's bytes.
ComplexityO(n) where n = size of the pixel data