예제 #1
0
        public void DrawSingleLineOfText(PdfFormField field, string text, BaseFont font, float fontSize, float llx, float lly, float urx, float ury)
        {
            PdfAppearance tp  = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
            PdfAppearance tp2 = (PdfAppearance)tp.Duplicate;

            tp2.SetFontAndSize(font, fontSize);
            tp2.ResetRGBColorFill();
            field.DefaultAppearanceString = tp2;
            tp.DrawTextField(0f, 0f, urx - llx, ury - lly);
            tp.BeginVariableText();
            tp.SaveState();
            tp.Rectangle(3f, 3f, urx - llx - 6f, ury - lly - 6f);
            tp.Clip();
            tp.NewPath();
            tp.BeginText();
            tp.SetFontAndSize(font, fontSize);
            tp.ResetRGBColorFill();
            tp.SetTextMatrix(4, (ury - lly) / 2 - (fontSize * 0.3f));
            tp.ShowText(text);
            tp.EndText();
            tp.RestoreState();
            tp.EndVariableText();
            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
        }
예제 #2
0
        public void DrawCheckBoxAppearences(PdfFormField field, string value, float llx, float lly, float urx, float ury)
        {
            BaseFont      font = BaseFont.CreateFont(BaseFont.ZAPFDINGBATS, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
            float         size = (ury - lly);
            PdfAppearance tpOn = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
            PdfAppearance tp2  = (PdfAppearance)tpOn.Duplicate;

            tp2.SetFontAndSize(font, size);
            tp2.ResetRGBColorFill();
            field.DefaultAppearanceString = tp2;
            tpOn.DrawTextField(0f, 0f, urx - llx, ury - lly);
            tpOn.SaveState();
            tpOn.ResetRGBColorFill();
            tpOn.BeginText();
            tpOn.SetFontAndSize(font, size);
            tpOn.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "4", (urx - llx) / 2, (ury - lly) / 2 - (size * 0.3f), 0);
            tpOn.EndText();
            tpOn.RestoreState();
            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, value, tpOn);
            PdfAppearance tpOff = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);

            tpOff.DrawTextField(0f, 0f, urx - llx, ury - lly);
            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
        }
예제 #3
0
 public void DrawSingleLineOfText(PdfFormField field, string text, BaseFont font, float fontSize, float llx, float lly, float urx, float ury)
 {
     PdfAppearance tp = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
     PdfAppearance tp2 = (PdfAppearance)tp.Duplicate;
     tp2.SetFontAndSize(font, fontSize);
     tp2.ResetRGBColorFill();
     field.DefaultAppearanceString = tp2;
     tp.DrawTextField(0f, 0f, urx - llx, ury - lly);
     tp.BeginVariableText();
     tp.SaveState();
     tp.Rectangle(3f, 3f, urx - llx - 6f, ury - lly - 6f);
     tp.Clip();
     tp.NewPath();
     tp.BeginText();
     tp.SetFontAndSize(font, fontSize);
     tp.ResetRGBColorFill();
     tp.SetTextMatrix(4, (ury - lly) / 2 - (fontSize * 0.3f));
     tp.ShowText(text);
     tp.EndText();
     tp.RestoreState();
     tp.EndVariableText();
     field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
 }
예제 #4
0
 public static PdfFormField CreateTextField(PdfWriter writer, bool multiline, bool password, int maxLen)
 {
     PdfFormField field = new PdfFormField(writer);
     field.Put(PdfName.FT, PdfName.TX);
     int flags = (multiline ? FF_MULTILINE : 0);
     flags += (password ? FF_PASSWORD : 0);
     field.Put(PdfName.FF, new PdfNumber(flags));
     if (maxLen > 0)
         field.Put(PdfName.MAXLEN, new PdfNumber(maxLen));
     return field;
 }
