Equals() public method

public Equals ( Object obj ) : bool
obj Object
return bool
Example #1
0
        // ---------------------------------------------------------------------------
        /**
         * Manipulates a PDF file src with the byte array as result
         */
        public byte[] ManipulatePdf(byte[] pdf)
        {
            PdfName key = new PdfName("ITXT_SpecialId");
              PdfName value = new PdfName("123456789");
              // Read the file
              PdfReader reader = new PdfReader(pdf);
              int n = reader.XrefSize;
              PdfObject pdfObject;
              PRStream prStream;
              // Look for image and manipulate image prStream
              for (int i = 0; i < n; i++) {
            pdfObject = reader.GetPdfObject(i);
            if (pdfObject == null || !pdfObject.IsStream()) continue;

            prStream = (PRStream) pdfObject;
            byte[] imageBytes;
            if (value.Equals(prStream.Get(key))) {
              PdfImageObject image = new PdfImageObject(prStream);
              using (System.Drawing.Image original = image.GetDrawingImage()) {
            if (original == null) continue;
            int width = (int)(original.Width * FACTOR);
            int height = (int)(original.Height * FACTOR);

            using (System.Drawing.Image thumb = new Bitmap(width, height) ) {
              using ( Graphics graphic = Graphics.FromImage(thumb) ) {
                graphic.DrawImage(original, 0, 0, width, height);
                using (MemoryStream ms = new MemoryStream()) {
                  thumb.Save(ms, ImageFormat.Jpeg);
                  imageBytes = ms.ToArray();
                }
              }
            }
            prStream.Clear();
            prStream.SetData(imageBytes, false, PRStream.NO_COMPRESSION);
            prStream.Put(PdfName.TYPE, PdfName.XOBJECT);
            prStream.Put(PdfName.SUBTYPE, PdfName.IMAGE);
            prStream.Put(key, value);
            prStream.Put(PdfName.FILTER, PdfName.DCTDECODE);
            prStream.Put(PdfName.WIDTH, new PdfNumber(width));
            prStream.Put(PdfName.HEIGHT, new PdfNumber(height));
            prStream.Put(PdfName.BITSPERCOMPONENT, new PdfNumber(8));
            prStream.Put(PdfName.COLORSPACE, PdfName.DEVICERGB);
              }
            }
              }
              // Save altered PDF
              using (MemoryStream ms = new MemoryStream()) {
            using (PdfStamper stamper = new PdfStamper(reader, ms)) {
            }
            return ms.ToArray();
              }
        }
Example #2
0
        private void SetTextAlignAttribute(int elementAlign)
        {
            PdfName align = null;

            switch (elementAlign)
            {
            case Element.ALIGN_LEFT:
                align = PdfName.START;
                break;

            case Element.ALIGN_CENTER:
                align = PdfName.CENTER;
                break;

            case Element.ALIGN_RIGHT:
                align = PdfName.END;
                break;

            case Element.ALIGN_JUSTIFIED:
                align = PdfName.JUSTIFY;
                break;
            }
            PdfObject obj = GetParentAttribute(parent, PdfName.TEXTALIGN);

            if (obj is PdfName)
            {
                PdfName textAlign = ((PdfName)obj);
                if (align != null && !textAlign.Equals(align))
                {
                    this.SetAttribute(PdfName.TEXTALIGN, align);
                }
            }
            else
            {
                if (align != null && !PdfName.START.Equals(align))
                {
                    this.SetAttribute(PdfName.TEXTALIGN, align);
                }
            }
        }
        public override bool Equals(Object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (!(o is PdfSpotColor))
            {
                return(false);
            }

            PdfSpotColor spotColor = (PdfSpotColor)o;

            if (!altcs.Equals(spotColor.altcs))
            {
                return(false);
            }
            if (!name.Equals(spotColor.name))
            {
                return(false);
            }

            return(true);
        }
Example #4
0
        virtual public void SetMKIconFit(PdfName scale, PdfName scalingType, float leftoverLeft, float leftoverBottom, bool fitInBounds)
        {
            PdfDictionary dic = new PdfDictionary();

            if (!scale.Equals(PdfName.A))
            {
                dic.Put(PdfName.SW, scale);
            }
            if (!scalingType.Equals(PdfName.P))
            {
                dic.Put(PdfName.S, scalingType);
            }
            if (leftoverLeft != 0.5f || leftoverBottom != 0.5f)
            {
                PdfArray array = new PdfArray(new PdfNumber(leftoverLeft));
                array.Add(new PdfNumber(leftoverBottom));
                dic.Put(PdfName.A, array);
            }
            if (fitInBounds)
            {
                dic.Put(PdfName.FB, PdfBoolean.PDFTRUE);
            }
            MK.Put(PdfName.IF, dic);
        }
