Exception occur :Reason : Coordinate outside allow

2020-02-16 03:54发布

问题:

I am getting "Coordinate outside allowed range java.lang.IllegalStateException" exception while applying redaction in pdf document.

i have tried with various coordinate but every time same exception showing.Could you please help us why i am getting this exception only for specific document.

Exception Trace: Reason : Coordinate outside allowed range java.lang.IllegalStateException: Coordinate outside allowed range at com.itextpdf.text.pdf.parser.clipper.ClipperBase.rangeTest(ClipperBase.java:120) at com.itextpdf.text.pdf.parser.clipper.ClipperBase.rangeTest(ClipperBase.java:122) at com.itextpdf.text.pdf.parser.clipper.ClipperBase.addPath(ClipperBase.java:194) at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRegionFilter.addPath(PdfCleanUpRegionFilter.java:418) at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRegionFilter.filterFillPath(PdfCleanUpRegionFilter.java:173) at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRenderListener.filterCurrentPath(PdfCleanUpRenderListener.java:368) at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRenderListener.renderPath(PdfCleanUpRenderListener.java:207) at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.paintPath(PdfContentStreamProcessor.java:377)

Used itextpdf-5.5.9 and itext-xtra-5.5.9

Sample code :

        PdfReader reader = new PdfReader(src);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(targetPdf));
        stamper.setRotateContents(false);
        List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
        Rectangle rectangle = new Rectangle(400, 600, 500, 650);
        cleanUpLocations.add(new PdfCleanUpLocation(1, rectangle, BaseColor.BLACK));
        PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, stamper);
        cleaner.cleanUp();
        stamper.close();
        reader.close();

回答1:

This issue is related to the fact, that we itext used long datatype as internal representation for coordinates in PDF during certain operations. This decision was made in order to avoid precison loss . The content stream of the document you provided contains the command of drawing a rectangle with coordinates (0,0,65535,65535). At some point of the cleaner.cleanUp(); operation, we have to use the coordinates specified in the PDF content stream without applying any transformation matrices. In order to convert it to long, every coordinate gets multiplied by a public constant PdfCleanUpProcessor.floatMultiplier , which is currently equal to 10^14. Then 65535*10^14 is compared to the biggest long number (namely, 4611686018427387903) and is considered to be out of range, because 65535*10^14 is bigger. We may change PdfCleanUpProcessor.floatMultiplier to be 0.5*10^14, or 10^13. This should be usable in other situations, because 65535 is a tremendous number for a PDF, and is not encountered frequently. It's extremely unlikely to encounter even bigger numbers



标签: itext