예제 #5
0
 public void DrawRadioAppearences(PdfFormField field, string value, float llx, float lly, float urx, float ury)
 {
     PdfAppearance tpOn = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
     tpOn.DrawRadioField(0f, 0f, urx - llx, ury - lly, true);
     field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, value, tpOn);
     PdfAppearance tpOff = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
     tpOff.DrawRadioField(0f, 0f, urx - llx, ury - lly, false);
     field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
 }
예제 #6
0
 public PdfFormField AddHtmlPostButton(string name, string caption, string value, string url, BaseFont font, float fontSize, float llx, float lly, float urx, float ury)
 {
     PdfAction action = PdfAction.CreateSubmitForm(url, null, PdfAction.SUBMIT_HTML_FORMAT);
     PdfFormField button = new PdfFormField(writer, llx, lly, urx, ury, action);
     SetButtonParams(button, PdfFormField.FF_PUSHBUTTON, name, value);
     DrawButton(button, caption, font, fontSize, llx, lly, urx, ury);
     AddFormField(button);
     return button;
 }
예제 #7
0
 public PdfFormField AddRadioButton(PdfFormField radiogroup, string value, float llx, float lly, float urx, float ury)
 {
     PdfFormField radio = PdfFormField.CreateEmpty(writer);
     radio.SetWidget(new Rectangle(llx, lly, urx, ury), PdfAnnotation.HIGHLIGHT_TOGGLE);
     string name = ((PdfName)radiogroup.Get(PdfName.V)).ToString().Substring(1);
     if (name.Equals(value)) {
     radio.AppearanceState = value;
     }
     else {
     radio.AppearanceState = "Off";
     }
     DrawRadioAppearences(radio, value, llx, lly, urx, ury);
     radiogroup.AddKid(radio);
     return radio;
 }
예제 #8
0
        /**
         * Gets a radio or check field.
         * @param isRadio <CODE>true</CODE> to get a radio field, <CODE>false</CODE> to get
         * a check field
         * @throws IOException on error
         * @throws DocumentException on error
         * @return the field
         */
        protected PdfFormField GetField(bool isRadio)
        {
            PdfFormField field = null;

            if (isRadio)
            {
                field = PdfFormField.CreateEmpty(writer);
            }
            else
            {
                field = PdfFormField.CreateCheckBox(writer);
            }
            field.SetWidget(box, PdfAnnotation.HIGHLIGHT_INVERT);
            if (!isRadio)
            {
                field.FieldName = fieldName;
                if ((options & READ_ONLY) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_READ_ONLY);
                }
                if ((options & REQUIRED) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_REQUIRED);
                }
                field.ValueAsName = vchecked ? onValue : "Off";
            }
            if (text != null)
            {
                field.MKNormalCaption = text;
            }
            if (rotation != 0)
            {
                field.MKRotation = rotation;
            }
            field.BorderStyle = new PdfBorderDictionary(borderWidth, borderStyle, new PdfDashPattern(3));
            PdfAppearance tpon  = GetAppearance(isRadio, true);
            PdfAppearance tpoff = GetAppearance(isRadio, false);

            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, onValue, tpon);
            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpoff);
            field.AppearanceState = vchecked ? onValue : "Off";
            PdfAppearance da = (PdfAppearance)tpon.Duplicate;

            da.SetFontAndSize(RealFont, fontSize);
            if (textColor == null)
            {
                da.SetGrayFill(0);
            }
            else
            {
                da.SetColorFill(textColor);
            }
            field.DefaultAppearanceString = da;
            if (borderColor != null)
            {
                field.MKBorderColor = borderColor;
            }
            if (backgroundColor != null)
            {
                field.MKBackgroundColor = backgroundColor;
            }
            switch (visibility)
            {
            case HIDDEN:
                field.Flags = PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_HIDDEN;
                break;

            case VISIBLE_BUT_DOES_NOT_PRINT:
                break;

            case HIDDEN_BUT_PRINTABLE:
                field.Flags = PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_NOVIEW;
                break;

            default:
                field.Flags = PdfAnnotation.FLAGS_PRINT;
                break;
            }
            return(field);
        }
