I need to refactor some reports (generated with Jasper) using MS Reporting Services. Copies of original reports are available in PDF. The requirement is to make the new reports “pixel perfect” which is very cumbersome…
For making life easier I would like to have a tool which overlays the original and generated report PDFs in order to measure if they are pixel perfect or not.
Is such a tool out there?
The most simple, immediately available method to do this: use ImageMagick’s
compare(which is also available on Windows/Linux/Mac and other).It can even compare PDF pages (though it uses Ghostscript as its delegate to render the PDF pages to pixel images first):
The resulting
delta.pdfwill depict each pixel as red which has a different color between the two compared PDF pages. All identical pixels will be purely white. The[0]tellcompareto use the first pages of each file for comparison (page count is zero-based).You can see how this works out with the following example:
Here are the respective pages (converted to scaled-down PNGs for web display). The reference page is on the left, the modified page is the middle one, the ‘delta-pixel-are-red’ image is on the right:
A slightly different visual result you can get by skipping the
-compose srcparameter. Then you’ll get the original file’s pixels as a gray-shaded background (for context) with the delta pixels in red:If you don’t like the red color for pixel differences, use
-highlight-color:The default resolution used to render the PDF pages is 72 dpi. Should you need a higher precision, you can switch to 300 dpi using the
-densityparameter like this:Note, switching to higher densities will slow down the process and create bigger files.
You can even create a *.txt file for the delta image which describes each pixel’s coordinates and the respective color values:
Then simply count the number of total vs. black pixels (sorry, this is Unix/Linux/MacOSX syntax):
In the example used for the illustrations above, I get
Of course the ‘ideal’ result would be