private PdfFormField MergeFieldsWithTheSameName(PdfFormField existingField, PdfFormField newField)
        {
            String fieldName = newField.GetFieldName().ToUnicodeString();

            existingField.GetPdfObject().Remove(PdfName.T);
            PdfFormField mergedField = formTo.GetField(fieldName);
            PdfArray     kids        = mergedField.GetKids();

            if (kids != null && !kids.IsEmpty())
            {
                mergedField.AddKid(existingField);
                return(mergedField);
            }
            newField.GetPdfObject().Remove(PdfName.T);
            mergedField = PdfFormField.CreateEmptyField(documentTo);
            formTo.GetFields().Remove(newField.GetPdfObject());
            mergedField.Put(PdfName.FT, existingField.GetFormType()).Put(PdfName.T, new PdfString(fieldName));
            PdfDictionary parent = existingField.GetParent();

            if (parent != null)
            {
                mergedField.Put(PdfName.Parent, parent);
            }
            kids = existingField.GetKids();
            if (kids != null)
            {
                mergedField.Put(PdfName.Kids, kids);
            }
            mergedField.AddKid(existingField).AddKid(newField);
            return(mergedField);
        }
Example #2
0
        private PdfFormField MergeFieldsWithTheSameName(PdfFormField existingField, PdfFormField newField)
        {
            String    fullFieldName = newField.GetFieldName().ToUnicodeString();
            PdfString fieldName     = newField.GetPdfObject().GetAsString(PdfName.T);

            newField.GetPdfObject().Remove(PdfName.T);
            newField.GetPdfObject().Remove(PdfName.P);
            existingField = formTo.GetField(fullFieldName);
            PdfArray kids = existingField.GetKids();

            if (kids != null && !kids.IsEmpty())
            {
                existingField.AddKid(newField);
                return(existingField);
            }
            existingField.GetPdfObject().Remove(PdfName.T);
            existingField.GetPdfObject().Remove(PdfName.P);
            formTo.GetFields().Remove(existingField.GetPdfObject());
            PdfFormField mergedField = PdfFormField.CreateEmptyField(documentTo);

            mergedField.Put(PdfName.FT, existingField.GetFormType()).Put(PdfName.T, fieldName);
            PdfDictionary parent = existingField.GetParent();

            if (parent != null)
            {
                mergedField.Put(PdfName.Parent, parent);
                PdfArray parentKids = parent.GetAsArray(PdfName.Kids);
                for (int i = 0; i < parentKids.Size(); i++)
                {
                    PdfObject obj = parentKids.Get(i);
                    if (obj == existingField.GetPdfObject())
                    {
                        parentKids.Set(i, mergedField.GetPdfObject());
                        break;
                    }
                }
            }
            kids = existingField.GetKids();
            if (kids != null)
            {
                mergedField.Put(PdfName.Kids, kids);
            }
            mergedField.AddKid(existingField).AddKid(newField);
            PdfObject value = existingField.GetValue();

            if (value != null)
            {
                mergedField.Put(PdfName.V, existingField.GetPdfObject().Get(PdfName.V));
            }
            return(mergedField);
        }
Example #3
0
        /**
         * @see com.lowagie.text.pdf.PdfPageEvent#onGenericTag(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document, com.lowagie.text.Rectangle, java.lang.String)
         */
        public override void OnGenericTag(PdfWriter writer, Document document,
                                          Rectangle rect, String text)
        {
            rect.Bottom = rect.Bottom - 3;
            PdfFormField field = (PdfFormField)genericChunkFields[text];

            if (field == null)
            {
                TextField tf = new TextField(writer, new Rectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)), text);
                tf.FontSize = 14;
                field       = tf.GetTextField();
            }
            else
            {
                field.Put(PdfName.RECT, new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)));
            }
            if (parent == null)
            {
                writer.AddAnnotation(field);
            }
            else
            {
                parent.AddKid(field);
            }
        }
Example #4
0
            public override void Draw(DrawContext drawContext)
            {
                base.Draw(drawContext);
                PdfFormField field = PdfFormField.CreateSignature(drawContext.GetDocument(), GetOccupiedAreaBBox());

                field.SetFieldName(name);
                if (Lock != null)
                {
                    field.Put(PdfName.Lock, this.Lock.MakeIndirect(drawContext.GetDocument()).GetPdfObject());
                }

                field.GetWidgets()[0].SetFlag(PdfAnnotation.PRINT);
                field.GetWidgets()[0].SetHighlightMode(PdfAnnotation.HIGHLIGHT_INVERT);
                PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true).AddField(field);
            }
