1
0
Fork 0
forked from josch/img2pdf

replace --without-pdfrw by --engine=internal or --engine=pdfrw

This commit is contained in:
Johannes 'josch' Schauer 2020-05-28 12:46:37 +02:00
parent 997fe8efd8
commit e4dece1c9f
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1
2 changed files with 228 additions and 103 deletions

View file

@ -34,13 +34,11 @@ import logging
import struct
import platform
with_pdfrw = False
have_pdfrw = True
try:
import pdfrw
with_pdfrw = True
except ImportError:
pass
have_pdfrw = False
__version__ = "0.3.6"
default_dpi = 96.0
@ -69,6 +67,7 @@ papernames = {
"tabloid": "Tabloid",
}
Engine = Enum("Engine", "internal pdfrw pikepdf")
FitMode = Enum("FitMode", "into fill exact shrink enlarge")
@ -597,6 +596,7 @@ class MyPdfString:
class pdfdoc(object):
def __init__(
self,
engine=Engine.internal,
version="1.3",
title=None,
author=None,
@ -615,13 +615,21 @@ class pdfdoc(object):
center_window=False,
fullscreen=False,
):
if with_pdfrw:
if engine is None:
if have_pdfrw:
engine = Engine.pdfrw
else:
engine = Engine.internal
if engine == Engine.pdfrw:
from pdfrw import PdfWriter, PdfDict, PdfName, PdfString
else:
elif engine == Engine.internal:
PdfWriter = MyPdfWriter
PdfDict = MyPdfDict
PdfName = MyPdfName
PdfString = MyPdfString
else:
raise ValueError("unknown engine: %s" % engine)
now = datetime.now()
self.info = PdfDict(indirect=True)
@ -662,7 +670,7 @@ class pdfdoc(object):
self.writer.version = version
# this is done because pdfrw adds info, catalog and pages as the first
# three objects in this order
if not with_pdfrw:
if engine == Engine.internal:
self.writer.addobj(self.info)
self.writer.addobj(self.writer.catalog)
self.writer.addobj(self.writer.pages)
@ -674,6 +682,7 @@ class pdfdoc(object):
self.fit_window = fit_window
self.center_window = center_window
self.fullscreen = fullscreen
self.engine = engine
def add_imagepage(
self,
@ -698,15 +707,17 @@ class pdfdoc(object):
trimborder=None,
artborder=None,
):
if with_pdfrw:
if self.engine == Engine.pdfrw:
from pdfrw import PdfDict, PdfName, PdfObject, PdfString
from pdfrw.py23_diffs import convert_load
else:
elif self.engine == Engine.internal:
PdfDict = MyPdfDict
PdfName = MyPdfName
PdfObject = MyPdfObject
PdfString = MyPdfString
convert_load = my_convert_load
else:
raise ValueError("unknown engine: %s" % self.engine)
if color == Colorspace["1"] or color == Colorspace.L:
colorspace = PdfName.DeviceGray
@ -715,11 +726,11 @@ class pdfdoc(object):
elif color == Colorspace.CMYK or color == Colorspace["CMYK;I"]:
colorspace = PdfName.DeviceCMYK
elif color == Colorspace.P:
if with_pdfrw:
if self.engine == Engine.pdfrw:
raise Exception(
"pdfrw does not support hex strings for "
"palette image input, re-run with "
"--without-pdfrw"
"--engine=internal"
)
colorspace = [
PdfName.Indexed,
@ -843,7 +854,7 @@ class pdfdoc(object):
self.writer.addpage(page)
if not with_pdfrw:
if self.engine == Engine.internal:
self.writer.addobj(content)
self.writer.addobj(image)
@ -853,13 +864,15 @@ class pdfdoc(object):
return stream.getvalue()
def tostream(self, outputstream):
if with_pdfrw:
if self.engine == Engine.pdfrw:
from pdfrw import PdfDict, PdfName, PdfArray, PdfObject
else:
elif self.engine == Engine.internal:
PdfDict = MyPdfDict
PdfName = MyPdfName
PdfObject = MyPdfObject
PdfArray = MyPdfArray
else:
raise ValueError("unknown engine: %s" % self.engine)
NullObject = PdfObject("null")
TrueObject = PdfObject("true")
@ -871,10 +884,12 @@ class pdfdoc(object):
# is added, so we can only start using it after all pages have been
# written.
if with_pdfrw:
if self.engine == Engine.pdfrw:
catalog = self.writer.trailer.Root
else:
elif self.engine == Engine.internal:
catalog = self.writer.catalog
else:
raise ValueError("unknown engine: %s" % self.engine)
if (
self.fullscreen
@ -977,11 +992,13 @@ class pdfdoc(object):
raise ValueError("unknown page layout: %s" % self.page_layout)
# now write out the PDF
if with_pdfrw:
if self.engine == Engine.pdfrw:
self.writer.trailer.Info = self.info
self.writer.write(outputstream)
else:
elif self.engine == Engine.internal:
self.writer.tostream(self.info, outputstream)
else:
raise ValueError("unknown engine: %s" % self.engine)
def get_imgmetadata(imgdata, imgformat, default_dpi, colorspace, rawdata=None):
@ -1763,6 +1780,7 @@ def find_scale(pagewidth, pageheight):
def convert(*images, **kwargs):
_default_kwargs = dict(
engine=None,
title=None,
author=None,
creator=None,
@ -1792,11 +1810,9 @@ def convert(*images, **kwargs):
for kwname, default in _default_kwargs.items():
if kwname not in kwargs:
kwargs[kwname] = default
if "with_pdfrw" in kwargs:
global with_pdfrw
with_pdfrw = kwargs["with_pdfrw"]
pdf = pdfdoc(
kwargs["engine"],
"1.3",
kwargs["title"],
kwargs["author"],
@ -2064,6 +2080,16 @@ def parse_colorspacearg(string):
)
def parse_enginearg(string):
for c in Engine:
if c.name == string:
return c
allowed = ", ".join([c.name for c in Engine])
raise argparse.ArgumentTypeError(
"Unsupported engine: %s. Must be one of: %s." % (string, allowed)
)
def parse_borderarg(string):
if ":" in string:
h, v = string.split(":", 1)
@ -2315,7 +2341,7 @@ def gui():
doc = None
args = {
"without_pdfrw": tkinter.BooleanVar(),
"engine": tkinter.StringVar(),
"first_frame_only": tkinter.BooleanVar(),
"auto_orient": tkinter.BooleanVar(),
"fit": tkinter.StringVar(),
@ -2344,6 +2370,7 @@ def gui():
"colorspace": tkinter.StringVar(),
"first_frame_only": tkinter.BooleanVar(),
}
args["engine"].set("auto")
args["title"].set("")
args["auto_orient"].set(False)
args["fit"].set("into")
@ -2448,12 +2475,13 @@ def gui():
colorspacearg = next(
v for v in Colorspace if v.name == args["colorspace"].get()
)
enginearg = None
if args["engine"].get() != "auto":
enginearg = next(v for v in Engine if v.name == args["engine"].get())
global with_pdfrw
if with_pdfrw:
with_pdfrw = not args["without_pdfrw"].get()
convert(
*infiles,
engine=enginearg,
title=args["title"].get() if args["title"].get() else None,
author=args["author"].get() if args["author"].get() else None,
creator=args["creator"].get() if args["creator"].get() else None,
@ -2584,18 +2612,15 @@ def gui():
OptionMenu(output_options, args["colorspace"], "auto", state=tkinter.DISABLED).grid(
row=0, column=1, sticky=tkinter.W
)
tkinter.Label(output_options, text="engine").grid(row=1, column=0, sticky=tkinter.W)
OptionMenu(output_options, args["engine"], "auto", state=tkinter.DISABLED).grid(
row=1, column=1, sticky=tkinter.W
)
tkinter.Checkbutton(
output_options,
text="Suppress timestamp",
variable=args["nodate"],
state=tkinter.DISABLED,
).grid(row=1, column=0, columnspan=2, sticky=tkinter.W)
# TODO: only have this checkbox enabled if pdfrw is installed
tkinter.Checkbutton(
output_options,
text="without pdfrw",
variable=args["without_pdfrw"],
state=tkinter.DISABLED,
).grid(row=2, column=0, columnspan=2, sticky=tkinter.W)
tkinter.Checkbutton(
output_options,
@ -3091,15 +3116,15 @@ RGB.""",
)
outargs.add_argument(
"--without-pdfrw",
action="store_true",
help="By default, img2pdf uses the pdfrw library to create the output "
"PDF if pdfrw is available. If you want to use the internal PDF "
"generator of img2pdf even if pdfrw is present, then pass this "
"option. This can be useful if you want to have unicode metadata "
"values which pdfrw does not yet support (See "
"https://github.com/pmaupin/pdfrw/issues/39) or if you want the "
"PDF code to be more human readable.",
"--engine",
metavar="engine",
type=parse_enginearg,
help="Choose PDF engine. Can be either internal or pdfrw. The "
"internal engine does not have additional requirements and writes out "
"a human readable PDF. The pdfrw engine requires the pdfrw Python "
"module but does not support unicode metadata (See "
"https://github.com/pmaupin/pdfrw/issues/39) or palette data (See "
"https://github.com/pmaupin/pdfrw/issues/128).",
)
outargs.add_argument(
@ -3433,12 +3458,10 @@ and left/right, respectively. It is not possible to specify asymmetric borders.
)
exit(2)
global with_pdfrw
if with_pdfrw:
with_pdfrw = not args.without_pdfrw
try:
convert(
*args.images,
engine=args.engine,
title=args.title,
author=args.author,
creator=args.creator,

220
test.sh
View file

@ -122,11 +122,15 @@ if [ -z ${img2pdfprog+x} ]; then
img2pdfprog=src/img2pdf.py
fi
available_engines="internal"
if python3 -c "import pdfrw" 2>/dev/null; then
available_engines="$available_engines pdfrw"
fi
img2pdf()
{
# we use --without-pdfrw to better "grep" the result and because we
# cannot write palette based images otherwise
$img2pdfprog --without-pdfrw --producer="" --nodate "$1" > "$2" 2>/dev/null
$img2pdfprog --producer="" --nodate --engine="$1" "$2" > "$3" 2>/dev/null
}
tests=51 # number of tests
@ -146,7 +150,8 @@ identify -verbose "$tempdir/normal.jpg" | grep --quiet '^ Depth: 8-bit$'
identify -verbose "$tempdir/normal.jpg" | grep --quiet '^ Page geometry: 60x60+0+0$'
identify -verbose "$tempdir/normal.jpg" | grep --quiet '^ Compression: JPEG$'
img2pdf "$tempdir/normal.jpg" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/normal.jpg" "$tempdir/out.pdf"
# We have to use jpegtopnm with the original JPG before being able to compare
# it with imagemagick because imagemagick will decode the JPG slightly
@ -173,8 +178,10 @@ Resources.XObject.Im0.Filter == "/DCTDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/normal.jpg" "$tempdir/normal.pnm" "$tempdir/out.pdf"
rm "$tempdir/normal.jpg" "$tempdir/normal.pnm"
j=$((j+1))
###############################################################################
@ -196,7 +203,8 @@ identify -verbose "$tempdir/normal.jpg" | grep --quiet '^ Page geometry: 60x60+
identify -verbose "$tempdir/normal.jpg" | grep --quiet '^ Compression: JPEG$'
identify -verbose "$tempdir/normal.jpg" | grep --quiet '^ Orientation: RightTop$'
img2pdf "$tempdir/normal.jpg" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/normal.jpg" "$tempdir/out.pdf"
# We have to use jpegtopnm with the original JPG before being able to compare
# it with imagemagick because imagemagick will decode the JPG slightly
@ -226,8 +234,10 @@ Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
Rotate == 90
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/normal.jpg" "$tempdir/normal.pnm" "$tempdir/out.pdf" "$tempdir/normal_rotated.png"
rm "$tempdir/normal.jpg" "$tempdir/normal.pnm" "$tempdir/normal_rotated.png"
j=$((j+1))
###############################################################################
@ -244,7 +254,8 @@ identify -verbose "$tempdir/normal.jpg" | grep --quiet '^ Depth: 8-bit$'
identify -verbose "$tempdir/normal.jpg" | grep --quiet '^ Page geometry: 60x60+0+0$'
identify -verbose "$tempdir/normal.jpg" | grep --quiet '^ Compression: JPEG$'
img2pdf "$tempdir/normal.jpg" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/normal.jpg" "$tempdir/out.pdf"
gs -dQUIET -dNOPAUSE -dBATCH -sDEVICE=tiff32nc -r96 -sOutputFile="$tempdir/gs-%00d.tiff" "$tempdir/out.pdf"
similar "$tempdir/normal.jpg" "$tempdir/gs-1.tiff"
@ -269,8 +280,10 @@ Resources.XObject.Im0.Filter == "/DCTDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/normal.jpg" "$tempdir/out.pdf"
rm "$tempdir/normal.jpg"
j=$((j+1))
###############################################################################
@ -287,7 +300,8 @@ identify -verbose "$tempdir/normal.jp2" | grep --quiet '^ Depth: 8-bit$'
identify -verbose "$tempdir/normal.jp2" | grep --quiet '^ Page geometry: 60x60+0+0$'
identify -verbose "$tempdir/normal.jp2" | grep --quiet '^ Compression: JPEG2000$'
img2pdf "$tempdir/normal.jp2" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/normal.jp2" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/normal.jp2"
@ -303,8 +317,10 @@ Resources.XObject.Im0.Filter == "/JPXDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/normal.jp2" "$tempdir/out.pdf"
rm "$tempdir/normal.jp2"
j=$((j+1))
###############################################################################
@ -329,7 +345,8 @@ identify -verbose "$tempdir/normal.png" | grep --quiet '^ png:IHDR.color-type
identify -verbose "$tempdir/normal.png" | grep --quiet '^ png:IHDR.color_type: 2 (Truecolor)$'
identify -verbose "$tempdir/normal.png" | grep --quiet '^ png:IHDR.interlace_method: 0 (Not interlaced)$'
img2pdf "$tempdir/normal.png" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/normal.png" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/normal.png"
@ -346,8 +363,9 @@ Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
j=$((j+1))
###############################################################################
@ -367,7 +385,8 @@ identify -verbose "$tempdir/normal16.png" | grep --quiet '^ png:IHDR.color-ty
identify -verbose "$tempdir/normal16.png" | grep --quiet '^ png:IHDR.color_type: 2 (Truecolor)$'
identify -verbose "$tempdir/normal16.png" | grep --quiet '^ png:IHDR.interlace_method: 0 (Not interlaced)$'
img2pdf "$tempdir/normal16.png" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/normal16.png" "$tempdir/out.pdf"
compare_ghostscript "$tempdir/out.pdf" "$tempdir/normal16.png" tiff48nc
@ -389,8 +408,9 @@ Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
j=$((j+1))
###############################################################################
@ -412,11 +432,13 @@ identify -verbose "$tempdir/alpha8.png" | grep --quiet '^ png:IHDR.color-type
identify -verbose "$tempdir/alpha8.png" | grep --quiet '^ png:IHDR.color_type: 6 (RGBA)$'
identify -verbose "$tempdir/alpha8.png" | grep --quiet '^ png:IHDR.interlace_method: 0 (Not interlaced)$'
img2pdf "$tempdir/alpha8.png" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/alpha8.png" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
rm "$tempdir/alpha8.png"
j=$((j+1))
@ -438,11 +460,13 @@ identify -verbose "$tempdir/alpha.png" | grep --quiet '^ png:IHDR.color-type-
identify -verbose "$tempdir/alpha.png" | grep --quiet '^ png:IHDR.color_type: 6 (RGBA)$'
identify -verbose "$tempdir/alpha.png" | grep --quiet '^ png:IHDR.interlace_method: 0 (Not interlaced)$'
img2pdf "$tempdir/alpha.png" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/alpha.png" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
j=$((j+1))
@ -465,11 +489,13 @@ identify -verbose "$tempdir/alpha_gray8.png" | grep --quiet '^ png:IHDR.color
identify -verbose "$tempdir/alpha_gray8.png" | grep --quiet '^ png:IHDR.color_type: 4 (GrayAlpha)$'
identify -verbose "$tempdir/alpha_gray8.png" | grep --quiet '^ png:IHDR.interlace_method: 0 (Not interlaced)$'
img2pdf "$tempdir/alpha_gray8.png" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/alpha_gray8.png" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
rm "$tempdir/alpha_gray8.png"
j=$((j+1))
@ -493,11 +519,13 @@ identify -verbose "$tempdir/alpha_gray16.png" | grep --quiet '^ png:IHDR.colo
identify -verbose "$tempdir/alpha_gray16.png" | grep --quiet '^ png:IHDR.color_type: 4 (GrayAlpha)$'
identify -verbose "$tempdir/alpha_gray16.png" | grep --quiet '^ png:IHDR.interlace_method: 0 (Not interlaced)$'
img2pdf "$tempdir/alpha_gray16.png" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/alpha_gray16.png" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
rm "$tempdir/alpha_gray16.png"
j=$((j+1))
@ -521,7 +549,8 @@ identify -verbose "$tempdir/interlace.png" | grep --quiet '^ png:IHDR.color-t
identify -verbose "$tempdir/interlace.png" | grep --quiet '^ png:IHDR.color_type: 2 (Truecolor)$'
identify -verbose "$tempdir/interlace.png" | grep --quiet '^ png:IHDR.interlace_method: 1 (Adam7 method)$'
img2pdf "$tempdir/interlace.png" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/interlace.png" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/normal.png"
@ -538,8 +567,10 @@ Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/interlace.png" "$tempdir/out.pdf"
rm "$tempdir/interlace.png"
j=$((j+1))
###############################################################################
@ -568,7 +599,8 @@ for i in 1 2 4 8; do
identify -verbose "$tempdir/gray$i.png" | grep --quiet '^ png:IHDR.color_type: 0 (Grayscale)$'
identify -verbose "$tempdir/gray$i.png" | grep --quiet '^ png:IHDR.interlace_method: 0 (Not interlaced)$'
img2pdf "$tempdir/gray$i.png" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/gray$i.png" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/gray$i.png" pnggray
@ -586,8 +618,9 @@ Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
j=$((j+1))
done
@ -608,7 +641,8 @@ identify -verbose "$tempdir/gray16.png" | grep --quiet '^ png:IHDR.color-type
identify -verbose "$tempdir/gray16.png" | grep --quiet '^ png:IHDR.color_type: 0 (Grayscale)$'
identify -verbose "$tempdir/gray16.png" | grep --quiet '^ png:IHDR.interlace_method: 0 (Not interlaced)$'
img2pdf "$tempdir/gray16.png" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/gray16.png" "$tempdir/out.pdf"
# ghostscript outputs 8-bit grayscale, so the comparison will not be exact
gs -dQUIET -dNOPAUSE -dBATCH -sDEVICE=pnggray -r96 -sOutputFile="$tempdir/gs-%00d.png" "$tempdir/out.pdf"
@ -636,8 +670,9 @@ Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
j=$((j+1))
###############################################################################
@ -658,7 +693,11 @@ for i in 1 2 4 8; do
identify -verbose "$tempdir/palette$i.png" | grep --quiet '^ png:IHDR.color_type: 3 (Indexed)$'
identify -verbose "$tempdir/palette$i.png" | grep --quiet '^ png:IHDR.interlace_method: 0 (Not interlaced)$'
img2pdf "$tempdir/palette$i.png" "$tempdir/out.pdf"
for engine in $available_engines; do
if [ $engine = "pdfrw" ]; then
continue
fi
img2pdf $engine "$tempdir/palette$i.png" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/palette$i.png"
@ -676,8 +715,9 @@ Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
j=$((j+1))
done
@ -696,11 +736,13 @@ identify -verbose "$tempdir/alpha.gif" | grep --quiet '^ Colormap entries: 256$
identify -verbose "$tempdir/alpha.gif" | grep --quiet '^ Page geometry: 60x60+0+0$'
identify -verbose "$tempdir/alpha.gif" | grep --quiet '^ Compression: LZW$'
img2pdf "$tempdir/alpha.gif" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/alpha.gif" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
rm "$tempdir/alpha.gif"
j=$((j+1))
@ -726,7 +768,11 @@ for i in 1 2 4 8; do
identify -verbose "$tempdir/palette$i.gif" | grep --quiet '^ Page geometry: 60x60+0+0$'
identify -verbose "$tempdir/palette$i.gif" | grep --quiet '^ Compression: LZW$'
img2pdf "$tempdir/palette$i.gif" "$tempdir/out.pdf"
for engine in $available_engines; do
if [ $engine = "pdfrw" ]; then
continue
fi
img2pdf $engine "$tempdir/palette$i.gif" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/palette$i.png"
@ -744,8 +790,10 @@ Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/out.pdf" "$tempdir/palette$i.gif"
rm "$tempdir/palette$i.gif"
j=$((j+1))
done
@ -775,7 +823,11 @@ identify -verbose "$tempdir/animation.gif[1]" | grep --quiet '^ Page geometry:
identify -verbose "$tempdir/animation.gif[1]" | grep --quiet '^ Compression: LZW$'
identify -verbose "$tempdir/animation.gif[1]" | grep --quiet '^ Scene: 1$'
img2pdf "$tempdir/animation.gif" "$tempdir/out.pdf"
for engine in $available_engines; do
if [ $engine = "pdfrw" ]; then
continue
fi
img2pdf $engine "$tempdir/animation.gif" "$tempdir/out.pdf"
if [ "$(pdfinfo "$tempdir/out.pdf" | awk '/Pages:/ {print $2}')" != 2 ]; then
echo "pdf does not have 2 pages"
@ -805,6 +857,7 @@ END
rm "$tempdir/page-$page.pdf"
done
done
rm "$tempdir/animation.gif"
j=$((j+1))
@ -828,11 +881,13 @@ identify -verbose "$tempdir/float.tiff" | grep --quiet '^ tiff:alpha: unspeci
identify -verbose "$tempdir/float.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/float.tiff" | grep --quiet '^ tiff:photometric: RGB$'
img2pdf "$tempdir/float.tiff" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/float.tiff" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
rm "$tempdir/float.tiff"
j=$((j+1))
@ -855,7 +910,8 @@ identify -verbose "$tempdir/cmyk8.tiff" | grep --quiet '^ tiff:alpha: unspeci
identify -verbose "$tempdir/cmyk8.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/cmyk8.tiff" | grep --quiet '^ tiff:photometric: separated$'
img2pdf "$tempdir/cmyk8.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/cmyk8.tiff" "$tempdir/out.pdf"
compare_ghostscript "$tempdir/out.pdf" "$tempdir/cmyk8.tiff" tiff32nc
@ -877,8 +933,10 @@ Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/cmyk8.tiff" "$tempdir/out.pdf"
rm "$tempdir/cmyk8.tiff"
j=$((j+1))
###############################################################################
@ -900,11 +958,13 @@ identify -verbose "$tempdir/cmyk16.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/cmyk16.tiff" | grep --quiet '^ tiff:photometric: separated$'
# PIL is unable to read 16 bit CMYK images
img2pdf "$tempdir/cmyk16.gif" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/cmyk16.gif" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
rm "$tempdir/cmyk16.tiff"
j=$((j+1))
@ -927,7 +987,8 @@ identify -verbose "$tempdir/normal.tiff" | grep --quiet '^ tiff:alpha: unspec
identify -verbose "$tempdir/normal.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/normal.tiff" | grep --quiet '^ tiff:photometric: RGB$'
img2pdf "$tempdir/normal.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/normal.tiff" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/normal.tiff" tiff24nc
@ -944,8 +1005,10 @@ Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/normal.tiff" "$tempdir/out.pdf"
rm "$tempdir/normal.tiff"
j=$((j+1))
###############################################################################
@ -966,11 +1029,13 @@ identify -verbose "$tempdir/alpha8.tiff" | grep --quiet '^ tiff:alpha: unasso
identify -verbose "$tempdir/alpha8.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/alpha8.tiff" | grep --quiet '^ tiff:photometric: RGB$'
img2pdf "$tempdir/alpha8.tiff" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/alpha8.tiff" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
rm "$tempdir/alpha8.tiff"
j=$((j+1))
@ -993,11 +1058,13 @@ identify -verbose "$tempdir/alpha16.tiff" | grep --quiet '^ tiff:alpha: unass
identify -verbose "$tempdir/alpha16.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/alpha16.tiff" | grep --quiet '^ tiff:photometric: RGB$'
img2pdf "$tempdir/alpha16.tiff" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/alpha16.tiff" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
rm "$tempdir/alpha16.tiff"
j=$((j+1))
@ -1020,7 +1087,8 @@ identify -verbose "$tempdir/gray1.tiff" | grep --quiet '^ tiff:alpha: unspeci
identify -verbose "$tempdir/gray1.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/gray1.tiff" | grep --quiet '^ tiff:photometric: min-is-black$'
img2pdf "$tempdir/gray1.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/gray1.tiff" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/gray1.png" pnggray
@ -1038,8 +1106,10 @@ Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/gray1.tiff" "$tempdir/out.pdf"
rm "$tempdir/gray1.tiff"
j=$((j+1))
###############################################################################
@ -1061,7 +1131,8 @@ for i in 2 4 8; do
identify -verbose "$tempdir/gray$i.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/gray$i.tiff" | grep --quiet '^ tiff:photometric: min-is-black$'
img2pdf "$tempdir/gray$i.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/gray$i.tiff" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/gray$i.png" pnggray
@ -1079,8 +1150,10 @@ Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/gray$i.tiff" "$tempdir/out.pdf"
rm "$tempdir/gray$i.tiff"
j=$((j+1))
done
@ -1102,11 +1175,13 @@ identify -verbose "$tempdir/gray16.tiff" | grep --quiet '^ tiff:alpha: unspec
identify -verbose "$tempdir/gray16.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/gray16.tiff" | grep --quiet '^ tiff:photometric: min-is-black$'
img2pdf "$tempdir/gray16.tiff" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/gray16.tiff" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
rm "$tempdir/gray16.tiff"
j=$((j+1))
@ -1143,7 +1218,8 @@ identify -verbose "$tempdir/multipage.tiff[1]" | grep --quiet '^ tiff:endian:
identify -verbose "$tempdir/multipage.tiff[1]" | grep --quiet '^ tiff:photometric: RGB$'
identify -verbose "$tempdir/multipage.tiff[1]" | grep --quiet '^ Scene: 1$'
img2pdf "$tempdir/multipage.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/multipage.tiff" "$tempdir/out.pdf"
if [ "$(pdfinfo "$tempdir/out.pdf" | awk '/Pages:/ {print $2}')" != 2 ]; then
echo "pdf does not have 2 pages"
@ -1172,6 +1248,7 @@ END
rm "$tempdir/page-$page.pdf"
done
done
rm "$tempdir/multipage.tiff"
j=$((j+1))
@ -1205,7 +1282,11 @@ for i in 1 2 4 8; do
identify -verbose "$tempdir/palette$i.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/palette$i.tiff" | grep --quiet '^ tiff:photometric: palette$'
img2pdf "$tempdir/palette$i.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
if [ $engine = "pdfrw" ]; then
continue
fi
img2pdf $engine "$tempdir/palette$i.tiff" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/palette$i.png"
@ -1225,6 +1306,7 @@ Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/palette$i.tiff"
j=$((j+1))
@ -1253,11 +1335,13 @@ for i in 12 14 16; do
identify -verbose "$tempdir/normal$i.tiff" | grep --quiet '^ tiff:endian: lsb$'
identify -verbose "$tempdir/normal$i.tiff" | grep --quiet '^ tiff:photometric: RGB$'
img2pdf "$tempdir/normal$i.tiff" /dev/null && rc=$? || rc=$?
for engine in $available_engines; do
img2pdf $engine "$tempdir/normal$i.tiff" /dev/null && rc=$? || rc=$?
if [ "$rc" -eq 0 ]; then
echo needs to fail here
exit 1
fi
done
rm "$tempdir/normal$i.tiff"
j=$((j+1))
@ -1280,7 +1364,8 @@ identify -verbose "$tempdir/group4.tiff" | grep --quiet 'Compression: Group4'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:endian: lsb'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:photometric: min-is-white'
img2pdf "$tempdir/group4.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/group4.tiff" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
@ -1298,8 +1383,10 @@ Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
rm "$tempdir/group4.tiff"
j=$((j+1))
###############################################################################
@ -1319,7 +1406,8 @@ identify -verbose "$tempdir/group4.tiff" | grep --quiet 'Compression: Group4'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:endian: msb'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:photometric: min-is-white'
img2pdf "$tempdir/group4.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/group4.tiff" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
@ -1337,8 +1425,10 @@ Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
rm "$tempdir/group4.tiff"
j=$((j+1))
###############################################################################
@ -1358,7 +1448,8 @@ identify -verbose "$tempdir/group4.tiff" | grep --quiet 'Compression: Group4'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:endian: msb'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:photometric: min-is-white'
img2pdf "$tempdir/group4.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/group4.tiff" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
@ -1376,8 +1467,10 @@ Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
rm "$tempdir/group4.tiff"
j=$((j+1))
###############################################################################
@ -1402,7 +1495,8 @@ identify -verbose "$tempdir/group4.tiff" | grep --quiet 'Compression: Group4'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:endian: lsb'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:photometric: min-is-black'
img2pdf "$tempdir/group4.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/group4.tiff" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
@ -1420,8 +1514,10 @@ Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
rm "$tempdir/group4.tiff"
j=$((j+1))
###############################################################################
@ -1447,7 +1543,8 @@ identify -verbose "$tempdir/group4.tiff" | grep --quiet 'Compression: Group4'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:endian: lsb'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:photometric: min-is-white'
img2pdf "$tempdir/group4.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/group4.tiff" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
@ -1465,8 +1562,10 @@ Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
rm "$tempdir/group4.tiff"
j=$((j+1))
###############################################################################
@ -1489,7 +1588,8 @@ identify -verbose "$tempdir/group4.tiff" | grep --quiet 'Compression: Group4'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:endian: lsb'
identify -verbose "$tempdir/group4.tiff" | grep --quiet 'tiff:photometric: min-is-white'
img2pdf "$tempdir/group4.tiff" "$tempdir/out.pdf"
for engine in $available_engines; do
img2pdf $engine "$tempdir/group4.tiff" "$tempdir/out.pdf"
compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
@ -1507,8 +1607,10 @@ Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf"
done
rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
rm "$tempdir/group4.tiff"
j=$((j+1))
rm "$tempdir/alpha.png" "$tempdir/normal.png" "$tempdir/inverse.png" "$tempdir/palette1.png" "$tempdir/palette2.png" "$tempdir/palette4.png" "$tempdir/palette8.png" "$tempdir/gray8.png" "$tempdir/normal16.png" "$tempdir/gray16.png" "$tempdir/gray4.png" "$tempdir/gray2.png" "$tempdir/gray1.png"