Example #5
0
        public void SetMkIconFit(PdfName scale, PdfName scalingType, float leftoverLeft, float leftoverBottom, bool fitInBounds)
        {
            PdfDictionary dic = new PdfDictionary();

            if (!scale.Equals(PdfName.A))
            {
                dic.Put(PdfName.Sw, scale);
            }
            if (!scalingType.Equals(PdfName.P))
            {
                dic.Put(PdfName.S, scalingType);
            }
            if (leftoverLeft.ApproxNotEqual(0.5f) || leftoverBottom.ApproxNotEqual(0.5f))
            {
                PdfArray array = new PdfArray(new PdfNumber(leftoverLeft));
                array.Add(new PdfNumber(leftoverBottom));
                dic.Put(PdfName.A, array);
            }
            if (fitInBounds)
            {
                dic.Put(PdfName.Fb, PdfBoolean.Pdftrue);
            }
            Mk.Put(PdfName.If, dic);
        }
Example #6
0
 /** Additional-actions defining the actions to be taken in
 * response to various trigger events affecting the document
 * as a whole. The actions types allowed are: <CODE>DOCUMENT_CLOSE</CODE>,
 * <CODE>WILL_SAVE</CODE>, <CODE>DID_SAVE</CODE>, <CODE>WILL_PRINT</CODE>
 * and <CODE>DID_PRINT</CODE>.
 *
 * @param actionType the action type
 * @param action the action to execute in response to the trigger
 * @throws PdfException on invalid action type
 */
 public virtual void SetAdditionalAction(PdfName actionType, PdfAction action) {
     if (!(actionType.Equals(DOCUMENT_CLOSE) ||
     actionType.Equals(WILL_SAVE) ||
     actionType.Equals(DID_SAVE) ||
     actionType.Equals(WILL_PRINT) ||
     actionType.Equals(DID_PRINT))) {
         throw new PdfException(MessageLocalization.GetComposedMessage("invalid.additional.action.type.1", actionType.ToString()));
     }
     pdf.AddAdditionalAction(actionType, action);
 }
Example #7
0
 /**
 * Sets the open and close page additional action.
 * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
 * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
 * @param action the action to perform
 * @param page the page where the action will be applied. The first page is 1
 * @throws PdfException if the action type is invalid
 */    
 internal void SetPageAction(PdfName actionType, PdfAction action, int page) {
     if (!actionType.Equals(PAGE_OPEN) && !actionType.Equals(PAGE_CLOSE))
         throw new PdfException(MessageLocalization.GetComposedMessage("invalid.page.additional.action.type.1", actionType.ToString()));
     PdfDictionary pg = reader.GetPageN(page);
     PdfDictionary aa = (PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.AA), pg);
     if (aa == null) {
         aa = new PdfDictionary();
         pg.Put(PdfName.AA, aa);
         MarkUsed(pg);
     }
     aa.Put(actionType, action);
     MarkUsed(aa);
 }
Example #8
0
 /**
 * Sets the open and close page additional action.
 * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
 * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
 * @param action the action to perform
 * @param page the page where the action will be applied. The first page is 1
 * @throws PdfException if the action type is invalid
 */
 internal void SetPageAction(PdfName actionType, PdfAction action, int page)
 {
     if (!actionType.Equals(PAGE_OPEN) && !actionType.Equals(PAGE_CLOSE))
         throw new PdfException("Invalid page additional action type: " + actionType.ToString());
     PdfDictionary pg = reader.GetPageN(page);
     PdfDictionary aa = (PdfDictionary)PdfReader.GetPdfObject(pg.Get(PdfName.AA), pg);
     if (aa == null) {
         aa = new PdfDictionary();
         pg.Put(PdfName.AA, aa);
         MarkUsed(pg);
     }
     aa.Put(actionType, action);
     MarkUsed(aa);
 }
 public bool IsOutlineTree()
 {
     return(Outlines.Equals(_dictionaryType));
 }
 public bool IsCatalog()
 {
     return(Catalog.Equals(_dictionaryType));
 }
Example #11
0
 virtual public void SetWidget(Rectangle rect, PdfName highlight) {
     Put(PdfName.TYPE, PdfName.ANNOT);
     Put(PdfName.SUBTYPE, PdfName.WIDGET);
     Put(PdfName.RECT, new PdfRectangle(rect));
     annotation = true;
     if (highlight != null && !highlight.Equals(HIGHLIGHT_INVERT))
         Put(PdfName.H, highlight);
 }
