示例#1
0
        protected internal override void CheckForm(PdfDictionary form)
        {
            if (form == null)
            {
                return;
            }
            PdfBoolean needAppearances = form.GetAsBoolean(PdfName.NeedAppearances);

            if (needAppearances != null && needAppearances.GetValue())
            {
                throw new PdfAConformanceException(PdfAConformanceException.NeedAppearancesFlagOfTheInteractiveFormDictionaryShallEitherNotBePresentedOrShallBeFalse
                                                   );
            }
            CheckResources(form.GetAsDictionary(PdfName.DR));
            PdfArray fields = form.GetAsArray(PdfName.Fields);

            if (fields != null)
            {
                fields = GetFormFields(fields);
                foreach (PdfObject field in fields)
                {
                    PdfDictionary fieldDic = (PdfDictionary)field;
                    if (fieldDic.ContainsKey(PdfName.A) || fieldDic.ContainsKey(PdfName.AA))
                    {
                        throw new PdfAConformanceException(PdfAConformanceException.WidgetAnnotationDictionaryOrFieldDictionaryShallNotIncludeAOrAAEntry
                                                           );
                    }
                    CheckResources(fieldDic.GetAsDictionary(PdfName.DR));
                }
            }
        }
示例#2
0
        protected internal override void CheckForm(PdfDictionary form)
        {
            if (form == null)
            {
                return;
            }
            PdfBoolean needAppearances = form.GetAsBoolean(PdfName.NeedAppearances);

            if (needAppearances != null && needAppearances.GetValue())
            {
                throw new PdfAConformanceException(PdfAConformanceException.NEEDAPPEARANCES_FLAG_OF_THE_INTERACTIVE_FORM_DICTIONARY_SHALL_EITHER_NOT_BE_PRESENTED_OR_SHALL_BE_FALSE
                                                   );
            }
            CheckResources(form.GetAsDictionary(PdfName.DR));
            PdfArray fields = form.GetAsArray(PdfName.Fields);

            if (fields != null)
            {
                fields = GetFormFields(fields);
                foreach (PdfObject field in fields)
                {
                    PdfDictionary fieldDic = (PdfDictionary)field;
                    if (fieldDic.ContainsKey(PdfName.A) || fieldDic.ContainsKey(PdfName.AA))
                    {
                        throw new PdfAConformanceException(PdfAConformanceException.WIDGET_ANNOTATION_DICTIONARY_OR_FIELD_DICTIONARY_SHALL_NOT_INCLUDE_A_OR_AA_ENTRY
                                                           );
                    }
                    CheckResources(fieldDic.GetAsDictionary(PdfName.DR));
                }
            }
        }
示例#3
0
        private void DrawOverlayText(PdfCanvas canvas, String overlayText, Rectangle annotRect, PdfBoolean repeat,
                                     PdfString defaultAppearance, int justification)
        {
            IDictionary <String, IList> parsedDA;

            try {
                parsedDA = ParseDAParam(defaultAppearance);
            }
            catch (NullReferenceException) {
                throw new PdfException(PdfException.DefaultAppearanceNotFound);
            }
            PdfFont       font;
            float         fontSize       = 12;
            IList         fontArgs       = parsedDA.Get("Tf");
            PdfDictionary formDictionary = pdfDocument.GetCatalog().GetPdfObject().GetAsDictionary(PdfName.AcroForm);

            if (fontArgs != null && formDictionary != null)
            {
                font     = GetFontFromAcroForm((PdfName)fontArgs[0]);
                fontSize = ((PdfNumber)fontArgs[1]).FloatValue();
            }
            else
            {
                font = PdfFontFactory.CreateFont();
            }
            if (pdfDocument.IsTagged())
            {
                canvas.OpenTag(new CanvasArtifact());
            }
            iText.Layout.Canvas modelCanvas   = new iText.Layout.Canvas(canvas, pdfDocument, annotRect, false);
            Paragraph           p             = new Paragraph(overlayText).SetFont(font).SetFontSize(fontSize).SetMargin(0);
            TextAlignment?      textAlignment = TextAlignment.LEFT;

            switch (justification)
            {
            case 1: {
                textAlignment = TextAlignment.CENTER;
                break;
            }

            case 2: {
                textAlignment = TextAlignment.RIGHT;
                break;
            }

            default: {
                break;
            }
            }
            p.SetTextAlignment(textAlignment);
            IList strokeColorArgs;

            parsedDA.TryGetValue("StrokeColor", out strokeColorArgs);
            if (strokeColorArgs != null)
            {
                p.SetStrokeColor(GetColor(strokeColorArgs));
            }
            IList fillColorArgs;

            parsedDA.TryGetValue("FillColor", out fillColorArgs);
            if (fillColorArgs != null)
            {
                p.SetFontColor(GetColor(fillColorArgs));
            }
            modelCanvas.Add(p);
            if (repeat != null && repeat.GetValue())
            {
                bool?isFull = modelCanvas.GetRenderer().GetPropertyAsBoolean(Property.FULL);
                while (isFull == null || (bool)!isFull)
                {
                    p.Add(overlayText);
                    LayoutArea previousArea = modelCanvas.GetRenderer().GetCurrentArea().Clone();
                    modelCanvas.Relayout();
                    if (modelCanvas.GetRenderer().GetCurrentArea().Equals(previousArea))
                    {
                        // Avoid infinite loop. This might be caused by the fact that the font does not support the text we want to show
                        break;
                    }
                    isFull = modelCanvas.GetRenderer().GetPropertyAsBoolean(Property.FULL);
                }
            }
            modelCanvas.GetRenderer().Flush();
            if (pdfDocument.IsTagged())
            {
                canvas.CloseTag();
            }
        }
