9.14.  Render Pages to PNG

If you want to test formatted text, the only way to do it is to render a PDF page and compare the result with an image of the correctly formatted content. Section 3.17: “Layout - Entire PDF Pages” describes layout-tests using rendered pages. And the utility RenderPdfToImages renders a PDF document page by page into PNG files.

Program Start

::
:: Render PDF into image files. Each page as a file.
::

@echo off
setlocal
set CLASSPATH=./lib/pdfunit-2015.10/*;%CLASSPATH%
set CLASSPATH=./lib/jpedal/*;%CLASSPATH%
set CLASSPATH=./lib/bouncycastle-jdk15on-150/*;%CLASSPATH%

set TOOL=com.pdfunit.tools.RenderPdfToImages
set OUT_DIR=./tmp
set IN_FILE=compareToMaster.pdf
set PASSWD=

java  %TOOL%  %IN_FILE%  %OUT_DIR%  %PASSWD%
endlocal

Input

The input file compareToMaster.pdf consists of 4 pages with different images and text. The PDF Reader SumatraPDF (http://code.google.com/p/sumatrapdf) shows the first page:

Output

After running the rendering program 4 files are created:

.\tmp\_rendered_compareToMaster_page1
.\tmp\_rendered_compareToMaster_page2
.\tmp\_rendered_compareToMaster_page3
.\tmp\_rendered_compareToMaster_page4

The first of these files looks the same as seen with the PDF Reader.

Internally, PDFUnit uses the same algorithm to render the pages as the rendering program does. So any difference found by a test is due to a change in the PDF document.

PDFUnit uses the class org.jpedal.PdfDecoder from the project jPedal (http://www.idrsolutions.com/). Thanks to the developers.