예제 #1
0
        protected override void CheckImage(PdfWriter writer, int key, Object obj1)
        {
            PdfImage image = (PdfImage)obj1;

            if (image.Get(PdfName.SMASK) != null && !PdfName.NONE.Equals(image.GetAsName(PdfName.SMASK)))
            {
                throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("the.smask.key.is.not.allowed.in.images"));
            }
            if (image.Contains(PdfName.ALTERNATES))
            {
                throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("an.image.dictionary.shall.not.contain.alternates.key"));
            }
            if (image.Contains(PdfName.OPI))
            {
                throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("an.image.dictionary.shall.not.contain.opi.key"));
            }
            PdfBoolean interpolate = image.GetAsBoolean(PdfName.INTERPOLATE);

            if (interpolate != null && interpolate.BooleanValue)
            {
                throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("the.value.of.interpolate.key.shall.not.be.true"));
            }
            PdfName intent = image.GetAsName(PdfName.INTENT);

            if (intent != null && !(PdfName.RELATIVECOLORIMETRIC.Equals(intent) || PdfName.ABSOLUTECOLORIMETRIC.Equals(intent) || PdfName.PERCEPTUAL.Equals(intent) || PdfName.SATURATION.Equals(intent)))
            {
                throw new PdfAConformanceException(obj1, MessageLocalization.GetComposedMessage("1.value.of.intent.key.is.not.allowed", intent.ToString()));
            }
        }
예제 #2
0
        protected override void CheckImage(PdfWriter writer, int key, Object obj1)
        {
            PdfImage image = (PdfImage)obj1;

            if (image.Get(PdfName.SMASK) != null)
            {
                throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("the.smask.key.is.not.allowed.in.images"));
            }
        }
예제 #3
0
        /**
         *
         * @param writer
         * @param key
         * @param obj1
         */
        static public void CheckPdfAConformance(PdfWriter writer, int key, Object obj1)
        {
            if (writer == null || !writer.IsPdfIso())
            {
                return;
            }
            switch (key)
            {
            case PdfIsoKeys.PDFISOKEY_FONT:
                if (!((BaseFont)obj1).IsEmbedded())
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("all.the.fonts.must.be.embedded.this.one.isn.t.1", ((BaseFont)obj1).PostscriptFontName));
                }
                break;

            case PdfIsoKeys.PDFISOKEY_IMAGE:
                PdfImage image = (PdfImage)obj1;
                if (image.Get(PdfName.SMASK) != null)
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("the.smask.key.is.not.allowed.in.images"));
                }
                break;

            case PdfIsoKeys.PDFISOKEY_GSTATE:
                PdfDictionary gs  = (PdfDictionary)obj1;
                PdfObject     obj = gs.Get(PdfName.BM);
                if (obj != null && !PdfGState.BM_NORMAL.Equals(obj) && !PdfGState.BM_COMPATIBLE.Equals(obj))
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("blend.mode.1.not.allowed", obj.ToString()));
                }
                obj = gs.Get(PdfName.CA);
                double v = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).DoubleValue) != 1.0)
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("transparency.is.not.allowed.ca.eq.1", v));
                }
                obj = gs.Get(PdfName.ca_);
                v   = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).DoubleValue) != 1.0)
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("transparency.is.not.allowed.ca.eq.1", v));
                }
                break;

            case PdfIsoKeys.PDFISOKEY_LAYER:
                throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("layers.are.not.allowed"));

            default:
                break;
            }
        }