Example #5
0
 /**
  * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
  */
 public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases)
 {
     if (cellField == null || (fieldWriter == null && parent == null))
     {
         throw new ArgumentException("You have used the wrong constructor for this FieldPositioningEvents class.");
     }
     cellField.Put(PdfName.RECT, new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)));
     if (parent == null)
     {
         fieldWriter.AddAnnotation(cellField);
     }
     else
     {
         parent.AddKid(cellField);
     }
 }
Example #6
0
 /**
  * @see com.lowagie.text.pdf.PdfPCellEvent#cellLayout(com.lowagie.text.pdf.PdfPCell, com.lowagie.text.Rectangle, com.lowagie.text.pdf.PdfContentByte[])
  */
 public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvases)
 {
     if (cellField == null || (fieldWriter == null && parent == null))
     {
         throw new ArgumentException(MessageLocalization.GetComposedMessage("you.have.used.the.wrong.constructor.for.this.fieldpositioningevents.class"));
     }
     cellField.Put(PdfName.RECT, new PdfRectangle(rect.GetLeft(padding), rect.GetBottom(padding), rect.GetRight(padding), rect.GetTop(padding)));
     if (parent == null)
     {
         fieldWriter.AddAnnotation(cellField);
     }
     else
     {
         parent.AddKid(cellField);
     }
 }
Example #7
0
        protected PdfPCell CreateSignatureFieldCell(PdfWriter writer, String name, PdfDictionary Lock)
        {
            PdfPCell cell = new PdfPCell();

            cell.MinimumHeight = 50;
            PdfFormField field = PdfFormField.CreateSignature(writer);

            field.FieldName = name;
            if (Lock != null)
            {
                field.Put(PdfName.LOCK, writer.AddToBody(Lock).IndirectReference);
            }
            field.Flags    = PdfAnnotation.FLAGS_PRINT;
            cell.CellEvent = new MySignatureFieldEvent(field);
            return(cell);
        }
        private PdfFormField MergeFieldsWithTheSameName(PdfFormField newField)
        {
            String    fullFieldName = newField.GetFieldName().ToUnicodeString();
            PdfString fieldName     = newField.GetPdfObject().GetAsString(PdfName.T);

            logger.Warn(MessageFormatUtil.Format(iText.IO.LogMessageConstant.DOCUMENT_ALREADY_HAS_FIELD, fullFieldName
                                                 ));
            PdfFormField existingField = formTo.GetField(fullFieldName);

            if (existingField.IsFlushed())
            {
                int index = 0;
                do
                {
                    index++;
                    newField.SetFieldName(fieldName.ToUnicodeString() + "_#" + index);
                    fullFieldName = newField.GetFieldName().ToUnicodeString();
                }while (formTo.GetField(fullFieldName) != null);
                return(newField);
            }
            newField.GetPdfObject().Remove(PdfName.T);
            newField.GetPdfObject().Remove(PdfName.P);
            formTo.GetFields().Remove(existingField.GetPdfObject());
            PdfArray kids = existingField.GetKids();

            if (kids != null && !kids.IsEmpty())
            {
                existingField.AddKid(newField);
                return(existingField);
            }
            existingField.GetPdfObject().Remove(PdfName.T);
            existingField.GetPdfObject().Remove(PdfName.P);
            PdfFormField mergedField = PdfFormField.CreateEmptyField(documentTo);

            mergedField.Put(PdfName.FT, existingField.GetFormType()).Put(PdfName.T, fieldName);
            PdfDictionary parent = existingField.GetParent();

            if (parent != null)
            {
                mergedField.Put(PdfName.Parent, parent);
                PdfArray parentKids = parent.GetAsArray(PdfName.Kids);
                for (int i = 0; i < parentKids.Size(); i++)
                {
                    PdfObject obj = parentKids.Get(i);
                    if (obj == existingField.GetPdfObject())
                    {
                        parentKids.Set(i, mergedField.GetPdfObject());
                        break;
                    }
                }
            }
            kids = existingField.GetKids();
            if (kids != null)
            {
                mergedField.Put(PdfName.Kids, kids);
            }
            mergedField.AddKid(existingField).AddKid(newField);
            PdfObject value = existingField.GetPdfObject().Get(PdfName.V);

            if (value != null)
            {
                mergedField.Put(PdfName.V, existingField.GetPdfObject().Get(PdfName.V));
            }
            return(mergedField);
        }