Package org.apache.pdfbox.preflight.ValidationResult

Examples of org.apache.pdfbox.preflight.ValidationResult.ValidationError


    private void checkCharProcsAndMetrics() throws ValidationException
    {
        List<Integer> widths = getWidths(font);
        if (widths == null || widths.isEmpty())
        {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
                    "The Witdhs array is unreachable"));
            return;
        }

        COSDictionary charProcs = COSUtils.getAsDictionary(fontDictionary.getItem(COSName.CHAR_PROCS), cosDocument);
        if (charProcs == null)
        {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
                    "The CharProcs element isn't a dictionary"));
            return;
        }

        int fc = font.getCOSObject().getInt(COSName.FIRST_CHAR, -1);
        int lc = font.getCOSObject().getInt(COSName.LAST_CHAR, -1);

        /*
         * wArr length = (lc - fc) + 1 and it is an array of int.
         * If FirstChar is greater than LastChar, the validation
         * will fail because of the array will have an expected size &lt;= 0.
         */
        int expectedLength = (lc - fc) + 1;
        if (widths.size() != expectedLength)
        {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
                    "The length of Witdhs array is invalid. Expected : \"" + expectedLength + "\" Current : \""
                            + widths.size() + "\""));
            return;
        }

        // Check width consistency
        for (int i = 0; i < expectedLength; i++)
        {
            int code = fc + i;
            float width = widths.get(i);

            PDType3CharProc charProc = getCharProc(code);
            if (charProc != null)
            {
                try
                {
                    float fontProgramWidth = getWidthFromCharProc(charProc);
                    if (width == fontProgramWidth)
                    {
                        // Glyph is OK, we keep the CID.
                        this.fontContainer.markAsValid(code);
                    }
                    else
                    {
                        GlyphException glyphEx = new GlyphException(ERROR_FONTS_METRICS, code,
                                "The character with CID\"" + code + "\" should have a width equals to " + width);
                        this.fontContainer.markAsInvalid(code, glyphEx);
                    }
                }
                catch (ContentStreamException e)
                {
                    // TODO spaces/isartor-6-2-3-3-t02-fail-h.pdf --> si ajout de l'erreur dans le container le test
                    // echoue... pourquoi si la font est utilisée ca devrait planter???
                    this.context.addValidationError(new ValidationError(((ContentStreamException) e).getErrorCode(), e
                            .getMessage()));
                    return;
                }
                catch (IOException e)
                {
                    this.fontContainer.push(new ValidationError(ERROR_FONTS_TYPE3_DAMAGED,
                            "The CharProcs references an element which can't be read"));
                    return;
                }
            }
        }
View Full Code Here


        {

            COSDictionary dictionary = COSUtils.getAsDictionary(resources, cosDocument);
            if (dictionary == null)
            {
                this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID,
                        "The Resources element isn't a dictionary"));
                return;
            }

            // process Fonts and XObjects
            ContextHelper.validateElement(context, new PDResources(dictionary), RESOURCES_PROCESS);
            COSBase cbFont = dictionary.getItem(COSName.FONT);

            if (cbFont != null)
            {
                /*
                 * Check that all referenced object are present in the PDF file
                 */
                COSDictionary dicFonts = COSUtils.getAsDictionary(cbFont, cosDocument);
                Set<COSName> keyList = dicFonts.keySet();
                for (Object key : keyList)
                {

                    COSBase item = dicFonts.getItem((COSName) key);
                    COSDictionary xObjFont = COSUtils.getAsDictionary(item, cosDocument);

                    try
                    {
                        PDFont aFont = PDFontFactory.createFont(xObjFont);
                        FontContainer aContainer = this.context.getFontContainer(aFont.getCOSObject());
                        // another font is used in the Type3, check if the font is valid.
                        if (!aContainer.isValid())
                        {
                            this.fontContainer.push(new ValidationError(ERROR_FONTS_TYPE3_DAMAGED,
                                    "The Resources dictionary of type 3 font contains invalid font"));
                        }
                    }
                    catch (IOException e)
                    {
                        context.addValidationError(new ValidationError(PreflightConstants.ERROR_FONTS_DAMAGED,
                                "Unable to valid the Type3 : " + e.getMessage()));
                    }
                }
            }
        }