예제 #4
0
        /**
         * Business logic that checks if a certain object is in conformance with PDF/X.
         * @param writer    the writer that is supposed to write the PDF/X file
         * @param key       the type of PDF ISO conformance that has to be checked
         * @param obj1      the object that is checked for conformance
         */
        public static void CheckPDFXConformance(PdfWriter writer, int key, Object obj1)
        {
            if (writer == null || !writer.IsPdfX())
            {
                return;
            }
            int conf = writer.PDFXConformance;

            switch (key)
            {
            case PdfIsoKeys.PDFISOKEY_COLOR:
                switch (conf)
                {
                case PdfWriter.PDFX1A2001:
                    if (obj1 is ExtendedColor)
                    {
                        ExtendedColor ec = (ExtendedColor)obj1;
                        switch (ec.Type)
                        {
                        case ExtendedColor.TYPE_CMYK:
                        case ExtendedColor.TYPE_GRAY:
                            return;

                        case ExtendedColor.TYPE_RGB:
                            throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("colorspace.rgb.is.not.allowed"));

                        case ExtendedColor.TYPE_SEPARATION:
                            SpotColor sc = (SpotColor)ec;
                            CheckPDFXConformance(writer, PdfIsoKeys.PDFISOKEY_COLOR, sc.PdfSpotColor.AlternativeCS);
                            break;

                        case ExtendedColor.TYPE_SHADING:
                            ShadingColor xc = (ShadingColor)ec;
                            CheckPDFXConformance(writer, PdfIsoKeys.PDFISOKEY_COLOR, xc.PdfShadingPattern.Shading.ColorSpace);
                            break;

                        case ExtendedColor.TYPE_PATTERN:
                            PatternColor pc = (PatternColor)ec;
                            CheckPDFXConformance(writer, PdfIsoKeys.PDFISOKEY_COLOR, pc.Painter.DefaultColor);
                            break;
                        }
                    }
                    else if (obj1 is BaseColor)
                    {
                        throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("colorspace.rgb.is.not.allowed"));
                    }
                    break;
                }
                break;

            case PdfIsoKeys.PDFISOKEY_CMYK:
                break;

            case PdfIsoKeys.PDFISOKEY_RGB:
                if (conf == PdfWriter.PDFX1A2001)
                {
                    throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("colorspace.rgb.is.not.allowed"));
                }
                break;

            case PdfIsoKeys.PDFISOKEY_FONT:
                if (!((BaseFont)obj1).IsEmbedded())
                {
                    throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("all.the.fonts.must.be.embedded.this.one.isn.t.1", ((BaseFont)obj1).PostscriptFontName));
                }
                break;

            case PdfIsoKeys.PDFISOKEY_IMAGE:
                PdfImage image = (PdfImage)obj1;
                if (image.Get(PdfName.SMASK) != null)
                {
                    throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("the.smask.key.is.not.allowed.in.images"));
                }
                switch (conf)
                {
                case PdfWriter.PDFX1A2001:
                    PdfObject cs = image.Get(PdfName.COLORSPACE);
                    if (cs == null)
                    {
                        return;
                    }
                    if (cs.IsName())
                    {
                        if (PdfName.DEVICERGB.Equals(cs))
                        {
                            throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("colorspace.rgb.is.not.allowed"));
                        }
                    }
                    else if (cs.IsArray())
                    {
                        if (PdfName.CALRGB.Equals(((PdfArray)cs)[0]))
                        {
                            throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("colorspace.calrgb.is.not.allowed"));
                        }
                    }
                    break;
                }
                break;

            case PdfIsoKeys.PDFISOKEY_GSTATE:
                PdfDictionary gs  = (PdfDictionary)obj1;
                PdfObject     obj = gs.Get(PdfName.BM);
                if (obj != null && !PdfGState.BM_NORMAL.Equals(obj) && !PdfGState.BM_COMPATIBLE.Equals(obj))
                {
                    throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("blend.mode.1.not.allowed", obj.ToString()));
                }
                obj = gs.Get(PdfName.CA);
                double v = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).DoubleValue) != 1.0)
                {
                    throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("transparency.is.not.allowed.ca.eq.1", v));
                }
                obj = gs.Get(PdfName.ca_);
                v   = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).DoubleValue) != 1.0)
                {
                    throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("transparency.is.not.allowed.ca.eq.1", v));
                }
                break;

            case PdfIsoKeys.PDFISOKEY_LAYER:
                throw new PdfXConformanceException(MessageLocalization.GetComposedMessage("layers.are.not.allowed"));
            }
        }
