[reportlab-users] Automatic testing PDF output

Roberto Alsina ralsina at netmanagers.com.ar
Thu May 21 12:26:37 EDT 2009


I now a solution to this problem was posted a few months ago, but I really
can't find it in the archives.

So, I spend a few hours trying to reinvent the wheel, and here it is for
google's sake: compare PDF testing tests reportlab automatically.

It will check the metadata using pdfinfo (from poppler), and then visually
page by page using imagemagick. If there are differences, you will have a
diffpage-n.png where the differences are visible in red.

If you want to compare two PDF files ($bn.pdf and correct/$bn.pdf), and have
imagemagick and poppler installed and a bourne style shell:

compare_pdfinfo() {
# Given two PDF files $1 and $2, compare the output of pdfinfo except for
# creation date.
pdfinfo "$1" | grep -v CreationDate | grep -v "File size"> "$1.info"
pdfinfo "$2" | grep -v CreationDate | grep -v "File size"> "$2.info"
if cmp -s "$1.info" "$2.info"
then
true
#echo "PDF metadata is correct"
else
echo "PDF metadata for $1 is wrong"
fi
rm "$1.info" "$2.info"
}

compare_pdfinfo $bn.pdf correct/$bn.pdf
if [ ! -d temp-$bn ]
then
mkdir temp-$bn
fi
rm -f temp-$bn/*
convert $bn.pdf temp-$bn/page.png
convert correct/$bn.pdf temp-$bn/correctpage.png
cd temp-$bn
for page in page*png
do
result=`compare -metric PSNR $page correct$page diff$page 2>&1`
if [ "$result" = "inf" ]
then
#echo "$page is OK"
true
else
echo "$page has ERRORs, see temp-$bn/diff$page"
fi
done
cd ..


The latest version of the script where this fragment comes from will always be
at
http://code.google.com/p/rst2pdf/source/browse/trunk/rst2pdf/tests/input/run_tests.sh

--
("\''/").__..-''"`-. . Roberto Alsina
`9_ 9 ) `-. ( ).`-._.`) KDE Developer (MFCH)
(_Y_.)' ._ ) `._`. " -.-' http://lateral.netmanagers.com.ar
_..`-'_..-_/ /-'_.' The 6,855th most popular site of Slovenia
(l)-'' ((i).' ((!.' according to alexa.com (27/5/2007)
"Our opponent is an alien starship packed with atomic bombs, I said.
We have a protractor. Okay, I’ll go home and see if I can scrounge up a
ruler and a piece of string." — Neal Stephenson


More information about the reportlab-users mailing list