예제 #9
0
 /**
  * Adds an object to the calculationOrder.
  */
 public void AddCalculationOrder(PdfFormField formField)
 {
     calculationOrder.Add(formField.IndirectReference);
 }
예제 #10
0
 public static PdfAnnotation ShallowDuplicate(PdfAnnotation annot)
 {
     PdfAnnotation dup;
     if (annot.IsForm()) {
         dup = new PdfFormField(annot.writer);
         PdfFormField dupField = (PdfFormField)dup;
         PdfFormField srcField = (PdfFormField)annot;
         dupField.parent = srcField.parent;
         dupField.kids = srcField.kids;
     }
     else
         dup = new PdfAnnotation(annot.writer, null);
     dup.Merge(annot);
     dup.form = annot.form;
     dup.annotation = annot.annotation;
     dup.templates = annot.templates;
     return dup;
 }
예제 #11
0
        /** Gets a new text field.
         * @throws IOException on error
         * @throws DocumentException on error
         * @return a new text field
         */
        public PdfFormField GetTextField()
        {
            if (maxCharacterLength <= 0)
            {
                options &= ~COMB;
            }
            if ((options & COMB) != 0)
            {
                options &= ~MULTILINE;
            }
            PdfFormField field = PdfFormField.CreateTextField(writer, false, false, maxCharacterLength);

            field.SetWidget(box, PdfAnnotation.HIGHLIGHT_INVERT);
            switch (alignment)
            {
            case Element.ALIGN_CENTER:
                field.Quadding = PdfFormField.Q_CENTER;
                break;

            case Element.ALIGN_RIGHT:
                field.Quadding = PdfFormField.Q_RIGHT;
                break;
            }
            if (rotation != 0)
            {
                field.MKRotation = rotation;
            }
            if (fieldName != null)
            {
                field.FieldName = fieldName;
                if (!"".Equals(text))
                {
                    field.ValueAsString = text;
                }
                if (defaultText != null)
                {
                    field.DefaultValueAsString = defaultText;
                }
                if ((options & READ_ONLY) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_READ_ONLY);
                }
                if ((options & REQUIRED) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_REQUIRED);
                }
                if ((options & MULTILINE) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_MULTILINE);
                }
                if ((options & DO_NOT_SCROLL) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_DONOTSCROLL);
                }
                if ((options & PASSWORD) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_PASSWORD);
                }
                if ((options & FILE_SELECTION) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_FILESELECT);
                }
                if ((options & DO_NOT_SPELL_CHECK) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_DONOTSPELLCHECK);
                }
                if ((options & COMB) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_COMB);
                }
            }
            field.BorderStyle = new PdfBorderDictionary(borderWidth, borderStyle, new PdfDashPattern(3));
            PdfAppearance tp = GetAppearance();

            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
            PdfAppearance da = (PdfAppearance)tp.Duplicate;

            da.SetFontAndSize(RealFont, fontSize);
            if (textColor == null)
            {
                da.SetGrayFill(0);
            }
            else
            {
                da.SetColorFill(textColor);
            }
            field.DefaultAppearanceString = da;
            if (borderColor != null)
            {
                field.MKBorderColor = borderColor;
            }
            if (backgroundColor != null)
            {
                field.MKBackgroundColor = backgroundColor;
            }
            switch (visibility)
            {
            case HIDDEN:
                field.Flags = PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_HIDDEN;
                break;

            case VISIBLE_BUT_DOES_NOT_PRINT:
                break;

            case HIDDEN_BUT_PRINTABLE:
                field.Flags = PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_NOVIEW;
                break;

            default:
                field.Flags = PdfAnnotation.FLAGS_PRINT;
                break;
            }
            return(field);
        }
예제 #12
0
 private void ExpandFields(PdfFormField field, ArrayList allAnnots)
 {
     allAnnots.Add(field);
     ArrayList kids = field.Kids;
     if (kids != null) {
         for (int k = 0; k < kids.Count; ++k)
             ExpandFields((PdfFormField)kids[k], allAnnots);
     }
 }
