The reasons for testing a particular region of a PDF page are described in section
3.18: “Layout - in Clipping Areas”.
To find the coordinates of the area you want to test, PDFUnit provides the small utility
RenderPdfClippingAreaToImage. Choose the width, height and the position of
the upper left corner and the corresponding region is then extracted into a file.
Verify this file then “by eye” and vary the parameters until you got the right region.
Once you have found the correct coordinates for your region, use those parameters
in your PDFUnit test.
:: :: Render a part of a PDF page into an image file :: @echo off setlocal set CLASSPATH=./lib/pdfunit-2015.10/*;%CLASSPATH% set CLASSPATH=./lib/jpedal/*;%CLASSPATH% set CLASSPATH=./lib/bouncycastle-jdk15on-150/*;%CLASSPATH% set CLASSPATH=./lib/aspectj-1.8.0/*;%CLASSPATH% set TOOL=com.pdfunit.tools.RenderPdfClippingAreaToImage set OUT_DIR=./tmp set PAGENUMBER=1 set IN_FILE=documentForTextClipping.pdf set PASSWD= :: Format unit can only be 'mm' or 'points' set FORMATUNIT=points :: Put these values into your test code: set UPPERLEFTX=50 set UPPERLEFTY=130 set WIDTH=170 set HEIGHT=25 java %TOOL% %IN_FILE% %PAGENUMBER% %OUT_DIR% %FORMATUNIT% %UPPERLEFTX% %UPPERLEFTY% %WIDTH% %HEIGHT% %PASSWD% endlocal
As in line 17,
mm (Millimeter) or
can be used as the unit of measurement to describe the clipping area.
Maybe, you have to use a calculator to get the right values.
The upper part of the input file
the text: “
Content on first page.
The generated image file has to be checked.
The name of the generated PNG includes the area’s coordinates.
Because PDFUnit and the utility program
use the same algorithm, you can use the parameter values from the script for
your test. And later, you can derive them from the file name:
# # Parameters from filename: # _rendered_documentForTextClipping_page-1_area-50-130-170-25.out.png | | | | | | | +- height | | +- width | +- upperLeftY +- upperLeftX
Internally PDFUnit uses functions from the project “jPedal” (http://www.idrsolutions.com/). Thanks to the developer team.