Example #12
0
        virtual protected PdfArray BranchForm(Dictionary <string, object> level, PdfIndirectReference parent, String fname)
        {
            PdfArray arr = new PdfArray();

            foreach (KeyValuePair <string, object> entry in level)
            {
                String name = entry.Key;
                Object obj  = entry.Value;
                PdfIndirectReference ind = PdfIndirectReference;
                PdfDictionary        dic = new PdfDictionary();
                if (parent != null)
                {
                    dic.Put(PdfName.PARENT, parent);
                }
                dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
                String fname2 = fname + "." + name;
                int    coidx  = calculationOrder.IndexOf(fname2);
                if (coidx >= 0)
                {
                    calculationOrderRefs[coidx] = ind;
                }
                if (obj is Dictionary <string, object> )
                {
                    dic.Put(PdfName.KIDS, BranchForm((Dictionary <string, object>)obj, ind, fname2));
                    arr.Add(ind);
                    AddToBody(dic, ind);
                }
                else
                {
                    List <object> list = (List <object>)obj;
                    dic.MergeDifferent((PdfDictionary)list[0]);
                    if (list.Count == 3)
                    {
                        dic.MergeDifferent((PdfDictionary)list[2]);
                        int           page    = (int)list[1];
                        PdfDictionary pageDic = pageDics[page - 1];
                        PdfArray      annots  = pageDic.GetAsArray(PdfName.ANNOTS);
                        if (annots == null)
                        {
                            annots = new PdfArray();
                            pageDic.Put(PdfName.ANNOTS, annots);
                        }
                        PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
                        dic.Remove(iTextTag);
                        AdjustTabOrder(annots, ind, nn);
                    }
                    else
                    {
                        PdfDictionary field = (PdfDictionary)list[0];
                        PdfName       v     = field.GetAsName(PdfName.V);
                        PdfArray      kids  = new PdfArray();
                        for (int k = 1; k < list.Count; k += 2)
                        {
                            int           page    = (int)list[k];
                            PdfDictionary pageDic = pageDics[page - 1];
                            PdfArray      annots  = pageDic.GetAsArray(PdfName.ANNOTS);
                            if (annots == null)
                            {
                                annots = new PdfArray();
                                pageDic.Put(PdfName.ANNOTS, annots);
                            }
                            PdfDictionary widget = new PdfDictionary();
                            widget.Merge((PdfDictionary)list[k + 1]);
                            widget.Put(PdfName.PARENT, ind);
                            PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
                            widget.Remove(iTextTag);
                            if (PdfCopy.IsCheckButton(field))
                            {
                                PdfName _as = widget.GetAsName(PdfName.AS);
                                if (v != null && _as != null)
                                {
                                    widget.Put(PdfName.AS, v);
                                }
                            }
                            else if (PdfCopy.IsRadioButton(field))
                            {
                                PdfName _as = widget.GetAsName(PdfName.AS);
                                if (v != null && _as != null && !_as.Equals(GetOffStateName(widget)))
                                {
                                    if (!mergedRadioButtons.ContainsKey(list))
                                    {
                                        mergedRadioButtons[list] = null;
                                        widget.Put(PdfName.AS, v);
                                    }
                                    else
                                    {
                                        widget.Put(PdfName.AS, GetOffStateName(widget));
                                    }
                                }
                            }
                            PdfIndirectReference wref = AddToBody(widget).IndirectReference;
                            AdjustTabOrder(annots, wref, nn);
                            kids.Add(wref);
                            Propagate(widget, null, false);
                        }
                        dic.Put(PdfName.KIDS, kids);
                    }
                    arr.Add(ind);
                    AddToBody(dic, ind);
                    Propagate(dic, null, false);
                }
            }
            return(arr);
        }
Example #13
0
        /**
         *  Checks if a <CODE>Dictionary</CODE> is of the type OUTLINES.
         *
         * @return        <CODE>true</CODE> if it is, <CODE>false</CODE> if it isn't.
         */

        public bool IsOutlineTree()
        {
            return(OUTLINES.Equals(dictionaryType));
        }