예제 #13
0
        public static PdfFormField CreateEmpty(PdfWriter writer)
        {
            PdfFormField field = new PdfFormField(writer);

            return(field);
        }
예제 #14
0
 protected static PdfFormField CreateChoice(PdfWriter writer, int flags, PdfArray options, int topIndex)
 {
     PdfFormField field = new PdfFormField(writer);
     field.Put(PdfName.FT, PdfName.CH);
     field.Put(PdfName.FF, new PdfNumber(flags));
     field.Put(PdfName.OPT, options);
     if (topIndex > 0)
         field.Put(PdfName.TI, new PdfNumber(topIndex));
     return field;
 }
예제 #15
0
 protected static PdfFormField CreateButton(PdfWriter writer, int flags)
 {
     PdfFormField field = new PdfFormField(writer);
     field.Button = flags;
     return field;
 }
예제 #16
0
 public void AddKid(PdfFormField field)
 {
     field.parent = this;
     if (kids == null)
         kids = new ArrayList();
     kids.Add(field);
 }
예제 #17
0
 public void SetCheckBoxParams(PdfFormField field, string name, string value, bool status, float llx, float lly, float urx, float ury)
 {
     field.SetWidget(new Rectangle(llx, lly, urx, ury), PdfAnnotation.HIGHLIGHT_TOGGLE);
     field.FieldName = name;
     if (status) {
     field.ValueAsName = value;
     field.AppearanceState = value;
     }
     else {
     field.ValueAsName = "Off";
     field.AppearanceState = "Off";
     }
     field.Flags = PdfAnnotation.FLAGS_PRINT;
     field.SetPage();
     field.BorderStyle = new PdfBorderDictionary(1, PdfBorderDictionary.STYLE_SOLID);
 }
예제 #18
0
        protected PdfFormField GetChoiceField(bool isList)
        {
            options &= (~MULTILINE) & (~COMB);
            String[] uchoices = choices;
            if (uchoices == null)
            {
                uchoices = new String[0];
            }
            int topChoice = choiceSelection;

            if (topChoice >= uchoices.Length)
            {
                topChoice = uchoices.Length - 1;
            }
            if (text == null)
            {
                text = "";               //fixed by Kazuya Ujihara (ujihara.jp)
            }
            if (topChoice >= 0)
            {
                text = uchoices[topChoice];
            }
            if (topChoice < 0)
            {
                topChoice = 0;
            }
            PdfFormField field = null;

            String[,] mix = null;
            if (choiceExports == null)
            {
                if (isList)
                {
                    field = PdfFormField.CreateList(writer, uchoices, topChoice);
                }
                else
                {
                    field = PdfFormField.CreateCombo(writer, (options & EDIT) != 0, uchoices, topChoice);
                }
            }
            else
            {
                mix = new String[uchoices.Length, 2];
                for (int k = 0; k < mix.GetLength(0); ++k)
                {
                    mix[k, 0] = mix[k, 1] = uchoices[k];
                }
                int top = Math.Min(uchoices.Length, choiceExports.Length);
                for (int k = 0; k < top; ++k)
                {
                    if (choiceExports[k] != null)
                    {
                        mix[k, 0] = choiceExports[k];
                    }
                }
                if (isList)
                {
                    field = PdfFormField.CreateList(writer, mix, topChoice);
                }
                else
                {
                    field = PdfFormField.CreateCombo(writer, (options & EDIT) != 0, mix, topChoice);
                }
            }
            field.SetWidget(box, PdfAnnotation.HIGHLIGHT_INVERT);
            if (rotation != 0)
            {
                field.MKRotation = rotation;
            }
            if (fieldName != null)
            {
                field.FieldName = fieldName;
                if (uchoices.Length > 0)
                {
                    if (mix != null)
                    {
                        field.ValueAsString        = mix[topChoice, 0];
                        field.DefaultValueAsString = mix[topChoice, 0];
                    }
                    else
                    {
                        field.ValueAsString        = text;
                        field.DefaultValueAsString = text;
                    }
                }
                if ((options & READ_ONLY) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_READ_ONLY);
                }
                if ((options & REQUIRED) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_REQUIRED);
                }
                if ((options & DO_NOT_SPELL_CHECK) != 0)
                {
                    field.SetFieldFlags(PdfFormField.FF_DONOTSPELLCHECK);
                }
            }
            field.BorderStyle = new PdfBorderDictionary(borderWidth, borderStyle, new PdfDashPattern(3));
            PdfAppearance tp;

            if (isList)
            {
                tp = GetListAppearance();
                if (topFirst > 0)
                {
                    field.Put(PdfName.TI, new PdfNumber(topFirst));
                }
            }
            else
            {
                tp = GetAppearance();
            }
            field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
            PdfAppearance da = (PdfAppearance)tp.Duplicate;

            da.SetFontAndSize(RealFont, fontSize);
            if (textColor == null)
            {
                da.SetGrayFill(0);
            }
            else
            {
                da.SetColorFill(textColor);
            }
            field.DefaultAppearanceString = da;
            if (borderColor != null)
            {
                field.MKBorderColor = borderColor;
            }
            if (backgroundColor != null)
            {
                field.MKBackgroundColor = backgroundColor;
            }
            switch (visibility)
            {
            case HIDDEN:
                field.Flags = PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_HIDDEN;
                break;

            case VISIBLE_BUT_DOES_NOT_PRINT:
                break;

            case HIDDEN_BUT_PRINTABLE:
                field.Flags = PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_NOVIEW;
                break;

            default:
                field.Flags = PdfAnnotation.FLAGS_PRINT;
                break;
            }
            return(field);
        }