示例#4
0
        public virtual bool GetOpen()
        {
            PdfBoolean open = GetPdfObject().GetAsBoolean(PdfName.Open);

            return(open != null && open.GetValue());
        }
示例#5
0
        /// <summary>
        /// If true, the text specified by the
        /// <see cref="iText.Kernel.Pdf.PdfName.Contents"/>
        /// or
        /// <see cref="iText.Kernel.Pdf.PdfName.RC"/>
        /// entries
        /// (see
        /// <see cref="PdfAnnotation.GetContents()"/>
        /// and
        /// <see cref="PdfMarkupAnnotation.GetRichText()"/>
        /// )
        /// is replicated as a caption in the appearance of the line.
        /// </summary>
        /// <returns>
        /// true, if the annotation text is replicated as a caption, false otherwise. If this property is
        /// not set, default value is used which is <i>false</i>.
        /// </returns>
        public virtual bool GetContentsAsCaption()
        {
            PdfBoolean b = GetPdfObject().GetAsBoolean(PdfName.Cap);

            return(b != null && b.GetValue());
        }
示例#6
0
        public virtual byte[] Decode(byte[] b, PdfName filterName, PdfObject decodeParams, PdfDictionary streamDictionary
                                     )
        {
            PdfNumber wn = streamDictionary.GetAsNumber(PdfName.Width);
            PdfNumber hn = streamDictionary.GetAsNumber(PdfName.Height);

            if (wn == null || hn == null)
            {
                throw new PdfException(PdfException.FilterCcittfaxdecodeIsOnlySupportedForImages);
            }
            int           width     = wn.IntValue();
            int           height    = hn.IntValue();
            PdfDictionary param     = decodeParams is PdfDictionary ? (PdfDictionary)decodeParams : null;
            int           k         = 0;
            bool          blackIs1  = false;
            bool          byteAlign = false;

            if (param != null)
            {
                PdfNumber kn = param.GetAsNumber(PdfName.K);
                if (kn != null)
                {
                    k = kn.IntValue();
                }
                PdfBoolean bo = param.GetAsBoolean(PdfName.BlackIs1);
                if (bo != null)
                {
                    blackIs1 = bo.GetValue();
                }
                bo = param.GetAsBoolean(PdfName.EncodedByteAlign);
                if (bo != null)
                {
                    byteAlign = bo.GetValue();
                }
            }
            byte[] outBuf = new byte[(width + 7) / 8 * height];
            TIFFFaxDecompressor decoder = new TIFFFaxDecompressor();

            if (k == 0 || k > 0)
            {
                int tiffT4Options = k > 0 ? TIFFConstants.GROUP3OPT_2DENCODING : 0;
                tiffT4Options |= byteAlign ? TIFFConstants.GROUP3OPT_FILLBITS : 0;
                decoder.SetOptions(1, TIFFConstants.COMPRESSION_CCITTFAX3, tiffT4Options, 0);
                decoder.DecodeRaw(outBuf, b, width, height);
                if (decoder.fails > 0)
                {
                    byte[] outBuf2  = new byte[(width + 7) / 8 * height];
                    int    oldFails = decoder.fails;
                    decoder.SetOptions(1, TIFFConstants.COMPRESSION_CCITTRLE, tiffT4Options, 0);
                    decoder.DecodeRaw(outBuf2, b, width, height);
                    if (decoder.fails < oldFails)
                    {
                        outBuf = outBuf2;
                    }
                }
            }
            else
            {
                TIFFFaxDecoder deca = new TIFFFaxDecoder(1, width, height);
                deca.DecodeT6(outBuf, b, 0, height, 0);
            }
            if (!blackIs1)
            {
                int len = outBuf.Length;
                for (int t = 0; t < len; ++t)
                {
                    outBuf[t] ^= 0xff;
                }
            }
            b = outBuf;
            return(b);
        }