[reportlab-users] Automatic testing PDF output
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:
# 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"
#echo "PDF metadata is correct"
echo "PDF metadata for $1 is wrong"
rm "$1.info" "$2.info"
compare_pdfinfo $bn.pdf correct/$bn.pdf
if [ ! -d temp-$bn ]
rm -f temp-$bn/*
convert $bn.pdf temp-$bn/page.png
convert correct/$bn.pdf temp-$bn/correctpage.png
for page in page*png
result=`compare -metric PSNR $page correct$page diff$page 2>&1`
if [ "$result" = "inf" ]
#echo "$page is OK"
echo "$page has ERRORs, see temp-$bn/diff$page"
The latest version of the script where this fragment comes from will always be
("\''/").__..-''"`-. . 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