예제 #5
0
        /**
         * Business logic that checks if a certain object is in conformance with PDF/X.
         * @param writer    the writer that is supposed to write the PDF/X file
         * @param key       the type of PDF/X conformance that has to be checked
         * @param obj1      the object that is checked for conformance
         */
        public static void CheckPDFXConformance(PdfWriter writer, int key, Object obj1)
        {
            if (writer == null || !writer.IsPdfX())
            {
                return;
            }
            int conf = writer.PDFXConformance;

            switch (key)
            {
            case PDFXKEY_COLOR:
                switch (conf)
                {
                case PdfWriter.PDFX1A2001:
                    if (obj1 is ExtendedColor)
                    {
                        ExtendedColor ec = (ExtendedColor)obj1;
                        switch (ec.Type)
                        {
                        case ExtendedColor.TYPE_CMYK:
                        case ExtendedColor.TYPE_GRAY:
                            return;

                        case ExtendedColor.TYPE_RGB:
                            throw new PdfXConformanceException("Colorspace RGB is not allowed.");

                        case ExtendedColor.TYPE_SEPARATION:
                            SpotColor sc = (SpotColor)ec;
                            CheckPDFXConformance(writer, PDFXKEY_COLOR, sc.PdfSpotColor.AlternativeCS);
                            break;

                        case ExtendedColor.TYPE_SHADING:
                            ShadingColor xc = (ShadingColor)ec;
                            CheckPDFXConformance(writer, PDFXKEY_COLOR, xc.PdfShadingPattern.Shading.ColorSpace);
                            break;

                        case ExtendedColor.TYPE_PATTERN:
                            PatternColor pc = (PatternColor)ec;
                            CheckPDFXConformance(writer, PDFXKEY_COLOR, pc.Painter.DefaultColor);
                            break;
                        }
                    }
                    else if (obj1 is Color)
                    {
                        throw new PdfXConformanceException("Colorspace RGB is not allowed.");
                    }
                    break;
                }
                break;

            case PDFXKEY_CMYK:
                break;

            case PDFXKEY_RGB:
                if (conf == PdfWriter.PDFX1A2001)
                {
                    throw new PdfXConformanceException("Colorspace RGB is not allowed.");
                }
                break;

            case PDFXKEY_FONT:
                if (!((BaseFont)obj1).IsEmbedded())
                {
                    throw new PdfXConformanceException("All the fonts must be embedded. This one isn't: " + ((BaseFont)obj1).PostscriptFontName);
                }
                break;

            case PDFXKEY_IMAGE:
                PdfImage image = (PdfImage)obj1;
                if (image.Get(PdfName.SMASK) != null)
                {
                    throw new PdfXConformanceException("The /SMask key is not allowed in images.");
                }
                switch (conf)
                {
                case PdfWriter.PDFX1A2001:
                    PdfObject cs = image.Get(PdfName.COLORSPACE);
                    if (cs == null)
                    {
                        return;
                    }
                    if (cs.IsName())
                    {
                        if (PdfName.DEVICERGB.Equals(cs))
                        {
                            throw new PdfXConformanceException("Colorspace RGB is not allowed.");
                        }
                    }
                    else if (cs.IsArray())
                    {
                        if (PdfName.CALRGB.Equals(((PdfArray)cs)[0]))
                        {
                            throw new PdfXConformanceException("Colorspace CalRGB is not allowed.");
                        }
                    }
                    break;
                }
                break;

            case PDFXKEY_GSTATE:
                PdfDictionary gs  = (PdfDictionary)obj1;
                PdfObject     obj = gs.Get(PdfName.BM);
                if (obj != null && !PdfGState.BM_NORMAL.Equals(obj) && !PdfGState.BM_COMPATIBLE.Equals(obj))
                {
                    throw new PdfXConformanceException("Blend mode " + obj.ToString() + " not allowed.");
                }
                obj = gs.Get(PdfName.CA);
                double v = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).DoubleValue) != 1.0)
                {
                    throw new PdfXConformanceException("Transparency is not allowed: /CA = " + v);
                }
                obj = gs.Get(PdfName.ca_);
                v   = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).DoubleValue) != 1.0)
                {
                    throw new PdfXConformanceException("Transparency is not allowed: /ca = " + v);
                }
                break;

            case PDFXKEY_LAYER:
                throw new PdfXConformanceException("Layers are not allowed.");
            }
        }
예제 #6
0
        /**
         *
         * @param writer
         * @param key
         * @param obj1
         */
        static public void CheckPdfAConformance(PdfWriter writer, int key, Object obj1)
        {
            if (writer == null || !writer.IsPdfIso())
            {
                return;
            }
            switch (key)
            {
            case PdfIsoKeys.PDFISOKEY_FONT:
                BaseFont bf = (BaseFont)obj1;
                if (bf.FontType == BaseFont.FONT_TYPE_DOCUMENT)
                {
                    PdfStream     prs            = null;
                    PdfDictionary fontDictionary = ((DocumentFont)bf).FontDictionary;
                    PdfDictionary fontDescriptor = fontDictionary.GetAsDict(PdfName.FONTDESCRIPTOR);
                    if (fontDescriptor != null)
                    {
                        prs = fontDescriptor.GetAsStream(PdfName.FONTFILE);
                        if (prs == null)
                        {
                            prs = fontDescriptor.GetAsStream(PdfName.FONTFILE2);
                        }
                        if (prs == null)
                        {
                            prs = fontDescriptor.GetAsStream(PdfName.FONTFILE3);
                        }
                    }
                    if (prs == null)
                    {
                        throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("all.the.fonts.must.be.embedded.this.one.isn.t.1", ((BaseFont)obj1).PostscriptFontName));
                    }
                }
                else
                {
                    if (!bf.IsEmbedded())
                    {
                        throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("all.the.fonts.must.be.embedded.this.one.isn.t.1", ((BaseFont)obj1).PostscriptFontName));
                    }
                }
                break;

            case PdfIsoKeys.PDFISOKEY_IMAGE:
                PdfImage image = (PdfImage)obj1;
                if (image.Get(PdfName.SMASK) != null)
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("the.smask.key.is.not.allowed.in.images"));
                }
                break;

            case PdfIsoKeys.PDFISOKEY_GSTATE:
                PdfDictionary gs  = (PdfDictionary)obj1;
                PdfObject     obj = gs.Get(PdfName.BM);
                if (obj != null && !PdfGState.BM_NORMAL.Equals(obj) && !PdfGState.BM_COMPATIBLE.Equals(obj))
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("blend.mode.1.not.allowed", obj.ToString()));
                }
                obj = gs.Get(PdfName.CA);
                double v = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).DoubleValue) != 1.0)
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("transparency.is.not.allowed.ca.eq.1", v));
                }
                obj = gs.Get(PdfName.ca_);
                v   = 0.0;
                if (obj != null && (v = ((PdfNumber)obj).DoubleValue) != 1.0)
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("transparency.is.not.allowed.ca.eq.1", v));
                }
                break;

            case PdfIsoKeys.PDFISOKEY_LAYER:
                throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("layers.are.not.allowed"));

            default:
                break;
            }
        }