예제 #19
0
 /**
  * @param field
  * @param name
  * @param llx
  * @param lly
  * @param urx
  * @param ury
  */
 public void SetSignatureParams(PdfFormField field, String name, float llx, float lly, float urx, float ury)
 {
     field.SetWidget(new Rectangle(llx, lly, urx, ury), PdfAnnotation.HIGHLIGHT_INVERT);
     field.FieldName = name;
     field.Flags = PdfAnnotation.FLAGS_PRINT;
     field.SetPage();
     field.MKBorderColor = Color.BLACK;
     field.MKBackgroundColor = Color.WHITE;
 }
예제 #20
0
        /**
         * Adds an object to the calculationOrder.
         */

        public void AddCalculationOrder(PdfFormField formField)
        {
            calculationOrder.Add(formField.IndirectReference);
        }
예제 #21
0
 void AddFormFieldRaw(PdfFormField field)
 {
     annotations.Add(field);
     ArrayList kids = field.Kids;
     if (kids != null) {
         for (int k = 0; k < kids.Count; ++k)
             AddFormFieldRaw((PdfFormField)kids[k]);
     }
 }
예제 #22
0
        /**
         * Adds a formfield to the AcroForm.
         */

        public void AddFormField(PdfFormField formField)
        {
            writer.AddAnnotation(formField);
        }
예제 #23
0
 /**
  * Adds a formfield to the AcroForm.
  */
 public void AddFormField(PdfFormField formField)
 {
     writer.AddAnnotation(formField);
 }
예제 #24
0
 public PdfFormField AddResetButton(string name, string caption, string value, BaseFont font, float fontSize, float llx, float lly, float urx, float ury)
 {
     PdfAction action = PdfAction.CreateResetForm(null, 0);
     PdfFormField button = new PdfFormField(writer, llx, lly, urx, ury, action);
     SetButtonParams(button, PdfFormField.FF_PUSHBUTTON, name, value);
     DrawButton(button, caption, font, fontSize, llx, lly, urx, ury);
     AddFormField(button);
     return button;
 }
