xpark.dataset.ImageToPdf#

class xpark.dataset.ImageToPdf(*, output_dir: str, tmp_dir: str | None = None, source_mode: str | None = None)#

Compose a list of images into a multi-page PDF and persist to disk.

Writes one PDF per input row under output_dir. output_dir may be a local directory or a remote URI supported by fsspec (e.g. cos://bucket/prefix).

Each row’s images may be encoded binaries, local/remote paths, or tensors — whatever read_image accepts. Rows whose image list is null or empty produce a null output (no PDF is written for them).

Parameters:
  • output_dir – The directory (or URI prefix) where PDFs are written.

  • tmp_dir – Temporary directory for remote outputs. Defaults to the system temp directory (tempfile.gettempdir()) when None. In Ray worker sandboxes where /tmp may not be writable, pass an explicit writable directory instead.

  • source_mode – The mode of the images. Default is auto detect.

Examples

from xpark.dataset import from_items
from xpark.dataset.expressions import col
from xpark.dataset.processors.image_to_pdf import ImageToPdf

ds = from_items([{"pages": ["cos://bucket/images/p1.jpg", "/data/images/p2.jpg"]}])
ds = ds.with_column(
    "pdf_uri",
    ImageToPdf(output_dir="cos://bucket/pdfs")
    .options(batch_size=4)
    .with_column(col("pages")),
)

Methods

__call__(images[, filenames])

Call self as a function.

options(**kwargs)

with_column(images[, filenames])

__call__(images: pa.ChunkedArray, filenames: pa.ChunkedArray | None = None) → pa.Array#

Call self as a function.

options(**kwargs: Unpack[ExprUDFOptions]) → Self#
with_column(images: pa.ChunkedArray, filenames: pa.ChunkedArray | None = None) → pa.Array#