1
0
Fork 0
forked from josch/img2pdf

test.sh: use pikepdf instead of grep to check PDF

- no requirement on layout chosen by PDF engine anymore, thus we can
   test any pdf writer with this
 - check value at full path instead of anywhere in the document, thus no
   possible false positives if expected value was present in a different
   object
 - allows adding additional checks where we couldn't use grep before
   (multipage pdf created by pdfseparate)
This commit is contained in:
Johannes 'josch' Schauer 2020-05-28 06:32:29 +02:00
parent 17dd59e722
commit c808061b4b
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

466
test.sh
View file

@ -79,6 +79,11 @@ compare_pdfimages()
rm "$tempdir/images-000.png" rm "$tempdir/images-000.png"
} }
checkpdf()
{
python3 -c 'import pikepdf,sys; p=pikepdf.open(sys.argv[1]);exit(sum([not eval("p.pages[0]."+l) for l in sys.stdin]))' "$1"
}
error() error()
{ {
echo test $j failed echo test $j failed
@ -160,12 +165,14 @@ pdfimages -j "$tempdir/out.pdf" "$tempdir/images"
cmp "$tempdir/normal.jpg" "$tempdir/images-000.jpg" cmp "$tempdir/normal.jpg" "$tempdir/images-000.jpg"
rm "$tempdir/images-000.jpg" rm "$tempdir/images-000.jpg"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceRGB$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 8
grep --quiet '^ /Filter /DCTDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceRGB"
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/DCTDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/normal.jpg" "$tempdir/normal.pnm" "$tempdir/out.pdf" rm "$tempdir/normal.jpg" "$tempdir/normal.pnm" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -210,13 +217,15 @@ pdfimages -j "$tempdir/out.pdf" "$tempdir/images"
cmp "$tempdir/normal.jpg" "$tempdir/images-000.jpg" cmp "$tempdir/normal.jpg" "$tempdir/images-000.jpg"
rm "$tempdir/images-000.jpg" rm "$tempdir/images-000.jpg"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceRGB$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 8
grep --quiet '^ /Filter /DCTDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceRGB"
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/DCTDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
grep --quiet '^ /Rotate 90$' "$tempdir/out.pdf" Resources.XObject.Im0.Width == 60
Rotate == 90
END
rm "$tempdir/normal.jpg" "$tempdir/normal.pnm" "$tempdir/out.pdf" "$tempdir/normal_rotated.png" rm "$tempdir/normal.jpg" "$tempdir/normal.pnm" "$tempdir/out.pdf" "$tempdir/normal_rotated.png"
j=$((j+1)) j=$((j+1))
@ -251,13 +260,15 @@ pdfimages -j "$tempdir/out.pdf" "$tempdir/images"
cmp "$tempdir/normal.jpg" "$tempdir/images-000.jpg" cmp "$tempdir/normal.jpg" "$tempdir/images-000.jpg"
rm "$tempdir/images-000.jpg" rm "$tempdir/images-000.jpg"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceCMYK$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 8
grep --quiet '^ /Decode \[ 1 0 1 0 1 0 1 0 \]$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceCMYK"
grep --quiet '^ /Filter /DCTDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.Decode == pikepdf.Array([ 1, 0, 1, 0, 1, 0, 1, 0 ])
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/DCTDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/normal.jpg" "$tempdir/out.pdf" rm "$tempdir/normal.jpg" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -284,12 +295,14 @@ pdfimages -jp2 "$tempdir/out.pdf" "$tempdir/images"
cmp "$tempdir/normal.jp2" "$tempdir/images-000.jp2" cmp "$tempdir/normal.jp2" "$tempdir/images-000.jp2"
rm "$tempdir/images-000.jp2" rm "$tempdir/images-000.jp2"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceRGB$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 8
grep --quiet '^ /Filter /JPXDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceRGB"
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/JPXDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/normal.jp2" "$tempdir/out.pdf" rm "$tempdir/normal.jp2" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -322,15 +335,17 @@ compare_rendered "$tempdir/out.pdf" "$tempdir/normal.png"
compare_pdfimages "$tempdir/out.pdf" "$tempdir/normal.png" compare_pdfimages "$tempdir/out.pdf" "$tempdir/normal.png"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceRGB$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 8
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceRGB"
grep --quiet '^ /Colors 3$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.BitsPerComponent == 8
grep --quiet '^ /Predictor 15$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Colors == 3
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Predictor == 15
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf" rm "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -363,15 +378,17 @@ rm "$tempdir/poppler-1.png"
# pdfimages is unable to write 16 bit output # pdfimages is unable to write 16 bit output
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 16$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceRGB$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 16
grep --quiet '^ /BitsPerComponent 16$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceRGB"
grep --quiet '^ /Colors 3$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.BitsPerComponent == 16
grep --quiet '^ /Predictor 15$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Colors == 3
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Predictor == 15
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf" rm "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -510,15 +527,17 @@ compare_rendered "$tempdir/out.pdf" "$tempdir/normal.png"
compare_pdfimages "$tempdir/out.pdf" "$tempdir/normal.png" compare_pdfimages "$tempdir/out.pdf" "$tempdir/normal.png"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceRGB$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 8
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceRGB"
grep --quiet '^ /Colors 3$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.BitsPerComponent == 8
grep --quiet '^ /Predictor 15$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Colors == 3
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Predictor == 15
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/interlace.png" "$tempdir/out.pdf" rm "$tempdir/interlace.png" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -556,14 +575,17 @@ for i in 1 2 4 8; do
compare_pdfimages "$tempdir/out.pdf" "$tempdir/gray$i.png" compare_pdfimages "$tempdir/out.pdf" "$tempdir/gray$i.png"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent '"$i"'$' "$tempdir/out.pdf" cat << END | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /ColorSpace /DeviceGray$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /BitsPerComponent '"$i"'$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == $i
grep --quiet '^ /Colors 1$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceGray"
grep --quiet '^ /Predictor 15$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.BitsPerComponent == $i
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Colors == 1
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Predictor == 15
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf" rm "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -603,15 +625,17 @@ pdfimages -png "$tempdir/out.pdf" "$tempdir/images"
similar "$tempdir/gray16.png" "$tempdir/images-000.png" similar "$tempdir/gray16.png" "$tempdir/images-000.png"
rm "$tempdir/images-000.png" rm "$tempdir/images-000.png"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 16$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceGray$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 16
grep --quiet '^ /BitsPerComponent 16$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceGray"
grep --quiet '^ /Colors 1$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.BitsPerComponent == 16
grep --quiet '^ /Predictor 15$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Colors == 1
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Predictor == 15
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf" rm "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -640,15 +664,18 @@ for i in 1 2 4 8; do
# pdfimages cannot export palette based images # pdfimages cannot export palette based images
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << END | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent '"$i"'$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace \[ /Indexed /DeviceRGB ' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == $i
grep --quiet '^ /BitsPerComponent '"$i"'$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace[0] == "/Indexed"
grep --quiet '^ /Colors 1$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace[1] == "/DeviceRGB"
grep --quiet '^ /Predictor 15$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.BitsPerComponent == $i
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Colors == 1
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Predictor == 15
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf" rm "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -705,15 +732,18 @@ for i in 1 2 4 8; do
# pdfimages cannot export palette based images # pdfimages cannot export palette based images
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << END | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent '"$i"'$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace \[ /Indexed /DeviceRGB ' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == $i
grep --quiet '^ /BitsPerComponent '"$i"'$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace[0] == "/Indexed"
grep --quiet '^ /Colors 1$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace[1] == "/DeviceRGB"
grep --quiet '^ /Predictor 15$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.BitsPerComponent == $i
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Colors == 1
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Predictor == 15
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf" "$tempdir/palette$i.gif" rm "$tempdir/out.pdf" "$tempdir/palette$i.gif"
j=$((j+1)) j=$((j+1))
@ -760,10 +790,18 @@ for page in 1 2; do
# pdfimages cannot export palette based images # pdfimages cannot export palette based images
# We cannot grep the PDF metadata here, because the page was cat << END | checkpdf "$tempdir/page-$page.pdf"
# rewritten into a non-greppable format by pdfseparate. but that's Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
# okay, because we already grepped single pages before and multipage Resources.XObject.Im0.BitsPerComponent == 8
# PDF should not be different. Resources.XObject.Im0.ColorSpace[0] == "/Indexed"
Resources.XObject.Im0.ColorSpace[1] == "/DeviceRGB"
Resources.XObject.Im0.DecodeParms.BitsPerComponent == 8
Resources.XObject.Im0.DecodeParms.Colors == 1
Resources.XObject.Im0.DecodeParms.Predictor == 15
Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/page-$page.pdf" rm "$tempdir/page-$page.pdf"
done done
@ -831,12 +869,14 @@ pdfimages -tiff "$tempdir/out.pdf" "$tempdir/images"
compare -metric AE "$tempdir/cmyk8.tiff" "$tempdir/images-000.tif" null: 2>/dev/null compare -metric AE "$tempdir/cmyk8.tiff" "$tempdir/images-000.tif" null: 2>/dev/null
rm "$tempdir/images-000.tif" rm "$tempdir/images-000.tif"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceCMYK$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 8
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceCMYK"
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/cmyk8.tiff" "$tempdir/out.pdf" rm "$tempdir/cmyk8.tiff" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -893,15 +933,17 @@ compare_rendered "$tempdir/out.pdf" "$tempdir/normal.tiff" tiff24nc
compare_pdfimages "$tempdir/out.pdf" "$tempdir/normal.tiff" compare_pdfimages "$tempdir/out.pdf" "$tempdir/normal.tiff"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceRGB$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 8
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceRGB"
grep --quiet '^ /Colors 3$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.BitsPerComponent == 8
grep --quiet '^ /Predictor 15$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Colors == 3
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Predictor == 15
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/normal.tiff" "$tempdir/out.pdf" rm "$tempdir/normal.tiff" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -984,16 +1026,18 @@ compare_rendered "$tempdir/out.pdf" "$tempdir/gray1.png" pnggray
compare_pdfimages "$tempdir/out.pdf" "$tempdir/gray1.png" compare_pdfimages "$tempdir/out.pdf" "$tempdir/gray1.png"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 1$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceGray$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 1
grep --quiet '^ /BlackIs1 true$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceGray"
grep --quiet '^ /Columns 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].BlackIs1 == True
grep --quiet '^ /K -1$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Columns == 60
grep --quiet '^ /Rows 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].K == -1
grep --quiet '^ /Filter \[ /CCITTFaxDecode \]$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Rows == 60
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/gray1.tiff" "$tempdir/out.pdf" rm "$tempdir/gray1.tiff" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -1024,15 +1068,17 @@ for i in 2 4 8; do
compare_pdfimages "$tempdir/out.pdf" "$tempdir/gray$i.png" compare_pdfimages "$tempdir/out.pdf" "$tempdir/gray$i.png"
# When saving a PNG, PIL will store it as 8-bit data # When saving a PNG, PIL will store it as 8-bit data
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceGray$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 8
grep --quiet '^ /BitsPerComponent 8$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceGray"
grep --quiet '^ /Colors 1$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.BitsPerComponent == 8
grep --quiet '^ /Predictor 15$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Colors == 1
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Predictor == 15
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/gray$i.tiff" "$tempdir/out.pdf" rm "$tempdir/gray$i.tiff" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -1112,10 +1158,17 @@ for page in 1 2; do
compare_pdfimages "$tempdir/page-$page.pdf" "$tempdir/multipage.tiff[$((page-1))]" compare_pdfimages "$tempdir/page-$page.pdf" "$tempdir/multipage.tiff[$((page-1))]"
# We cannot grep the PDF metadata here, because the page was cat << 'END' | checkpdf "$tempdir/page-$page.pdf"
# rewritten into a non-greppable format by pdfseparate. but that's Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
# okay, because we already grepped single pages before and multipage Resources.XObject.Im0.BitsPerComponent == 8
# PDF should not be different. Resources.XObject.Im0.ColorSpace == "/DeviceRGB"
Resources.XObject.Im0.DecodeParms.BitsPerComponent == 8
Resources.XObject.Im0.DecodeParms.Colors == 3
Resources.XObject.Im0.DecodeParms.Predictor == 15
Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/page-$page.pdf" rm "$tempdir/page-$page.pdf"
done done
@ -1158,15 +1211,18 @@ for i in 1 2 4 8; do
# pdfimages cannot export palette based images # pdfimages cannot export palette based images
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << END | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent '"$i"'$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace \[ /Indexed /DeviceRGB ' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == $i
grep --quiet '^ /BitsPerComponent '"$i"'$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace[0] == "/Indexed"
grep --quiet '^ /Colors 1$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace[1] == "/DeviceRGB"
grep --quiet '^ /Predictor 15$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.BitsPerComponent == $i
grep --quiet '^ /Filter /FlateDecode$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Colors == 1
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms.Predictor == 15
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter == "/FlateDecode"
Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/out.pdf" rm "$tempdir/out.pdf"
@ -1230,16 +1286,18 @@ compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff" compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 1$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceGray$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 1
grep --quiet '^ /BlackIs1 false$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceGray"
grep --quiet '^ /Columns 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].BlackIs1 == False
grep --quiet '^ /K -1$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Columns == 60
grep --quiet '^ /Rows 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].K == -1
grep --quiet '^ /Filter \[ /CCITTFaxDecode \]$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Rows == 60
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/group4.tiff" "$tempdir/out.pdf" rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -1267,16 +1325,18 @@ compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff" compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 1$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceGray$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 1
grep --quiet '^ /BlackIs1 false$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceGray"
grep --quiet '^ /Columns 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].BlackIs1 == False
grep --quiet '^ /K -1$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Columns == 60
grep --quiet '^ /Rows 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].K == -1
grep --quiet '^ /Filter \[ /CCITTFaxDecode \]$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Rows == 60
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/group4.tiff" "$tempdir/out.pdf" rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -1304,16 +1364,18 @@ compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff" compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 1$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceGray$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 1
grep --quiet '^ /BlackIs1 false$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceGray"
grep --quiet '^ /Columns 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].BlackIs1 == False
grep --quiet '^ /K -1$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Columns == 60
grep --quiet '^ /Rows 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].K == -1
grep --quiet '^ /Filter \[ /CCITTFaxDecode \]$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Rows == 60
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/group4.tiff" "$tempdir/out.pdf" rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -1346,16 +1408,18 @@ compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff" compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 1$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceGray$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 1
grep --quiet '^ /BlackIs1 true$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceGray"
grep --quiet '^ /Columns 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].BlackIs1 == True
grep --quiet '^ /K -1$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Columns == 60
grep --quiet '^ /Rows 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].K == -1
grep --quiet '^ /Filter \[ /CCITTFaxDecode \]$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Rows == 60
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/group4.tiff" "$tempdir/out.pdf" rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -1389,16 +1453,18 @@ compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff" compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 1$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceGray$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 1
grep --quiet '^ /BlackIs1 false$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceGray"
grep --quiet '^ /Columns 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].BlackIs1 == False
grep --quiet '^ /K -1$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Columns == 60
grep --quiet '^ /Rows 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].K == -1
grep --quiet '^ /Filter \[ /CCITTFaxDecode \]$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Rows == 60
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/group4.tiff" "$tempdir/out.pdf" rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))
@ -1429,16 +1495,18 @@ compare_rendered "$tempdir/out.pdf" "$tempdir/group4.tiff" pnggray
compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff" compare_pdfimages "$tempdir/out.pdf" "$tempdir/group4.tiff"
grep --quiet '^45.0000 0 0 45.0000 0.0000 0.0000 cm$' "$tempdir/out.pdf" cat << 'END' | checkpdf "$tempdir/out.pdf"
grep --quiet '^ /BitsPerComponent 1$' "$tempdir/out.pdf" Contents.read_raw_bytes() == b'q\n45.0000 0 0 45.0000 0.0000 0.0000 cm\n/Im0 Do\nQ'
grep --quiet '^ /ColorSpace /DeviceGray$' "$tempdir/out.pdf" Resources.XObject.Im0.BitsPerComponent == 1
grep --quiet '^ /BlackIs1 false$' "$tempdir/out.pdf" Resources.XObject.Im0.ColorSpace == "/DeviceGray"
grep --quiet '^ /Columns 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].BlackIs1 == False
grep --quiet '^ /K -1$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Columns == 60
grep --quiet '^ /Rows 60$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].K == -1
grep --quiet '^ /Filter \[ /CCITTFaxDecode \]$' "$tempdir/out.pdf" Resources.XObject.Im0.DecodeParms[0].Rows == 60
grep --quiet '^ /Height 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Filter[0] == "/CCITTFaxDecode"
grep --quiet '^ /Width 60$' "$tempdir/out.pdf" Resources.XObject.Im0.Height == 60
Resources.XObject.Im0.Width == 60
END
rm "$tempdir/group4.tiff" "$tempdir/out.pdf" rm "$tempdir/group4.tiff" "$tempdir/out.pdf"
j=$((j+1)) j=$((j+1))