예제 #25
0
 public PdfFormField AddMap(string name, string value, string url, PdfContentByte appearance, float llx, float lly, float urx, float ury)
 {
     PdfAction action = PdfAction.CreateSubmitForm(url, null, PdfAction.SUBMIT_HTML_FORMAT | PdfAction.SUBMIT_COORDINATES);
     PdfFormField button = new PdfFormField(writer, llx, lly, urx, ury, action);
     SetButtonParams(button, PdfFormField.FF_PUSHBUTTON, name, null);
     PdfAppearance pa = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
     pa.Add(appearance);
     button.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, pa);
     AddFormField(button);
     return button;
 }
예제 #26
0
 public void DrawCheckBoxAppearences(PdfFormField field, string value, float llx, float lly, float urx, float ury)
 {
     BaseFont font = BaseFont.CreateFont(BaseFont.ZAPFDINGBATS, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
     float size = (ury - lly);
     PdfAppearance tpOn = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
     PdfAppearance tp2 = (PdfAppearance)tpOn.Duplicate;
     tp2.SetFontAndSize(font, size);
     tp2.ResetRGBColorFill();
     field.DefaultAppearanceString = tp2;
     tpOn.DrawTextField(0f, 0f, urx - llx, ury - lly);
     tpOn.SaveState();
     tpOn.ResetRGBColorFill();
     tpOn.BeginText();
     tpOn.SetFontAndSize(font, size);
     tpOn.ShowTextAligned(PdfContentByte.ALIGN_CENTER, "4", (urx - llx) / 2, (ury - lly) / 2 - (size * 0.3f), 0);
     tpOn.EndText();
     tpOn.RestoreState();
     field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, value, tpOn);
     PdfAppearance tpOff = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
     tpOff.DrawTextField(0f, 0f, urx - llx, ury - lly);
     field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, "Off", tpOff);
 }
예제 #27
0
 public void AddRadioGroup(PdfFormField radiogroup)
 {
     AddFormField(radiogroup);
 }
예제 #28
0
 public static PdfFormField CreateSignature(PdfWriter writer)
 {
     PdfFormField field = new PdfFormField(writer);
     field.Put(PdfName.FT, PdfName.SIG);
     return field;
 }
예제 #29
0
 public void DrawButton(PdfFormField button, string caption, BaseFont font, float fontSize, float llx, float lly, float urx, float ury)
 {
     PdfAppearance pa = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
     pa.DrawButton(0f, 0f, urx - llx, ury - lly, caption, font, fontSize);
     button.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, pa);
 }
예제 #30
0
 public void AddRadioGroup(PdfFormField radiogroup)
 {
     AddFormField(radiogroup);
 }
예제 #31
0
 public void DrawMultiLineOfText(PdfFormField field, string text, BaseFont font, float fontSize, float llx, float lly, float urx, float ury)
 {
     PdfAppearance tp = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
     PdfAppearance tp2 = (PdfAppearance)tp.Duplicate;
     tp2.SetFontAndSize(font, fontSize);
     tp2.ResetRGBColorFill();
     field.DefaultAppearanceString = tp2;
     tp.DrawTextField(0f, 0f, urx - llx, ury - lly);
     tp.BeginVariableText();
     tp.SaveState();
     tp.Rectangle(3f, 3f, urx - llx - 6f, ury - lly - 6f);
     tp.Clip();
     tp.NewPath();
     tp.BeginText();
     tp.SetFontAndSize(font, fontSize);
     tp.ResetRGBColorFill();
     tp.SetTextMatrix(4, 5);
     var tokenizer = new StringTokenizer(text, "\n");
     float yPos = ury - lly;
     while (tokenizer.HasMoreTokens()) {
     yPos -= fontSize * 1.2f;
     tp.ShowTextAligned(PdfContentByte.ALIGN_LEFT, tokenizer.NextToken(), 3, yPos, 0);
     }
     tp.EndText();
     tp.RestoreState();
     tp.EndVariableText();
     field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
 }
예제 #32
0
 /** Adds the <CODE>PdfAnnotation</CODE> to the calculation order
 * array.
 * @param annot the <CODE>PdfAnnotation</CODE> to be added
 */
 public virtual void AddCalculationOrder(PdfFormField annot)
 {
     pdf.AddCalculationOrder(annot);
 }