Example #14
0
        internal void MergeField(String name, AcroFields.Item item)
        {
            Hashtable       map = fieldTree;
            StringTokenizer tk  = new StringTokenizer(name, ".");

            if (!tk.HasMoreTokens())
            {
                return;
            }
            while (true)
            {
                String s   = tk.NextToken();
                Object obj = map[s];
                if (tk.HasMoreTokens())
                {
                    if (obj == null)
                    {
                        obj    = new Hashtable();
                        map[s] = obj;
                        map    = (Hashtable)obj;
                        continue;
                    }
                    else if (obj is Hashtable)
                    {
                        map = (Hashtable)obj;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    if (obj is Hashtable)
                    {
                        return;
                    }
                    PdfDictionary merged = (PdfDictionary)item.merged[0];
                    if (obj == null)
                    {
                        PdfDictionary field = new PdfDictionary();
                        foreach (PdfName key in merged.Keys)
                        {
                            if (fieldKeys.ContainsKey(key))
                            {
                                field.Put(key, merged.Get(key));
                            }
                        }
                        ArrayList list = new ArrayList();
                        list.Add(field);
                        CreateWidgets(list, item);
                        map[s] = list;
                    }
                    else
                    {
                        ArrayList     list  = (ArrayList)obj;
                        PdfDictionary field = (PdfDictionary)list[0];
                        PdfName       type1 = (PdfName)field.Get(PdfName.FT);
                        PdfName       type2 = (PdfName)merged.Get(PdfName.FT);
                        if (type1 == null || !type1.Equals(type2))
                        {
                            return;
                        }
                        int       flag1 = 0;
                        PdfObject f1    = field.Get(PdfName.FF);
                        if (f1 != null && f1.IsNumber())
                        {
                            flag1 = ((PdfNumber)f1).IntValue;
                        }
                        int       flag2 = 0;
                        PdfObject f2    = merged.Get(PdfName.FF);
                        if (f2 != null && f2.IsNumber())
                        {
                            flag2 = ((PdfNumber)f2).IntValue;
                        }
                        if (type1.Equals(PdfName.BTN))
                        {
                            if (((flag1 ^ flag2) & PdfFormField.FF_PUSHBUTTON) != 0)
                            {
                                return;
                            }
                            if ((flag1 & PdfFormField.FF_PUSHBUTTON) == 0 && ((flag1 ^ flag2) & PdfFormField.FF_RADIO) != 0)
                            {
                                return;
                            }
                        }
                        else if (type1.Equals(PdfName.CH))
                        {
                            if (((flag1 ^ flag2) & PdfFormField.FF_COMBO) != 0)
                            {
                                return;
                            }
                        }
                        CreateWidgets(list, item);
                    }
                    return;
                }
            }
        }
Example #15
0
// ---------------------------------------------------------------------------     
    /**
     * Manipulates a PDF file src with the file dest as result
     * @param src the original PDF
     */
    public byte[] ManipulatePdf(byte[] src) {
      // the font file
      byte[] fontfile = null;
      using (FileStream fs = new FileStream(
        FONT, FileMode.Open, FileAccess.Read)) 
      {
        fontfile = new byte[fs.Length];
        fs.Read(fontfile, 0, (int) fs.Length);
      }
      // create a new stream for the font file
      PdfStream stream = new PdfStream(fontfile);
      stream.FlateCompress();
      stream.Put(PdfName.LENGTH1, new PdfNumber(fontfile.Length));
      // create a reader object
      PdfReader reader = new PdfReader(src);
      int n = reader.XrefSize;
      PdfDictionary font;
      using (MemoryStream ms = new MemoryStream()) {      
        using (PdfStamper stamper = new PdfStamper(reader, ms)) {
          PdfName fontname = new PdfName(FONTNAME);
          for (int i = 0; i < n; i++) {
            PdfObject objectPdf = reader.GetPdfObject(i);
            if (objectPdf == null || !objectPdf.IsDictionary()) {
              continue;
            }
            font = (PdfDictionary)objectPdf;
            if (PdfName.FONTDESCRIPTOR.Equals(font.Get(PdfName.TYPE))
                && fontname.Equals(font.Get(PdfName.FONTNAME))) 
            {
              PdfIndirectObject objref = stamper.Writer.AddToBody(stream);
              font.Put(PdfName.FONTFILE2, objref.IndirectReference);
            }
          }
        }
        return ms.ToArray();
      }
    } 
        private void WriteAttributes(Paragraph paragraph)
        {
            if (paragraph != null)
            {
                // Setting non-inheritable attributes
                if (paragraph.SpacingBefore.CompareTo(0f) != 0)
                {
                    this.SetAttribute(PdfName.SPACEBEFORE, new PdfNumber(paragraph.SpacingBefore));
                }
                if (paragraph.SpacingAfter.CompareTo(0f) != 0)
                {
                    this.SetAttribute(PdfName.SPACEAFTER, new PdfNumber(paragraph.SpacingAfter));
                }

                // Setting inheritable attributes
                IPdfStructureElement parent = (IPdfStructureElement)this.GetParent(true);
                PdfObject            obj    = parent.GetAttribute(PdfName.COLOR);
                if ((paragraph.Font != null) && (paragraph.Font.Color != null))
                {
                    BaseColor c = paragraph.Font.Color;
                    SetColorAttribute(c, obj, PdfName.COLOR);
                }
                obj = parent.GetAttribute(PdfName.TEXTINDENT);
                if (paragraph.FirstLineIndent.CompareTo(0f) != 0)
                {
                    bool writeIndent = true;
                    if (obj is PdfNumber)
                    {
                        if (((PdfNumber)obj).FloatValue.CompareTo(paragraph.FirstLineIndent) == 0)
                        {
                            writeIndent = false;
                        }
                    }
                    if (writeIndent)
                    {
                        this.SetAttribute(PdfName.TEXTINDENT, new PdfNumber(paragraph.FirstLineIndent));
                    }
                }
                obj = parent.GetAttribute(PdfName.STARTINDENT);
                if (obj is PdfNumber)
                {
                    float startIndent = ((PdfNumber)obj).FloatValue;
                    if (startIndent.CompareTo(paragraph.IndentationLeft) != 0)
                    {
                        this.SetAttribute(PdfName.STARTINDENT, new PdfNumber(paragraph.IndentationLeft));
                    }
                }
                else
                {
                    if (Math.Abs(paragraph.IndentationLeft) > float.MinValue)
                    {
                        this.SetAttribute(PdfName.STARTINDENT, new PdfNumber(paragraph.IndentationLeft));
                    }
                }

                obj = parent.GetAttribute(PdfName.ENDINDENT);
                if (obj is PdfNumber)
                {
                    float endIndent = ((PdfNumber)obj).FloatValue;
                    if (endIndent.CompareTo(paragraph.IndentationRight) != 0)
                    {
                        this.SetAttribute(PdfName.ENDINDENT, new PdfNumber(paragraph.IndentationRight));
                    }
                }
                else
                {
                    if (paragraph.IndentationRight.CompareTo(0) != 0)
                    {
                        this.SetAttribute(PdfName.ENDINDENT, new PdfNumber(paragraph.IndentationRight));
                    }
                }

                PdfName align = null;
                switch (paragraph.Alignment)
                {
                case Element.ALIGN_LEFT:
                    align = PdfName.START;
                    break;

                case Element.ALIGN_CENTER:
                    align = PdfName.CENTER;
                    break;

                case Element.ALIGN_RIGHT:
                    align = PdfName.END;
                    break;

                case Element.ALIGN_JUSTIFIED:
                    align = PdfName.JUSTIFY;
                    break;
                }
                obj = parent.GetAttribute(PdfName.TEXTALIGN);
                if (obj is PdfName)
                {
                    PdfName textAlign = ((PdfName)obj);
                    if (align != null && !textAlign.Equals(align))
                    {
                        this.SetAttribute(PdfName.TEXTALIGN, align);
                    }
                }
                else
                {
                    if (align != null && !PdfName.START.Equals(align))
                    {
                        this.SetAttribute(PdfName.TEXTALIGN, align);
                    }
                }
            }
        }
Example #17
0
        /** Gets the field value or <CODE>null</CODE> if the field does not
         * exist or has no value defined.
         * @param name the fully qualified field name
         * @return the field value or <CODE>null</CODE>
         */
        virtual public String GetFieldValue(String name)
        {
            PdfDictionary field = GetField(name);

            if (field == null)
            {
                return(null);
            }
            PdfObject v = GetPdfObject(field.Get(PdfName.V));

            if (v == null)
            {
                return(null);
            }
            if (v.IsName())
            {
                return(PdfName.DecodeName(((PdfName)v).ToString()));
            }
            else if (v.IsString())
            {
                PdfString vs = (PdfString)v;
                if (encoding == null || vs.Encoding != null)
                {
                    return(vs.ToUnicodeString());
                }
                byte[] b = vs.GetBytes();
                if (b.Length >= 2 && b[0] == (byte)254 && b[1] == (byte)255)
                {
                    return(vs.ToUnicodeString());
                }
                try {
                    if (encoding.Equals(PdfName.SHIFT_JIS))
                    {
                        return(Encoding.GetEncoding(932).GetString(b));
                    }
                    else if (encoding.Equals(PdfName.UHC))
                    {
                        return(Encoding.GetEncoding(949).GetString(b));
                    }
                    else if (encoding.Equals(PdfName.GBK))
                    {
                        return(Encoding.GetEncoding(936).GetString(b));
                    }
                    else if (encoding.Equals(PdfName.BIGFIVE))
                    {
                        return(Encoding.GetEncoding(950).GetString(b));
                    }
                    else if (encoding.Equals(PdfName.UTF_8))
                    {
                        return(Encoding.UTF8.GetString(b));
                    }
                }
                catch  {
                }
                return(vs.ToUnicodeString());
            }
            return(null);
        }
Example #18
0
        /**
         *  Checks if a <CODE>Dictionary</CODE> is of the type CATALOG.
         *
         * @return        <CODE>true</CODE> if it is, <CODE>false</CODE> if it isn't.
         */

        public bool IsCatalog()
        {
            return(CATALOG.Equals(dictionaryType));
        }
 /**
 * Sets the annotation's highlighting mode. The values can be
 * <CODE>HIGHLIGHT_NONE</CODE>, <CODE>HIGHLIGHT_INVERT</CODE>,
 * <CODE>HIGHLIGHT_OUTLINE</CODE> and <CODE>HIGHLIGHT_PUSH</CODE>;
 * @param highlight the annotation's highlighting mode
 */
 public void SetHighlighting(PdfName highlight)
 {
     if (highlight.Equals(HIGHLIGHT_INVERT))
         Remove(PdfName.H);
     else
         Put(PdfName.H, highlight);
 }
 public void SetMKIconFit(PdfName scale, PdfName scalingType, float leftoverLeft, float leftoverBottom, bool fitInBounds)
 {
     PdfDictionary dic = new PdfDictionary();
     if (!scale.Equals(PdfName.A))
         dic.Put(PdfName.SW, scale);
     if (!scalingType.Equals(PdfName.P))
         dic.Put(PdfName.S, scalingType);
     if (leftoverLeft != 0.5f || leftoverBottom != 0.5f) {
         PdfArray array = new PdfArray(new PdfNumber(leftoverLeft));
         array.Add(new PdfNumber(leftoverBottom));
         dic.Put(PdfName.A, array);
     }
     if (fitInBounds)
         dic.Put(PdfName.FB, PdfBoolean.PDFTRUE);
     MK.Put(PdfName.IF, dic);
 }
 protected static PdfAnnotation CreateLink(PdfWriter writer, Rectangle rect, PdfName highlight)
 {
     PdfAnnotation annot = new PdfAnnotation(writer, rect);
     annot.Put(PdfName.SUBTYPE, PdfName.LINK);
     if (!highlight.Equals(HIGHLIGHT_INVERT))
         annot.Put(PdfName.H, highlight);
     return annot;
 }
Example #22
0
        internal void MergeField(String name, AcroFields.Item item)
        {
            Dictionary <string, object> map = fieldTree;
            StringTokenizer             tk  = new StringTokenizer(name, ".");

            if (!tk.HasMoreTokens())
            {
                return;
            }
            while (true)
            {
                String s = tk.NextToken();
                Object obj;
                map.TryGetValue(s, out obj);
                if (tk.HasMoreTokens())
                {
                    if (obj == null)
                    {
                        obj    = new Dictionary <string, object>();
                        map[s] = obj;
                        map    = (Dictionary <string, object>)obj;
                        continue;
                    }
                    else if (obj is Dictionary <string, object> )
                    {
                        map = (Dictionary <string, object>)obj;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    if (obj is Dictionary <string, object> )
                    {
                        return;
                    }
                    PdfDictionary merged = item.GetMerged(0);
                    if (obj == null)
                    {
                        PdfDictionary field = new PdfDictionary();
                        if (PdfName.SIG.Equals(merged.Get(PdfName.FT)))
                        {
                            hasSignature = true;
                        }
                        foreach (PdfName key in merged.Keys)
                        {
                            if (fieldKeys.ContainsKey(key))
                            {
                                field.Put(key, merged.Get(key));
                            }
                        }
                        List <object> list = new List <object>();
                        list.Add(field);
                        CreateWidgets(list, item);
                        map[s] = list;
                    }
                    else
                    {
                        List <object> list  = (List <object>)obj;
                        PdfDictionary field = (PdfDictionary)list[0];
                        PdfName       type1 = (PdfName)field.Get(PdfName.FT);
                        PdfName       type2 = (PdfName)merged.Get(PdfName.FT);
                        if (type1 == null || !type1.Equals(type2))
                        {
                            return;
                        }
                        int       flag1 = 0;
                        PdfObject f1    = field.Get(PdfName.FF);
                        if (f1 != null && f1.IsNumber())
                        {
                            flag1 = ((PdfNumber)f1).IntValue;
                        }
                        int       flag2 = 0;
                        PdfObject f2    = merged.Get(PdfName.FF);
                        if (f2 != null && f2.IsNumber())
                        {
                            flag2 = ((PdfNumber)f2).IntValue;
                        }
                        if (type1.Equals(PdfName.BTN))
                        {
                            if (((flag1 ^ flag2) & PdfFormField.FF_PUSHBUTTON) != 0)
                            {
                                return;
                            }
                            if ((flag1 & PdfFormField.FF_PUSHBUTTON) == 0 && ((flag1 ^ flag2) & PdfFormField.FF_RADIO) != 0)
                            {
                                return;
                            }
                        }
                        else if (type1.Equals(PdfName.CH))
                        {
                            if (((flag1 ^ flag2) & PdfFormField.FF_COMBO) != 0)
                            {
                                return;
                            }
                        }
                        CreateWidgets(list, item);
                    }
                    return;
                }
            }
        }
Example #23
0
 /**
  * Checks the type of the dictionary.
  * @param type the type you're looking for
  * @return true if the type of the dictionary corresponds with the type you're looking for
  */
 public bool CheckType(PdfName type) {
     if(type == null)
         return false;
     if(dictionaryType == null)
         dictionaryType = GetAsName(PdfName.TYPE);
     return type.Equals(dictionaryType);
 }
Example #24
0
 // methods concerning the type of Dictionary
 /**
  * Checks if a <CODE>PdfDictionary</CODE> is of a certain type.
  *
  * @param        type    a type of dictionary
  * @return        <CODE>true</CODE> of <CODE>false</CODE>
  *
  * @deprecated
  */
 public bool IsDictionaryType(PdfName type)
 {
     return type.Equals(dictionaryType);
 }
        /**
         * @param colorSpaceName the name of the color space. If null, a bi-tonal (black and white) color space is assumed.
         * @return the components per pixel for the specified color space
         */
        private static int GetComponentsPerPixel(PdfName colorSpaceName, PdfDictionary colorSpaceDic)
        {
            if (colorSpaceName == null)
                return 1;
            if (colorSpaceName.Equals(PdfName.DEVICEGRAY))
                return 1;
            if (colorSpaceName.Equals(PdfName.DEVICERGB))
                return 3;
            if (colorSpaceName.Equals(PdfName.DEVICECMYK))
                return 4;

            if (colorSpaceDic != null){
                PdfArray colorSpace = colorSpaceDic.GetAsArray(colorSpaceName);
                if (colorSpace != null){
                    if (PdfName.INDEXED.Equals(colorSpace.GetAsName(0))){
                        return 1;
                    }
                }
            }

            throw new ArgumentException("Unexpected color space " + colorSpaceName);
        }
 public bool IsFont()
 {
     return(Font.Equals(_dictionaryType));
 }
Example #27
0
 /** Additional-actions defining the actions to be taken in
 * response to various trigger events affecting the document
 * as a whole. The actions types allowed are: <CODE>DOCUMENT_CLOSE</CODE>,
 * <CODE>WILL_SAVE</CODE>, <CODE>DID_SAVE</CODE>, <CODE>WILL_PRINT</CODE>
 * and <CODE>DID_PRINT</CODE>.
 *
 * @param actionType the action type
 * @param action the action to execute in response to the trigger
 * @throws PdfException on invalid action type
 */
 public virtual void SetAdditionalAction(PdfName actionType, PdfAction action)
 {
     if (!(actionType.Equals(DOCUMENT_CLOSE) ||
     actionType.Equals(WILL_SAVE) ||
     actionType.Equals(DID_SAVE) ||
     actionType.Equals(WILL_PRINT) ||
     actionType.Equals(DID_PRINT))) {
         throw new PdfException("Invalid additional action type: " + actionType.ToString());
     }
     pdf.AddAdditionalAction(actionType, action);
 }
 public bool IsPages()
 {
     return(Pages.Equals(_dictionaryType));
 }
Example #29
0
 /** Sets the open and close page additional action.
 * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
 * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
 * @param action the action to perform
 * @throws PdfException if the action type is invalid
 */
 public virtual void SetPageAction(PdfName actionType, PdfAction action)
 {
     if (!actionType.Equals(PAGE_OPEN) && !actionType.Equals(PAGE_CLOSE))
         throw new PdfException("Invalid page additional action type: " + actionType.ToString());
     pdf.SetPageAction(actionType, action);
 }
Example #30
0
 /** Additional-actions defining the actions to be taken in
 * response to various trigger events affecting the document
 * as a whole. The actions types allowed are: <CODE>DOCUMENT_CLOSE</CODE>,
 * <CODE>WILL_SAVE</CODE>, <CODE>DID_SAVE</CODE>, <CODE>WILL_PRINT</CODE>
 * and <CODE>DID_PRINT</CODE>.
 *
 * @param actionType the action type
 * @param action the action to execute in response to the trigger
 * @throws PdfException on invalid action type
 */
 public override void SetAdditionalAction(PdfName actionType, PdfAction action)
 {
     if (!(actionType.Equals(DOCUMENT_CLOSE) ||
     actionType.Equals(WILL_SAVE) ||
     actionType.Equals(DID_SAVE) ||
     actionType.Equals(WILL_PRINT) ||
     actionType.Equals(DID_PRINT))) {
         throw new PdfException("Invalid additional action type: " + actionType.ToString());
     }
     PdfDictionary aa = (PdfDictionary)PdfReader.GetPdfObject(reader.Catalog.Get(PdfName.AA));
     if (aa == null) {
         if (action == null)
             return;
         aa = new PdfDictionary();
         reader.Catalog.Put(PdfName.AA, aa);
     }
     MarkUsed(aa);
     if (action == null)
         aa.Remove(actionType);
     else
         aa.Put(actionType, action);
 }
Example #31
0
        // methods concerning the type of Dictionary

        /**
         *  Checks if a <CODE>Dictionary</CODE> is of the type FONT.
         *
         * @return        <CODE>true</CODE> if it is, <CODE>false</CODE> if it isn't.
         */

        public bool IsFont()
        {
            return(FONT.Equals(dictionaryType));
        }
Example #32
0
 /** Additional-actions defining the actions to be taken in
 * response to various trigger events affecting the document
 * as a whole. The actions types allowed are: <CODE>DOCUMENT_CLOSE</CODE>,
 * <CODE>WILL_SAVE</CODE>, <CODE>DID_SAVE</CODE>, <CODE>WILL_PRINT</CODE>
 * and <CODE>DID_PRINT</CODE>.
 *
 * @param actionType the action type
 * @param action the action to execute in response to the trigger
 * @throws PdfException on invalid action type
 */
 public override void SetAdditionalAction(PdfName actionType, PdfAction action) {
     if (!(actionType.Equals(DOCUMENT_CLOSE) ||
     actionType.Equals(WILL_SAVE) ||
     actionType.Equals(DID_SAVE) ||
     actionType.Equals(WILL_PRINT) ||
     actionType.Equals(DID_PRINT))) {
         throw new PdfException(MessageLocalization.GetComposedMessage("invalid.additional.action.type.1", actionType.ToString()));
     }
     PdfDictionary aa = reader.Catalog.GetAsDict(PdfName.AA);
     if (aa == null) {
         if (action == null)
             return;
         aa = new PdfDictionary();
         reader.Catalog.Put(PdfName.AA, aa);
     }
     MarkUsed(aa);
     if (action == null)
         aa.Remove(actionType);
     else
         aa.Put(actionType, action);
 }
Example #33
0
        /**
         *  Checks if a <CODE>Dictionary</CODE> is of the type PAGES.
         *
         * @return        <CODE>true</CODE> if it is, <CODE>false</CODE> if it isn't.
         */

        public bool IsPages()
        {
            return(PAGES.Equals(dictionaryType));
        }
Example #34
0
 /** Sets the open and close page additional action.
 * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE>
 * or <CODE>PdfWriter.PAGE_CLOSE</CODE>
 * @param action the action to perform
 * @throws PdfException if the action type is invalid
 */    
 public virtual void SetPageAction(PdfName actionType, PdfAction action) {
     if (!actionType.Equals(PAGE_OPEN) && !actionType.Equals(PAGE_CLOSE))
         throw new PdfException(MessageLocalization.GetComposedMessage("invalid.page.additional.action.type.1", actionType.ToString()));
     pdf.SetPageAction(actionType, action);
 }
Example #35
0
 /**
  * @param colorSpaceName the name of the color space. If null, a bi-tonal (black and white) color space is assumed.
  * @return the components per pixel for the specified color space
  */
 private static int GetComponentsPerPixel(PdfName colorSpaceName){
     if (colorSpaceName == null)
         return 1;
     if (colorSpaceName.Equals(PdfName.DEVICEGRAY))
         return 1;
     if (colorSpaceName.Equals(PdfName.DEVICERGB))
         return 3;
     if (colorSpaceName.Equals(PdfName.DEVICECMYK))
         return 4;
     
     throw new ArgumentException("Unexpected color space " + colorSpaceName);
 }