Skip to content

Commit

Permalink
Make images extracted for jbig2enc optimization have unique filenames
Browse files Browse the repository at this point in the history
Fixes #1396
  • Loading branch information
jbarlow83 committed Oct 28, 2024
1 parent ee5acbe commit 6c6cbfd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/ocrmypdf/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ def extract_image_jbig2(
imgname = root / f'{xref:08d}'
with imgname.open('wb') as f:
ext = pim.extract_to(stream=f)
imgname.rename(imgname.with_suffix(ext))
# Rename the file so it has .prejbig2.ext extension
# Making it unique avoids problems with Windows if the
# same image is extracted multiple times
imgname.rename(imgname.with_suffix(".prejbig2" + ext))
except NotImplementedError as e:
if '/Decode' in str(e):
log.debug(
Expand All @@ -175,7 +178,7 @@ def extract_image_jbig2(
pim.obj.ColorSpace = colorspace
else:
del pim.obj.ColorSpace
return XrefExt(xref, ext)
return XrefExt(xref, ".prejbig2" + ext)
return None


Expand Down

0 comments on commit 6c6cbfd

Please sign in to comment.