예제 #33
0
 /**
  * @param field
  * @param llx
  * @param lly
  * @param urx
  * @param ury
  */
 public void DrawSignatureAppearences(PdfFormField field, float llx, float lly, float urx, float ury)
 {
     PdfAppearance tp = PdfAppearance.CreateAppearance(writer, urx - llx, ury - lly);
     tp.SetGrayFill(1.0f);
     tp.Rectangle(0, 0, urx - llx, ury - lly);
     tp.Fill();
     tp.SetGrayStroke(0);
     tp.SetLineWidth(1);
     tp.Rectangle(0.5f, 0.5f, urx - llx - 0.5f, ury - lly - 0.5f);
     tp.ClosePathStroke();
     tp.SaveState();
     tp.Rectangle(1, 1, urx - llx - 2, ury - lly - 2);
     tp.Clip();
     tp.NewPath();
     tp.RestoreState();
     field.SetAppearance(PdfAnnotation.APPEARANCE_NORMAL, tp);
 }
예제 #34
0
 /**
 * Replaces the first field with a new pushbutton. The pushbutton can be created with
 * {@link #getNewPushbuttonFromField(String)} from the same document or it can be a
 * generic PdfFormField of the type pushbutton.
 * @param field the field name
 * @param button the <CODE>PdfFormField</CODE> representing the pushbutton
 * @return <CODE>true</CODE> if the field was replaced, <CODE>false</CODE> if the field
 * was not a pushbutton
 */
 public bool ReplacePushbuttonField(String field, PdfFormField button)
 {
     return ReplacePushbuttonField(field, button, 0);
 }
예제 #35
0
 public void SetButtonParams(PdfFormField button, int characteristics, string name, string value)
 {
     button.Button = characteristics;
     button.Flags = PdfAnnotation.FLAGS_PRINT;
     button.SetPage();
     button.FieldName = name;
     if (value != null) button.ValueAsString = value;
 }
예제 #36
0
 /**
 * Replaces the designated field with a new pushbutton. The pushbutton can be created with
 * {@link #getNewPushbuttonFromField(String,int)} from the same document or it can be a
 * generic PdfFormField of the type pushbutton.
 * @param field the field name
 * @param button the <CODE>PdfFormField</CODE> representing the pushbutton
 * @param order the field order in fields with same name
 * @return <CODE>true</CODE> if the field was replaced, <CODE>false</CODE> if the field
 * was not a pushbutton
 */
 public bool ReplacePushbuttonField(String field, PdfFormField button, int order)
 {
     if (GetFieldType(field) != FIELD_TYPE_PUSHBUTTON)
         return false;
     Item item = GetFieldItem(field);
     if (order >= item.Size)
         return false;
     PdfDictionary merged = item.GetMerged(order);
     PdfDictionary values = item.GetValue(order);
     PdfDictionary widgets = item.GetWidget(order);
     for (int k = 0; k < buttonRemove.Length; ++k) {
         merged.Remove(buttonRemove[k]);
         values.Remove(buttonRemove[k]);
         widgets.Remove(buttonRemove[k]);
     }
     foreach (PdfName key in button.Keys) {
         if (key.Equals(PdfName.T) || key.Equals(PdfName.RECT))
             continue;
         if (key.Equals(PdfName.FF))
             values.Put(key, button.Get(key));
         else
             widgets.Put(key, button.Get(key));
         merged.Put(key, button.Get(key));
     }
     return true;
 }
예제 #37
0
 public void SetChoiceParams(PdfFormField field, string name, string defaultValue, float llx, float lly, float urx, float ury)
 {
     field.SetWidget(new Rectangle(llx, lly, urx, ury), PdfAnnotation.HIGHLIGHT_INVERT);
     if (defaultValue != null) {
     field.ValueAsString = defaultValue;
     field.DefaultValueAsString = defaultValue;
     }
     field.FieldName = name;
     field.Flags = PdfAnnotation.FLAGS_PRINT;
     field.SetPage();
     field.BorderStyle = new PdfBorderDictionary(2, PdfBorderDictionary.STYLE_SOLID);
 }