View Full Code Here

            {
                Encoding encodingValue = ttFont.getEncoding();
                if (encodingValue == null
                        || !(encodingValue instanceof MacRomanEncoding || encodingValue instanceof WinAnsiEncoding))
                {
                    this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING,
                            "The Encoding is invalid for the NonSymbolic TTF"));
                }
            }

            /*
             * For symbolic font, no encoding entry is allowed and only one encoding entry is expected into the FontFile
             * CMap (Check latter when the FontFile stream will be checked)
             */
            if (fd.isSymbolic() && ((COSDictionary) fontDictionary).getItem(COSName.ENCODING) != null)
            {
                this.fontContainer.push(new ValidationError(ERROR_FONTS_ENCODING,
                        "The Encoding should be missing for the Symbolic TTF"));
            }
        }
    }
View Full Code Here

        arePresent &= fontDictionary.containsKey(COSName.CIDSYSTEMINFO);
        arePresent &= fontDictionary.containsKey(COSName.FONT_DESC);

        if (!arePresent)
        {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_DICTIONARY_INVALID, "Required keys are missing"));
        }

        checkCIDSystemInfo(fontDictionary.getItem(COSName.CIDSYSTEMINFO));
        checkCIDToGIDMap(fontDictionary.getItem(COSName.CID_TO_GID_MAP));
    }
View Full Code Here

            COSBase sup = cidSysInfo.getItem(COSName.SUPPLEMENT);

            if (!(COSUtils.isString(reg, cosDocument) && COSUtils.isString(ord, cosDocument) && COSUtils.isInteger(sup,
                    cosDocument)))
            {
                this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_SYSINFO));
            }
        }
        else
        {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_SYSINFO));
        }
    }
View Full Code Here

        {
            // ---- valid only if the string is Identity
            String ctogStr = COSUtils.getAsString(ctog, cosDocument);
            if (!FONT_DICTIONARY_VALUE_CMAP_IDENTITY.equals(ctogStr))
            {
                this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CIDTOGID,
                        "The CIDToGID entry is invalid"));
            }
        }
        else if (COSUtils.isStream(ctog, cosDocument))
        {
            try
            {
                COSStream stream = COSUtils.getAsStream(ctog, cosDocument);

                // todo: check the map's content? (won't pdfbox do this?)
                InputStream is = stream.getUnfilteredStream();
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                byte[] map = os.toByteArray();
            }
            catch (IOException e)
            {
                // map can be invalid, return a Validation Error
                this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CIDTOGID));
            }
        }
        else if (mandatory)
        {
            this.fontContainer.push(new ValidationError(ERROR_FONTS_CIDKEYED_CIDTOGID));
        }
    }
View Full Code Here

        if (vPath.isEmpty()){
            return;
        }
        else if (!vPath.isExpectedType(PDPage.class))
        {
            addValidationError(context, new ValidationError(PreflightConstants.ERROR_PDF_PROCESSING_MISSING, "Page validation required at least a PDPage"));
        }
        else
        {
            PDPage page = (PDPage) vPath.peek();
            validateActions(context, page);
View Full Code Here

                PDXObject thumbImg = PDImageXObject.createThumbnail((COSStream)thumbBase);
                ContextHelper.validateElement(context, thumbImg, GRAPHIC_PROCESS);
            }
            catch (IOException e)
            {
                context.addValidationError(new ValidationError(ERROR_GRAPHIC_INVALID, "Unable to read Thumb image : "
                        + e.getMessage()));
            }
        }
    }
View Full Code Here

            PreflightContentStream csWrapper = new PreflightContentStream(context, page);
            csWrapper.validPageContentStream();
        }
        catch (IOException e)
        {
            context.addValidationError(new ValidationError(ERROR_UNKOWN_ERROR, e.getMessage()));
        }
    }
View Full Code Here

        if (groupDictionary != null)
        {
            String sVal = groupDictionary.getNameAsString(COSName.S);
            if (XOBJECT_DICTIONARY_VALUE_S_TRANSPARENCY.equals(sVal))
            {
                context.addValidationError(new ValidationError(ERROR_GRAPHIC_TRANSPARENCY_GROUP,
                        "Group has a transparency S entry or the S entry is null."));
                return;
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.preflight.ValidationResult.ValidationError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.