mirror of
https://github.com/DS4SD/docling.git
synced 2025-07-26 12:04:31 +00:00
add RGB conversion
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
This commit is contained in:
parent
6aa85cc933
commit
05f51b30d9
@ -57,28 +57,31 @@ class PdfDocumentBackend(PaginatedDocumentBackend):
|
|||||||
if self.input_format is InputFormat.IMAGE:
|
if self.input_format is InputFormat.IMAGE:
|
||||||
buf = BytesIO()
|
buf = BytesIO()
|
||||||
img = Image.open(self.path_or_stream)
|
img = Image.open(self.path_or_stream)
|
||||||
|
|
||||||
# Handle multi-page TIFF images
|
# Handle multi-page TIFF images
|
||||||
if hasattr(img, 'n_frames') and img.n_frames > 1:
|
if hasattr(img, "n_frames") and img.n_frames > 1:
|
||||||
# Extract all frames from multi-page image
|
# Extract all frames from multi-page image
|
||||||
frames = []
|
frames = []
|
||||||
try:
|
try:
|
||||||
for i in range(img.n_frames):
|
for i in range(img.n_frames):
|
||||||
img.seek(i)
|
img.seek(i)
|
||||||
frames.append(img.copy())
|
frame = img.copy().convert("RGB")
|
||||||
|
frames.append(frame)
|
||||||
except EOFError:
|
except EOFError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Save as multi-page PDF
|
# Save as multi-page PDF
|
||||||
if frames:
|
if frames:
|
||||||
frames[0].save(buf, "PDF", save_all=True, append_images=frames[1:])
|
frames[0].save(
|
||||||
|
buf, "PDF", save_all=True, append_images=frames[1:]
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# Fallback to single page if frame extraction fails
|
# Fallback to single page if frame extraction fails
|
||||||
img.save(buf, "PDF")
|
img.convert("RGB").save(buf, "PDF")
|
||||||
else:
|
else:
|
||||||
# Single page image - use existing behavior
|
# Single page image - convert to RGB and save
|
||||||
img.save(buf, "PDF")
|
img.convert("RGB").save(buf, "PDF")
|
||||||
|
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
self.path_or_stream = buf
|
self.path_or_stream = buf
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user