예제 #38
0
 public void AddCalculationOrder(PdfFormField formField)
 {
     acroForm.AddCalculationOrder(formField);
 }
예제 #39
0
 public void SetTextFieldParams(PdfFormField field, string text, string name, float llx, float lly, float urx, float ury)
 {
     field.SetWidget(new Rectangle(llx, lly, urx, ury), PdfAnnotation.HIGHLIGHT_INVERT);
     field.ValueAsString = text;
     field.DefaultValueAsString = text;
     field.FieldName = name;
     field.Flags = PdfAnnotation.FLAGS_PRINT;
     field.SetPage();
 }
예제 #40
0
            public void AddAnnotation(PdfAnnotation annot)
            {
                ArrayList allAnnots = new ArrayList();

                if (annot.IsForm())
                {
                    PdfFormField field = (PdfFormField)annot;
                    if (field.Parent != null)
                    {
                        return;
                    }
                    ExpandFields(field, allAnnots);
                    if (cstp.fieldTemplates == null)
                    {
                        cstp.fieldTemplates = new Hashtable();
                    }
                }
                else
                {
                    allAnnots.Add(annot);
                }
                for (int k = 0; k < allAnnots.Count; ++k)
                {
                    annot = (PdfAnnotation)allAnnots[k];
                    if (annot.IsForm())
                    {
                        if (!annot.IsUsed())
                        {
                            Hashtable templates = annot.Templates;
                            if (templates != null)
                            {
                                foreach (object tpl in templates.Keys)
                                {
                                    cstp.fieldTemplates[tpl] = null;
                                }
                            }
                        }
                        PdfFormField field = (PdfFormField)annot;
                        if (field.Parent == null)
                        {
                            AddDocumentField(field.IndirectReference);
                        }
                    }
                    if (annot.IsAnnotation())
                    {
                        PdfObject pdfobj = PdfReader.GetPdfObject(pageN.Get(PdfName.ANNOTS), pageN);
                        PdfArray  annots = null;
                        if (pdfobj == null || !pdfobj.IsArray())
                        {
                            annots = new PdfArray();
                            pageN.Put(PdfName.ANNOTS, annots);
                        }
                        else
                        {
                            annots = (PdfArray)pdfobj;
                        }
                        annots.Add(annot.IndirectReference);
                        if (!annot.IsUsed())
                        {
                            PdfRectangle rect = (PdfRectangle)annot.Get(PdfName.RECT);
                            if (rect != null && (rect.Left != 0 || rect.Right != 0 || rect.Top != 0 || rect.Bottom != 0))
                            {
                                int       rotation = reader.GetPageRotation(pageN);
                                Rectangle pageSize = reader.GetPageSizeWithRotation(pageN);
                                switch (rotation)
                                {
                                case 90:
                                    annot.Put(PdfName.RECT, new PdfRectangle(
                                                  pageSize.Top - rect.Bottom,
                                                  rect.Left,
                                                  pageSize.Top - rect.Top,
                                                  rect.Right));
                                    break;

                                case 180:
                                    annot.Put(PdfName.RECT, new PdfRectangle(
                                                  pageSize.Right - rect.Left,
                                                  pageSize.Top - rect.Bottom,
                                                  pageSize.Right - rect.Right,
                                                  pageSize.Top - rect.Top));
                                    break;

                                case 270:
                                    annot.Put(PdfName.RECT, new PdfRectangle(
                                                  rect.Bottom,
                                                  pageSize.Right - rect.Left,
                                                  rect.Top,
                                                  pageSize.Right - rect.Right));
                                    break;
                                }
                            }
                        }
                    }
                    if (!annot.IsUsed())
                    {
                        annot.SetUsed();
                        cstp.AddToBody(annot, annot.IndirectReference);
                    }
                }
            }